MyGUI  3.0.1
MyGUI_Widget.h
Go to the documentation of this file.
1 
7 /*
8  This file is part of MyGUI.
9 
10  MyGUI is free software: you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  MyGUI is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
22 */
23 #ifndef __MYGUI_WIDGET_H__
24 #define __MYGUI_WIDGET_H__
25 
26 #include "MyGUI_Prerequest.h"
27 #include "MyGUI_Any.h"
29 #include "MyGUI_ISubWidgetRect.h"
30 #include "MyGUI_ISubWidgetText.h"
31 #include "MyGUI_LayerItem.h"
32 #include "MyGUI_WidgetUserData.h"
33 #include "MyGUI_WidgetEvent.h"
34 #include "MyGUI_IWidgetCreator.h"
35 #include "MyGUI_ResourceSkin.h"
36 #include "MyGUI_IObject.h"
37 
38 namespace MyGUI
39 {
40 
42  public IObject,
43  public ICroppedRectangle,
44  public LayerItem,
45  public UserData,
46  public WidgetEvent,
47  public IWidgetCreator,
49  {
50  // для вызова закрытых деструкторов
51  friend class IWidgetCreator;
52 
54 
55  public:
56  Widget();
57 
65  Widget* createWidgetT(const std::string& _type, const std::string& _skin, const IntCoord& _coord, Align _align, const std::string& _name = "");
66 
68  Widget* createWidgetT(const std::string& _type, const std::string& _skin, int _left, int _top, int _width, int _height, Align _align, const std::string& _name = "");
69 
71  Widget* createWidgetRealT(const std::string& _type, const std::string& _skin, const FloatCoord& _coord, Align _align, const std::string& _name = "");
72 
74  Widget* createWidgetRealT(const std::string& _type, const std::string& _skin, float _left, float _top, float _width, float _height, Align _align, const std::string& _name = "");
75 
76  // templates for creating widgets by type
78  template <typename T>
79  T* createWidget(const std::string& _skin, const IntCoord& _coord, Align _align, const std::string& _name = "")
80  {
81  return static_cast<T*>(createWidgetT(T::getClassTypeName(), _skin, _coord, _align, _name));
82  }
83 
85  template <typename T>
86  T* createWidget(const std::string& _skin, int _left, int _top, int _width, int _height, Align _align, const std::string& _name = "")
87  {
88  return static_cast<T*>(createWidgetT(T::getClassTypeName(), _skin, IntCoord(_left, _top, _width, _height), _align, _name));
89  }
90 
92  template <typename T>
93  T* createWidgetReal(const std::string& _skin, const FloatCoord& _coord, Align _align, const std::string& _name = "")
94  {
95  return static_cast<T*>(createWidgetRealT(T::getClassTypeName(), _skin, _coord, _align, _name));
96  }
97 
99  template <typename T>
100  T* createWidgetReal(const std::string& _skin, float _left, float _top, float _width, float _height, Align _align, const std::string& _name = "")
101  {
102  return static_cast<T*>(createWidgetRealT(T::getClassTypeName(), _skin, _left, _top, _width, _height, _align, _name));
103  }
104 
113  Widget* createWidgetT(WidgetStyle _style, const std::string& _type, const std::string& _skin, const IntCoord& _coord, Align _align, const std::string& _layer = "", const std::string& _name = "");
114 
116  template <typename T>
117  T* createWidget(WidgetStyle _style, const std::string& _skin, const IntCoord& _coord, Align _align, const std::string& _layer = "", const std::string& _name = "")
118  {
119  return static_cast<T*>(createWidgetT(_style, T::getClassTypeName(), _skin, _coord, _align, _layer, _name));
120  }
121 
123  const std::string& getName() const { return mName; }
124 
125 
127  virtual void setPosition(const IntPoint& _value);
129  virtual void setSize(const IntSize& _value);
131  virtual void setCoord(const IntCoord& _value);
132 
134  void setPosition(int _left, int _top) { setPosition(IntPoint(_left, _top)); }
136  void setSize(int _width, int _height) { setSize(IntSize(_width, _height)); }
138  void setCoord(int _left, int _top, int _width, int _height) { setCoord(IntCoord(_left, _top, _width, _height)); }
139 
141  void setRealPosition(const FloatPoint& _value);
143  void setRealSize(const FloatSize& _value);
145  void setRealCoord(const FloatCoord& _value);
146 
148  void setRealPosition(float _left, float _top) { setRealPosition(FloatPoint(_left, _top)); }
150  void setRealSize(float _width, float _height) { setRealSize(FloatSize(_width, _height)); }
152  void setRealCoord(float _left, float _top, float _width, float _height) { setRealCoord(FloatCoord(_left, _top, _width, _height)); }
153 
155  virtual void setVisible(bool _value);
156 
158  virtual void setAlign(Align _value);
159 
161  virtual void setCaption(const UString& _value);
163  virtual const UString& getCaption();
164 
166  void setAlpha(float _value);
168  float getAlpha() { return mAlpha; }
169 
171  void setInheritsAlpha(bool _value);
173  bool isInheritsAlpha() { return mInheritsAlpha; }
174 
176  bool setState(const std::string& _value);
177 
178  void setColour(const Colour& _value);
179 
180  // являемся ли мы рутовым виджетом
182  bool isRootWidget() { return nullptr == mCroppedParent; }
183 
185  Widget* getParent() { return mParent; }
186 
188  EnumeratorWidgetPtr getEnumerator();
189 
191  size_t getChildCount();
192 
194  Widget* getChildAt(size_t _index);
195 
197  Widget* findWidget(const std::string& _name);
198 
200  void setNeedKeyFocus(bool _value) { mNeedKeyFocus = _value; }
205  bool isNeedKeyFocus() { return mNeedKeyFocus; }
206 
208  void setNeedMouseFocus(bool _value) { mNeedMouseFocus = _value; }
213  bool isNeedMouseFocus() { return mNeedMouseFocus; }
214 
220  void setInheritsPick(bool _value) { mInheritsPick = _value; }
222  bool isInheritsPick() { return mInheritsPick; }
223 
225  void setMaskPick(const std::string& _filename);
226 
228  virtual void setEnabled(bool _value);
230  void setEnabledSilent(bool _value) { mEnabled = _value; }
232  bool isEnabled() { return mEnabled; }
233 
235  void setPointer(const std::string& _value) { mPointer = _value; }
237  const std::string& getPointer();
238 
240  const std::string& getLayerName();
241 
243  IntCoord getClientCoord();
244 
246  Widget* getClientWidget() { return mWidgetClient; }
247 
249  ISubWidgetText * getSubWidgetText() { return mText; }
251  ISubWidgetRect * getSubWidgetMain() { return mMainSkin; }
252 
254  void setNeedToolTip(bool _value);
256  bool getNeedToolTip() { return mNeedToolTip; }
257 
259  void setEnableToolTip(bool _value);
261  bool getEnableToolTip() { return mEnableToolTip; }
262 
266  void detachFromWidget(const std::string& _layer = "");
267 
274  void attachToWidget(Widget* _parent, WidgetStyle _style = WidgetStyle::Child, const std::string& _layer = "");
275 
277  void changeWidgetSkin(const std::string& _skinname);
278 
284  void setWidgetStyle(WidgetStyle _style, const std::string& _layer = "");
286  WidgetStyle getWidgetStyle() { return mWidgetStyle; }
287 
292  virtual void setProperty(const std::string& _key, const std::string& _value);
293 
294 
295  /*internal:*/
296  // метод для запроса номера айтема и контейнера
297  virtual void _getContainer(Widget*& _container, size_t& _index);
298 
299  // дает приоритет виджету при пиккинге
300  void _forcePeek(Widget* _widget);
301 
302  void _setUVSet(const FloatRect& _rect);
303 
304  virtual void _setTextureName(const std::string& _texture);
305  virtual const std::string& _getTextureName();
306 
307  IWidgetCreator * _getIWidgetCreator() { return mIWidgetCreator; }
308 
309  IntCoord _getTextRegion();
310  IntSize _getTextSize();
311  void _setFontName(const std::string& _font);
312  const std::string& _getFontName();
313  void _setFontHeight(int _height);
314  int _getFontHeight();
315  void _setTextAlign(Align _align);
316  Align _getTextAlign();
317  void _setTextColour(const Colour& _colour);
318  const Colour& _getTextColour();
319 
320  // устанавливает строку заменив /n на реальный перенос
321  void setCaptionWithNewLine(const std::string& _value);
322  virtual void _initialise(WidgetStyle _style, const IntCoord& _coord, Align _align, ResourceSkin* _info, Widget* _parent, ICroppedRectangle * _croppedParent, IWidgetCreator * _creator, const std::string& _name);
323 
324 
325  /*obsolete:*/
326 #ifndef MYGUI_DONT_USE_OBSOLETE
327 
328  MYGUI_OBSOLETE("use : void Widget::setCoord(const IntCoord& _coord)")
329  void setPosition(const IntCoord& _coord) { setCoord(_coord); }
330  MYGUI_OBSOLETE("use : void Widget::setCoord(int _left, int _top, int _width, int _height)")
331  void setPosition(int _left, int _top, int _width, int _height) { setCoord(_left, _top, _width, _height); }
332 
333  MYGUI_OBSOLETE("use : void Widget::setEnableToolTip")
334  void enableToolTip(bool _enable) { setEnableToolTip(_enable); }
335 
336  MYGUI_OBSOLETE("use : void setInheritsPick(bool _inherits)")
337  void setInheritsPeek(bool _inherits) { setInheritsPick(_inherits); }
338  MYGUI_OBSOLETE("use : bool isInheritsPick()")
339  bool isInheritsPeek() { return isInheritsPick(); }
340 
341  MYGUI_OBSOLETE("use : void setMaskPick(const std::string& _filename)")
342  void setMaskPeek(const std::string& _filename) { setMaskPick(_filename); }
343 
344  MYGUI_OBSOLETE("use : const IntCoord& StaticText::getTextRegion()")
345  IntCoord getTextCoord() { return _getTextRegion(); }
346  MYGUI_OBSOLETE("use : IntSize StaticText::getTextSize()")
347  IntSize getTextSize() { return _getTextSize(); }
348 
349  MYGUI_OBSOLETE("use : void StaticText::setFontName(const std::string& _font)")
350  void setFontName(const std::string& _font) { _setFontName(_font); }
351  MYGUI_OBSOLETE("use : const std::string& StaticText::getFontName()")
352  const std::string& getFontName() { return _getFontName(); }
353 
354  MYGUI_OBSOLETE("use : void StaticText::setFontHeight(int _height)")
355  void setFontHeight(int _height) { _setFontHeight(_height); }
356  MYGUI_OBSOLETE("use : int StaticText::getFontHeight()")
357  int getFontHeight() { return _getFontHeight(); }
358 
359  MYGUI_OBSOLETE("use : void StaticText::setTextAlign(Align _align)")
360  void setTextAlign(Align _align) { _setTextAlign(_align); }
361  MYGUI_OBSOLETE("use : Align StaticText::getTextAlign()")
362  Align getTextAlign() { return _getTextAlign(); }
363 
364  MYGUI_OBSOLETE("use : void StaticText::setTextColour(const Colour& _colour)")
365  void setTextColour(const Colour& _colour) { _setTextColour(_colour); }
366  MYGUI_OBSOLETE("use : const Colour& StaticText::getTextColour()")
367  const Colour& getTextColour() { return _getTextColour(); }
368 
369 #endif // MYGUI_DONT_USE_OBSOLETE
370 
371  protected:
372  // все создание только через фабрику
373  Widget(WidgetStyle _style, const IntCoord& _coord, Align _align, ResourceSkin* _info, Widget* _parent, ICroppedRectangle * _croppedParent, IWidgetCreator * _creator, const std::string& _name);
374  virtual ~Widget();
375 
376  virtual void baseChangeWidgetSkin(ResourceSkin* _info);
377 
378  void _updateView(); // обновления себя и детей
379 
380  void _setAlign(const IntSize& _oldsize, bool _update);
381  void _setAlign(const IntCoord& _oldcoord, bool _update);
382 
383  // создает виджет
384  virtual Widget* baseCreateWidget(WidgetStyle _style, const std::string& _type, const std::string& _skin, const IntCoord& _coord, Align _align, const std::string& _layer, const std::string& _name);
385 
386  // удяляет неудачника
387  virtual void _destroyChildWidget(Widget* _widget);
388 
389  // удаляет всех детей
390  virtual void _destroyAllChildWidget();
391 
392  // запрашиваем у конейтера айтем по позиции мыши
393  virtual size_t _getContainerIndex(const IntPoint& _point) { return ITEM_NONE; }
394 
395  // сброс всех данных контейнера, тултипы и все остальное
396  virtual void _resetContainer(bool _update);
397 
398  virtual void baseUpdateEnable();
399 
400  // наследуемся он LayerInfo
401  virtual ILayerItem * getLayerItemByPoint(int _left, int _top);
402  virtual const IntCoord& getLayerItemCoord() { return mCoord; }
403 
404  private:
405 
406  void frameEntered(float _frame);
407 
408  void initialiseWidgetSkin(ResourceSkin* _info, const IntSize& _size);
409  void shutdownWidgetSkin(bool _deep = false);
410 
411  void _updateAlpha();
412  void _updateAbsolutePoint();
413 
414  // для внутреннего использования
415  void _setInheritsVisible(bool _value);
416  bool _isInheritsVisible() { return mInheritsVisible; }
417 
418  void _setInheritsEnable(bool _value);
419  bool _isInheritsEnable() { return mInheritsEnabled; }
420 
421  // показывает скрывает все сабскины
422  void _setSubSkinVisible(bool _visible);
423 
424  float _getRealAlpha() { return mRealAlpha; }
425 
426  // добавляет в список виджет
427  virtual void _linkChildWidget(Widget* _widget);
428  // удаляет из списка
429  virtual void _unlinkChildWidget(Widget* _widget);
430 
431  protected:
432  // список всех стейтов
434  // информация о маске для пикинга
437 
438  // вектор всех детей виджетов
440  // вектор детей скина
442  // вектор всех детей сабскинов
444 
445  // указатель на окно текста
447  // указатель на первый не текстовой сабскин
449 
450  // доступен ли на виджет
451  bool mEnabled;
453  // скрыты ли все сабскины при выходе за границу
455  // для иерархического скрытия
457  // прозрачность и флаг наследования альфы нашего оверлея
458  float mAlpha;
459  float mRealAlpha;
461  // имя виджета
462  std::string mName;
463  // курсор который будет показан при наведении
464  std::string mPointer;
465  std::string mTextureName;
467 
468  // наш отец в иерархии виджетов
470 
471  // это тот кто нас создал, и кто нас будет удалять
473 
474  // нужен ли виджету ввод с клавы
476  // нужен ли виджету фокус мыши
479 
480  // клиентская зона окна
481  // если виджет имеет пользовательские окна не в себе
482  // то обязательно проинициализировать Client
484 
492 
493  // поведение виджета, перекрывающийся дочерний или всплывающий
495 
498 
499  };
500 
501 } // namespace MyGUI
502 
503 #endif // __MYGUI_WIDGET_H__