MyGUI: MyGUI_Widget.h Source File

MyGUI 3.4.3

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"
12#include "MyGUI_EventPair.h"
13#include "MyGUI_ICroppedRectangle.h"
14#include "MyGUI_WidgetUserData.h"
15#include "MyGUI_WidgetInput.h"
16#include "MyGUI_ResourceSkin.h"
17#include "MyGUI_ResourceLayout.h"
18#include "MyGUI_IObject.h"
19#include "MyGUI_SkinItem.h"
20#include "MyGUI_BackwardCompatibility.h"
21
22namespace MyGUI
23{
24
25 using EventHandle_WidgetStringString = EventPairConvertStringView<
26 delegates::MultiDelegate<Widget*, const std::string&, const std::string&>,
27 delegates::MultiDelegate<Widget*, std::string_view, std::string_view>>;
28
32 class MYGUI_EXPORT Widget :
33 public IObject,
34 public ICroppedRectangle,
35 public UserData,
36 public WidgetInput,
37 public delegates::IDelegateUnlink,
38 public SkinItem,
39 public MemberObsolete<Widget>
40 {
41 // для вызова закрытых деструкторов
42 friend class WidgetManager;
43
44 MYGUI_RTTI_DERIVED(Widget)
45
46 public:
54 Widget* createWidgetT(
55 std::string_view _type,
56 std::string_view _skin,
57 const IntCoord& _coord,
58 Align _align,
59 std::string_view _name = {});
60
62 Widget* createWidgetT(
63 std::string_view _type,
64 std::string_view _skin,
65 int _left,
66 int _top,
67 int _width,
68 int _height,
69 Align _align,
70 std::string_view _name = {});
71
73 Widget* createWidgetRealT(
74 std::string_view _type,
75 std::string_view _skin,
76 const FloatCoord& _coord,
77 Align _align,
78 std::string_view _name = {});
79
81 Widget* createWidgetRealT(
82 std::string_view _type,
83 std::string_view _skin,
84 float _left,
85 float _top,
86 float _width,
87 float _height,
88 Align _align,
89 std::string_view _name = {});
90
91 // templates for creating widgets by type
93 template<typename T>
94 T* createWidget(std::string_view _skin, const IntCoord& _coord, Align _align, std::string_view _name = {})
95 {
96 return static_cast<T*>(createWidgetT(T::getClassTypeName(), _skin, _coord, _align, _name));
97 }
98
100 template<typename T>
101 T* createWidget(
102 std::string_view _skin,
103 int _left,
104 int _top,
105 int _width,
106 int _height,
107 Align _align,
108 std::string_view _name = {})
109 {
110 return static_cast<T*>(
111 createWidgetT(T::getClassTypeName(), _skin, IntCoord(_left, _top, _width, _height), _align, _name));
112 }
113
115 template<typename T>
116 T* createWidgetReal(std::string_view _skin, const FloatCoord& _coord, Align _align, std::string_view _name = {})
117 {
118 return static_cast<T*>(createWidgetRealT(T::getClassTypeName(), _skin, _coord, _align, _name));
119 }
120
122 template<typename T>
123 T* createWidgetReal(
124 std::string_view _skin,
125 float _left,
126 float _top,
127 float _width,
128 float _height,
129 Align _align,
130 std::string_view _name = {})
131 {
132 return static_cast<T*>(
133 createWidgetRealT(T::getClassTypeName(), _skin, _left, _top, _width, _height, _align, _name));
134 }
135
145 Widget* createWidgetT(
146 WidgetStyle _style,
147 std::string_view _type,
148 std::string_view _skin,
149 const IntCoord& _coord,
150 Align _align,
151 std::string_view _layer = {},
152 std::string_view _name = {});
153
155 template<typename T>
156 T* createWidget(
157 WidgetStyle _style,
158 std::string_view _skin,
159 const IntCoord& _coord,
160 Align _align,
161 std::string_view _layer = {},
162 std::string_view _name = {})
163 {
164 return static_cast<T*>(createWidgetT(_style, T::getClassTypeName(), _skin, _coord, _align, _layer, _name));
165 }
166
168 void setPosition(const IntPoint& _point) override;
170 void setSize(const IntSize& _size) override;
172 void setCoord(const IntCoord& _coord) override;
173
175 void setPosition(int _left, int _top);
177 void setSize(int _width, int _height);
179 void setCoord(int _left, int _top, int _width, int _height);
180
182 void setRealPosition(const FloatPoint& _point);
184 void setRealSize(const FloatSize& _size);
186 void setRealCoord(const FloatCoord& _coord);
187
189 void setRealPosition(float _left, float _top);
191 void setRealSize(float _width, float _height);
193 void setRealCoord(float _left, float _top, float _width, float _height);
194
196 const std::string& getName() const;
197
199 virtual void setVisible(bool _value);
201 bool getVisible() const;
202
207 void setDepth(int _value);
209 int getDepth() const;
210
212 bool getInheritedVisible() const;
213
215 virtual void setAlign(Align _value);
217 Align getAlign() const;
218
220 void setAlpha(float _alpha);
222 float getAlpha() const;
223
234 void setInheritsAlpha(bool _inherits);
236 bool getInheritsAlpha() const;
237
238 void setColour(const Colour& _value);
239
240 // являемся ли мы рутовым виджетом
242 bool isRootWidget() const;
243
245 Widget* getParent() const;
246
248 IntSize getParentSize() const;
249
251 EnumeratorWidgetPtr getEnumerator() const;
252
254 size_t getChildCount() const;
255
257 Widget* getChildAt(size_t _index) const;
258
263 Widget* findWidget(std::string_view _name);
264
268 void findWidgets(std::string_view _name, VectorWidgetPtr& _result);
269
271 virtual void setEnabled(bool _value);
273 void setEnabledSilent(bool _value);
275 bool getEnabled() const;
276
278 bool getInheritedEnabled() const;
279
281 IntCoord getClientCoord() const;
282
284 Widget* getClientWidget();
285 const Widget* getClientWidget() const;
286
290 void detachFromWidget(std::string_view _layer = {});
291
297 void attachToWidget(Widget* _parent, WidgetStyle _style = WidgetStyle::Child, std::string_view _layer = {});
298
300 void changeWidgetSkin(std::string_view _skinName);
301
307 void setWidgetStyle(WidgetStyle _style, std::string_view _layer = {});
309 WidgetStyle getWidgetStyle() const;
310
315 void setProperty(std::string_view _key, std::string_view _value);
316
317
324 EventHandle_WidgetStringString eventChangeProperty;
325
330 EventHandle_WidgetVoid eventChangeCoord;
331
336 EventHandle_WidgetVoid eventWidgetDestroyed;
337
338 /*internal:*/
339 // метод для запроса номера айтема и контейнера
340 virtual size_t _getItemIndex(Widget* _item) const;
341
342 // дает приоритет виджету при пиккинге
343 void _forcePick(Widget* _widget);
344
345 void _initialise(
346 WidgetStyle _style,
347 const IntCoord& _coord,
348 std::string_view _skinName,
349 Widget* _parent,
350 ICroppedRectangle* _croppedParent,
351 std::string_view _name);
352 void _shutdown();
353
354 // удяляет неудачника
355 void _destroyChildWidget(Widget* _widget);
356
357 void _setContainer(Widget* _value);
358 Widget* _getContainer() const;
359
360 void _setAlign(const IntSize& _oldsize, const IntSize& _newSize);
361 bool _checkPoint(int _left, int _top) const;
362
363 Widget* _createSkinWidget(
364 WidgetStyle _style,
365 std::string_view _type,
366 std::string_view _skin,
367 const IntCoord& _coord,
368 Align _align,
369 std::string_view _layer = {},
370 std::string_view _name = {});
371
372 // сброс всех данных контейнера, тултипы и все остальное
373 virtual void _resetContainer(bool _update);
374
375 bool _setWidgetState(std::string_view _state);
376
377 // перерисовывает детей
378 void _updateChilds();
379
380 protected:
381 // все создание только через фабрику
382 ~Widget() override = default;
383
384 virtual void shutdownOverride();
385 virtual void initialiseOverride();
386
387 void _updateView(); // обновления себя и детей
388
389 // создает виджет
390 Widget* baseCreateWidget(
391 WidgetStyle _style,
392 std::string_view _type,
393 std::string_view _skin,
394 const IntCoord& _coord,
395 Align _align,
396 std::string_view _layer,
397 std::string_view _name,
398 bool _template);
399
400 // удаляет всех детей
401 void _destroyAllChildWidget();
402
403 // запрашиваем у конейтера айтем по позиции мыши
404 virtual size_t _getContainerIndex(const IntPoint& _point) const;
405
406 virtual void baseUpdateEnable();
407
408 // наследуемся он LayerInfo
409 ILayerItem* getLayerItemByPoint(int _left, int _top) const override;
410 const IntCoord& getLayerItemCoord() const override;
411
412 template<typename T>
413 void assignWidget(T*& _widget, std::string_view _name)
414 {
415 _widget = nullptr;
416 for (const auto& iter : mWidgetChildSkin)
417 {
418 Widget* find = iter->findWidget(_name);
419 if (nullptr != find)
420 {
421 _widget = find->castType<T>(false);
422 break;
423 }
424 }
425 }
426
427 VectorWidgetPtr getSkinWidgetsByName(std::string_view _name) const;
428
429 virtual void onWidgetCreated(Widget* _widget);
430 virtual void onWidgetDestroy(Widget* _widget);
431
432 void setWidgetClient(Widget* _widget);
434 Widget* _getClientWidget();
435 const Widget* _getClientWidget() const;
436
437 virtual void setPropertyOverride(std::string_view _key, std::string_view _value);
438
439 private:
440 const WidgetInfo* initialiseWidgetSkinBase(ResourceSkin* _skinInfo, ResourceLayout* _templateInfo);
441 void shutdownWidgetSkinBase();
442
443 void _updateAlpha();
444 void _updateAbsolutePoint();
445
446 // для внутреннего использования
447 void _updateVisible();
448
449 void _updateEnabled();
450
451 float _getRealAlpha() const;
452
453 void _createChildSkinWidget(ResourceSkin* _info);
454 void _destroyChildSkinWidget();
455
456 void _parseSkinProperties(ResourceSkin* _info);
457 void _checkInheristProperties();
458
459 void _linkChildWidget(Widget* _widget);
460 void _unlinkChildWidget(Widget* _widget);
461
462 void setSkinProperty(ResourceSkin* _info);
463
464 void resizeLayerItemView(const IntSize& _oldView, const IntSize& _newView) override;
465
466 void addWidget(Widget* _widget);
467
468 private:
469 // клиентская зона окна
470 // если виджет имеет пользовательские окна не в себе
471 // то обязательно проинициализировать Client
472 Widget* mWidgetClient{nullptr};
473
474 // вектор всех детей виджетов
475 VectorWidgetPtr mWidgetChild;
476
477 // вектор детей скина
478 VectorWidgetPtr mWidgetChildSkin;
479
480 // availability for mouse/keyboard
481 bool mEnabled{true};
482 bool mInheritedEnabled{true};
483 // visibility on screen and for mouse
484 bool mVisible{true};
485 bool mInheritedVisible{true};
486 // transparency and transparency inheritance
487 float mAlpha{ALPHA_MAX};
488 float mRealAlpha{ALPHA_MAX};
489 bool mInheritsAlpha{true};
490 std::string mName;
491
492 // parent in widgets hierarchy
493 Widget* mParent{nullptr};
494
495 WidgetStyle mWidgetStyle{WidgetStyle::Child};
496
497 Widget* mContainer{nullptr};
498
499 Align mAlign{Align::Default};
500 int mDepth{0};
501 };
502
503} // namespace MyGUI
504
505#endif // MYGUI_WIDGET_H_
MyGUI_Any.h
MyGUI_BackwardCompatibility.h
MyGUI_EventPair.h
MyGUI_ICroppedRectangle.h
MyGUI_IObject.h
MYGUI_EXPORT
#define MYGUI_EXPORT
Definition MyGUI_Platform.h:77
MyGUI_Prerequest.h
MYGUI_RTTI_DERIVED
#define MYGUI_RTTI_DERIVED(DerivedType)
Definition MyGUI_RTTI.h:69
MyGUI_ResourceLayout.h
MyGUI_ResourceSkin.h
MyGUI_SkinItem.h
MyGUI_WidgetInput.h
MyGUI_WidgetUserData.h
MyGUI::EventPairConvertStringView
Definition MyGUI_EventPair.h:213
MyGUI::ICroppedRectangle
Definition MyGUI_ICroppedRectangle.h:17
MyGUI::ILayerItem
Definition MyGUI_ILayerItem.h:20
MyGUI::IObject
Definition MyGUI_IObject.h:17
MyGUI::IObject::castType
Type * castType(bool _throw=true)
Definition MyGUI_IObject.h:18
MyGUI::MemberObsolete
Definition MyGUI_DeprecatedTypes.h:14
MyGUI::ResourceLayout
Definition MyGUI_ResourceLayout.h:19
MyGUI::ResourceSkin
Definition MyGUI_ResourceSkin.h:22
MyGUI::SkinItem
Definition MyGUI_SkinItem.h:20
MyGUI::UserData
Definition MyGUI_WidgetUserData.h:18
MyGUI::Widget
widget description should be here.
Definition MyGUI_Widget.h:40
MyGUI::Widget::_destroyAllChildWidget
void _destroyAllChildWidget()
Definition MyGUI_Widget.cpp:442
MyGUI::Widget::getLayerItemByPoint
ILayerItem * getLayerItemByPoint(int _left, int _top) const override
Definition MyGUI_Widget.cpp:496
MyGUI::Widget::_checkPoint
bool _checkPoint(int _left, int _top) const
Definition MyGUI_Widget.cpp:1098
MyGUI::Widget::_destroyChildWidget
void _destroyChildWidget(Widget *_widget)
Definition MyGUI_Widget.cpp:411
MyGUI::Widget::eventChangeProperty
EventHandle_WidgetStringString eventChangeProperty
Definition MyGUI_Widget.h:324
MyGUI::Widget::createWidgetReal
T * createWidgetReal(std::string_view _skin, const FloatCoord &_coord, Align _align, std::string_view _name={})
Definition MyGUI_Widget.h:116
MyGUI::Widget::initialiseOverride
virtual void initialiseOverride()
Definition MyGUI_Widget.cpp:1122
MyGUI::Widget::createWidget
T * createWidget(std::string_view _skin, int _left, int _top, int _width, int _height, Align _align, std::string_view _name={})
Definition MyGUI_Widget.h:101
MyGUI::Widget::_shutdown
void _shutdown()
Definition MyGUI_Widget.cpp:112
MyGUI::Widget::_setAlign
void _setAlign(const IntSize &_oldsize, const IntSize &_newSize)
Definition MyGUI_Widget.cpp:612
MyGUI::Widget::baseUpdateEnable
virtual void baseUpdateEnable()
Definition MyGUI_Widget.cpp:1014
MyGUI::Widget::_initialise
void _initialise(WidgetStyle _style, const IntCoord &_coord, std::string_view _skinName, Widget *_parent, ICroppedRectangle *_croppedParent, std::string_view _name)
Definition MyGUI_Widget.cpp:31
MyGUI::Widget::WidgetManager
friend class WidgetManager
Definition MyGUI_Widget.h:42
MyGUI::Widget::getLayerItemCoord
const IntCoord & getLayerItemCoord() const override
Definition MyGUI_Widget.cpp:1402
MyGUI::Widget::createWidgetT
Widget * createWidgetT(std::string_view _type, std::string_view _skin, const IntCoord &_coord, Align _align, std::string_view _name={})
Definition MyGUI_Widget.cpp:944
MyGUI::Widget::findWidget
Widget * findWidget(std::string_view _name)
Definition MyGUI_Widget.cpp:575
MyGUI::Widget::eventChangeCoord
EventHandle_WidgetVoid eventChangeCoord
Definition MyGUI_Widget.h:330
MyGUI::Widget::~Widget
~Widget() override=default
MyGUI::Widget::assignWidget
void assignWidget(T *&_widget, std::string_view _name)
Definition MyGUI_Widget.h:413
MyGUI::Widget::createWidget
T * createWidget(WidgetStyle _style, std::string_view _skin, const IntCoord &_coord, Align _align, std::string_view _layer={}, std::string_view _name={})
Definition MyGUI_Widget.h:156
MyGUI::Widget::_getContainer
Widget * _getContainer() const
Definition MyGUI_Widget.cpp:1392
MyGUI::Widget::_createSkinWidget
Widget * _createSkinWidget(WidgetStyle _style, std::string_view _type, std::string_view _skin, const IntCoord &_coord, Align _align, std::string_view _layer={}, std::string_view _name={})
Definition MyGUI_Widget.cpp:1206
MyGUI::Widget::createWidget
T * createWidget(std::string_view _skin, const IntCoord &_coord, Align _align, std::string_view _name={})
Definition MyGUI_Widget.h:94
MyGUI::Widget::_setContainer
void _setContainer(Widget *_value)
Definition MyGUI_Widget.cpp:1387
MyGUI::Widget::_getContainerIndex
virtual size_t _getContainerIndex(const IntPoint &_point) const
Definition MyGUI_Widget.cpp:1397
MyGUI::Widget::_updateView
void _updateView()
Definition MyGUI_Widget.cpp:359
MyGUI::Widget::_forcePick
void _forcePick(Widget *_widget)
Definition MyGUI_Widget.cpp:547
MyGUI::Widget::eventWidgetDestroyed
EventHandle_WidgetVoid eventWidgetDestroyed
Definition MyGUI_Widget.h:336
MyGUI::Widget::_getItemIndex
virtual size_t _getItemIndex(Widget *_item) const
Definition MyGUI_Widget.cpp:1382
MyGUI::Widget::shutdownOverride
virtual void shutdownOverride()
Definition MyGUI_Widget.cpp:1118
MyGUI::Widget::baseCreateWidget
Widget * baseCreateWidget(WidgetStyle _style, std::string_view _type, std::string_view _skin, const IntCoord &_coord, Align _align, std::string_view _layer, std::string_view _name, bool _template)
Definition MyGUI_Widget.cpp:293
MyGUI::Widget::createWidgetReal
T * createWidgetReal(std::string_view _skin, float _left, float _top, float _width, float _height, Align _align, std::string_view _name={})
Definition MyGUI_Widget.h:123
MyGUI::WidgetInput
Definition MyGUI_WidgetInput.h:60
MyGUI::delegates::IDelegateUnlink
Definition MyGUI_Delegate.h:24
MyGUI::delegates::MultiDelegate
Definition MyGUI_Delegate.h:190
MyGUI
Definition MyGUI_ActionController.h:15
MyGUI::ALPHA_MAX
constexpr float ALPHA_MAX
Definition MyGUI_Macros.h:20
MyGUI::IntPoint
types::TPoint< int > IntPoint
Definition MyGUI_Types.h:27
MyGUI::FloatCoord
types::TCoord< float > FloatCoord
Definition MyGUI_Types.h:37
MyGUI::EnumeratorWidgetPtr
Enumerator< VectorWidgetPtr > EnumeratorWidgetPtr
Definition MyGUI_WidgetDefines.h:22
MyGUI::EventHandle_WidgetVoid
delegates::MultiDelegate< Widget * > EventHandle_WidgetVoid
Definition MyGUI_WidgetInput.h:48
MyGUI::EventHandle_WidgetStringString
EventPairConvertStringView< delegates::MultiDelegate< Widget *, const std::string &, const std::string & >, delegates::MultiDelegate< Widget *, std::string_view, std::string_view > > EventHandle_WidgetStringString
Definition MyGUI_Widget.h:25
MyGUI::IntCoord
types::TCoord< int > IntCoord
Definition MyGUI_Types.h:36
MyGUI::IntSize
types::TSize< int > IntSize
Definition MyGUI_Types.h:30
MyGUI::VectorWidgetPtr
std::vector< Widget * > VectorWidgetPtr
Definition MyGUI_WidgetDefines.h:20
MyGUI::Align
Definition MyGUI_Align.h:20
MyGUI::WidgetInfo
Definition MyGUI_LayoutData.h:23
MyGUI::WidgetStyle
Definition MyGUI_WidgetStyle.h:19