MyGUI  3.4.0
MyGUI_Widget.h
Go to the documentation of this file.
1 /*
2  * This source file is part of MyGUI. For the latest info, see http://mygui.info/
3  * Distributed under the MIT License
4  * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
5  */
6 
7 #ifndef MYGUI_WIDGET_H_
8 #define MYGUI_WIDGET_H_
9 
10 #include "MyGUI_Prerequest.h"
11 #include "MyGUI_Any.h"
13 #include "MyGUI_WidgetUserData.h"
14 #include "MyGUI_WidgetInput.h"
15 #include "MyGUI_ResourceSkin.h"
16 #include "MyGUI_ResourceLayout.h"
17 #include "MyGUI_IObject.h"
18 #include "MyGUI_SkinItem.h"
20 
21 namespace MyGUI
22 {
23 
25 
30  public IObject,
31  public ICroppedRectangle,
32  public UserData,
33  public WidgetInput,
35  public SkinItem,
36  public MemberObsolete<Widget>
37  {
38  // для вызова закрытых деструкторов
39  friend class WidgetManager;
40 
42 
43  public:
44  Widget();
45 
53  Widget* createWidgetT(const std::string& _type, const std::string& _skin, const IntCoord& _coord, Align _align, const std::string& _name = "");
54 
56  Widget* createWidgetT(const std::string& _type, const std::string& _skin, int _left, int _top, int _width, int _height, Align _align, const std::string& _name = "");
57 
59  Widget* createWidgetRealT(const std::string& _type, const std::string& _skin, const FloatCoord& _coord, Align _align, const std::string& _name = "");
60 
62  Widget* createWidgetRealT(const std::string& _type, const std::string& _skin, float _left, float _top, float _width, float _height, Align _align, const std::string& _name = "");
63 
64  // templates for creating widgets by type
66  template <typename T>
67  T* createWidget(const std::string& _skin, const IntCoord& _coord, Align _align, const std::string& _name = "")
68  {
69  return static_cast<T*>(createWidgetT(T::getClassTypeName(), _skin, _coord, _align, _name));
70  }
71 
73  template <typename T>
74  T* createWidget(const std::string& _skin, int _left, int _top, int _width, int _height, Align _align, const std::string& _name = "")
75  {
76  return static_cast<T*>(createWidgetT(T::getClassTypeName(), _skin, IntCoord(_left, _top, _width, _height), _align, _name));
77  }
78 
80  template <typename T>
81  T* createWidgetReal(const std::string& _skin, const FloatCoord& _coord, Align _align, const std::string& _name = "")
82  {
83  return static_cast<T*>(createWidgetRealT(T::getClassTypeName(), _skin, _coord, _align, _name));
84  }
85 
87  template <typename T>
88  T* createWidgetReal(const std::string& _skin, float _left, float _top, float _width, float _height, Align _align, const std::string& _name = "")
89  {
90  return static_cast<T*>(createWidgetRealT(T::getClassTypeName(), _skin, _left, _top, _width, _height, _align, _name));
91  }
92 
102  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 = "");
103 
105  template <typename T>
106  T* createWidget(WidgetStyle _style, const std::string& _skin, const IntCoord& _coord, Align _align, const std::string& _layer = "", const std::string& _name = "")
107  {
108  return static_cast<T*>(createWidgetT(_style, T::getClassTypeName(), _skin, _coord, _align, _layer, _name));
109  }
110 
112  void setPosition(const IntPoint& _value) override;
114  void setSize(const IntSize& _value) override;
116  void setCoord(const IntCoord& _value) override;
117 
119  void setPosition(int _left, int _top);
121  void setSize(int _width, int _height);
123  void setCoord(int _left, int _top, int _width, int _height);
124 
126  void setRealPosition(const FloatPoint& _value);
128  void setRealSize(const FloatSize& _value);
130  void setRealCoord(const FloatCoord& _value);
131 
133  void setRealPosition(float _left, float _top);
135  void setRealSize(float _width, float _height);
137  void setRealCoord(float _left, float _top, float _width, float _height);
138 
140  const std::string& getName() const;
141 
143  virtual void setVisible(bool _value);
145  bool getVisible() const;
146 
151  void setDepth(int _value);
153  int getDepth() const;
154 
156  bool getInheritedVisible() const;
157 
159  virtual void setAlign(Align _value);
161  Align getAlign() const;
162 
164  void setAlpha(float _value);
166  float getAlpha() const;
167 
178  void setInheritsAlpha(bool _value);
180  bool getInheritsAlpha() const;
181 
182  void setColour(const Colour& _value);
183 
184  // являемся ли мы рутовым виджетом
186  bool isRootWidget() const;
187 
189  Widget* getParent() const;
190 
191  IntSize getParentSize() const;
192 
194  EnumeratorWidgetPtr getEnumerator() const;
195 
197  size_t getChildCount();
198 
200  Widget* getChildAt(size_t _index);
201 
206  Widget* findWidget(const std::string& _name);
207 
211  void findWidgets(const std::string& _name, VectorWidgetPtr& _result);
212 
214  virtual void setEnabled(bool _value);
216  void setEnabledSilent(bool _value);
218  bool getEnabled() const;
219 
221  bool getInheritedEnabled() const;
222 
224  IntCoord getClientCoord();
225 
227  Widget* getClientWidget();
228  const Widget* getClientWidget() const;
229 
233  void detachFromWidget(const std::string& _layer = "");
234 
240  void attachToWidget(Widget* _parent, WidgetStyle _style = WidgetStyle::Child, const std::string& _layer = "");
241 
243  void changeWidgetSkin(const std::string& _skinName);
244 
250  void setWidgetStyle(WidgetStyle _style, const std::string& _layer = "");
252  WidgetStyle getWidgetStyle() const;
253 
258  void setProperty(const std::string& _key, const std::string& _value);
259 
260 
268 
274 
275  /*internal:*/
276  // метод для запроса номера айтема и контейнера
277  virtual size_t _getItemIndex(Widget* _item);
278 
279  // дает приоритет виджету при пиккинге
280  void _forcePick(Widget* _widget);
281 
282  void _initialise(WidgetStyle _style, const IntCoord& _coord, const std::string& _skinName, Widget* _parent, ICroppedRectangle* _croppedParent, const std::string& _name);
283  void _shutdown();
284 
285  // удяляет неудачника
286  void _destroyChildWidget(Widget* _widget);
287 
288  void _setContainer(Widget* _value);
289  Widget* _getContainer();
290 
291  void _setAlign(const IntSize& _oldsize, const IntSize& _newSize);
292  bool _checkPoint(int _left, int _top) const;
293 
294  Widget* _createSkinWidget(WidgetStyle _style, const std::string& _type, const std::string& _skin, const IntCoord& _coord, Align _align, const std::string& _layer = "", const std::string& _name = "");
295 
296  // сброс всех данных контейнера, тултипы и все остальное
297  virtual void _resetContainer(bool _update);
298 
299  bool _setWidgetState(const std::string& _value);
300 
301  // перерисовывает детей
302  void _updateChilds();
303 
304  protected:
305  // все создание только через фабрику
306  ~Widget() override = default;
307 
308  virtual void shutdownOverride();
309  virtual void initialiseOverride();
310 
311  void _updateView(); // обновления себя и детей
312 
313  // создает виджет
314  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, bool _template);
315 
316  // удаляет всех детей
317  void _destroyAllChildWidget();
318 
319  // запрашиваем у конейтера айтем по позиции мыши
320  virtual size_t _getContainerIndex(const IntPoint& _point);
321 
322  virtual void baseUpdateEnable();
323 
324  // наследуемся он LayerInfo
325  ILayerItem* getLayerItemByPoint(int _left, int _top) const override;
326  const IntCoord& getLayerItemCoord() const override;
327 
328  template <typename T>
329  void assignWidget(T*& _widget, const std::string& _name)
330  {
331  _widget = nullptr;
332  for (VectorWidgetPtr::iterator iter = mWidgetChildSkin.begin(); iter != mWidgetChildSkin.end(); ++iter)
333  {
334  Widget* find = (*iter)->findWidget(_name);
335  if (nullptr != find)
336  {
337  _widget = find->castType<T>(false);
338  break;
339  }
340  }
341  }
342 
343  VectorWidgetPtr getSkinWidgetsByName(const std::string& _name);
344 
345  void destroySkinWidget(Widget* _widget);
346 
347  virtual void onWidgetCreated(Widget* _widget);
348  virtual void onWidgetDestroy(Widget* _widget);
349 
350  void setWidgetClient(Widget* _widget);
352  Widget* _getClientWidget();
353 
354  virtual void setPropertyOverride(const std::string& _key, const std::string& _value);
355 
356  private:
357  const WidgetInfo* initialiseWidgetSkinBase(ResourceSkin* _info, ResourceLayout* _templateInfo);
358  void shutdownWidgetSkinBase();
359 
360  void _updateAlpha();
361  void _updateAbsolutePoint();
362 
363  // для внутреннего использования
364  void _updateVisible();
365 
366  void _updateEnabled();
367 
368  float _getRealAlpha() const;
369 
370  void _createChildSkinWidget(ResourceSkin* _info);
371  void _destroyChildSkinWidget();
372 
373  void _parseSkinProperties(ResourceSkin* _info);
374  void _checkInheristProperties();
375 
376  void _linkChildWidget(Widget* _widget);
377  void _unlinkChildWidget(Widget* _widget);
378 
379  void setSkinProperty(ResourceSkin* _info);
380 
381  void resizeLayerItemView(const IntSize& _oldView, const IntSize& _newView) override;
382 
383  void addWidget(Widget* _widget);
384 
385  private:
386  // клиентская зона окна
387  // если виджет имеет пользовательские окна не в себе
388  // то обязательно проинициализировать Client
389  Widget* mWidgetClient;
390 
391  // вектор всех детей виджетов
392  VectorWidgetPtr mWidgetChild;
393 
394  // вектор детей скина
395  VectorWidgetPtr mWidgetChildSkin;
396 
397  // доступен ли на виджет
398  bool mEnabled;
399  bool mInheritsEnabled;
400  // для иерархического скрытия
401  bool mInheritsVisible;
402  // прозрачность и флаг наследования альфы нашего оверлея
403  float mAlpha;
404  float mRealAlpha;
405  bool mInheritsAlpha;
406  // имя виджета
407  std::string mName;
408 
409  // наш отец в иерархии виджетов
410  Widget* mParent;
411 
412  // поведение виджета, перекрывающийся дочерний или всплывающий
413  WidgetStyle mWidgetStyle;
414 
415  Widget* mContainer;
416 
417  Align mAlign;
418  bool mVisible;
419  int mDepth;
420  };
421 
422 } // namespace MyGUI
423 
424 #endif // MYGUI_WIDGET_H_
MyGUI::Widget::createWidget
T * createWidget(const std::string &_skin, const IntCoord &_coord, Align _align, const std::string &_name="")
Definition: MyGUI_Widget.h:67
MyGUI::WidgetInput
Definition: MyGUI_WidgetInput.h:60
MyGUI_WidgetUserData.h
MyGUI::Widget::~Widget
~Widget() override=default
MyGUI::WidgetManager
Definition: MyGUI_WidgetManager.h:23
MyGUI::WidgetInfo
Definition: MyGUI_LayoutData.h:23
MyGUI_IObject.h
MyGUI::EventHandle_WidgetStringString
delegates::CMultiDelegate3< Widget *, const std::string &, const std::string & > EventHandle_WidgetStringString
Definition: MyGUI_Widget.h:24
MyGUI::ResourceSkin
Definition: MyGUI_ResourceSkin.h:23
MyGUI::Widget::eventChangeProperty
EventHandle_WidgetStringString eventChangeProperty
Definition: MyGUI_Widget.h:267
MyGUI::Widget::eventChangeCoord
EventHandle_WidgetVoid eventChangeCoord
Definition: MyGUI_Widget.h:273
MyGUI::delegates::MultiDelegate
Definition: MyGUI_Delegate.h:183
MyGUI::UserData
Definition: MyGUI_WidgetUserData.h:18
MyGUI::IntCoord
types::TCoord< int > IntCoord
Definition: MyGUI_Types.h:35
MyGUI::Widget
Widget properties. Skin childs. Widget widget description should be here.
Definition: MyGUI_Widget.h:37
MyGUI::types::TPoint< int >
MyGUI::Widget::createWidgetReal
T * createWidgetReal(const std::string &_skin, float _left, float _top, float _width, float _height, Align _align, const std::string &_name="")
Definition: MyGUI_Widget.h:88
MyGUI::Align
Definition: MyGUI_Align.h:20
MyGUI_ICroppedRectangle.h
MyGUI::ResourceLayout
Definition: MyGUI_ResourceLayout.h:20
MyGUI::Widget::createWidget
T * createWidget(WidgetStyle _style, const std::string &_skin, const IntCoord &_coord, Align _align, const std::string &_layer="", const std::string &_name="")
Definition: MyGUI_Widget.h:106
MyGUI_WidgetInput.h
MyGUI_Prerequest.h
MyGUI::IObject::castType
Type * castType(bool _throw=true)
Definition: MyGUI_IObject.h:18
MYGUI_RTTI_DERIVED
#define MYGUI_RTTI_DERIVED(DerivedType)
Definition: MyGUI_RTTI.h:48
MyGUI::Enumerator
Definition: MyGUI_Enumerator.h:49
MyGUI::MemberObsolete
Definition: MyGUI_DeprecatedTypes.h:14
MyGUI::types::TSize
Definition: MyGUI_TSize.h:19
MyGUI::ICroppedRectangle
Definition: MyGUI_ICroppedRectangle.h:17
MyGUI::WidgetStyle
Definition: MyGUI_WidgetStyle.h:19
MyGUI::Widget::createWidgetReal
T * createWidgetReal(const std::string &_skin, const FloatCoord &_coord, Align _align, const std::string &_name="")
Definition: MyGUI_Widget.h:81
MyGUI::IObject
Definition: MyGUI_IObject.h:17
MyGUI::Widget::assignWidget
void assignWidget(T *&_widget, const std::string &_name)
Definition: MyGUI_Widget.h:329
MyGUI::SkinItem
Definition: MyGUI_SkinItem.h:21
MyGUI::Colour
Definition: MyGUI_Colour.h:17
MYGUI_EXPORT
#define MYGUI_EXPORT
Definition: MyGUI_Platform.h:89
MyGUI_ResourceLayout.h
MyGUI::WidgetStyle::Child
@ Child
Definition: MyGUI_WidgetStyle.h:22
MyGUI::types::TCoord< int >
MyGUI::Widget::findWidget
Widget * findWidget(const std::string &_name)
Definition: MyGUI_Widget.cpp:535
MyGUI_BackwardCompatibility.h
MyGUI
Definition: MyGUI_ActionController.h:15
MyGUI_Any.h
MyGUI::Widget::createWidget
T * createWidget(const std::string &_skin, int _left, int _top, int _width, int _height, Align _align, const std::string &_name="")
Definition: MyGUI_Widget.h:74
MyGUI_SkinItem.h
MyGUI::ILayerItem
Definition: MyGUI_ILayerItem.h:20
MyGUI::VectorWidgetPtr
std::vector< Widget * > VectorWidgetPtr
Definition: MyGUI_WidgetDefines.h:20
MyGUI_ResourceSkin.h