MyGUI: MyGUI_Widget.h Source File

MyGUI 3.4.2

- Main Page
- Related Pages
- Namespaces
- Data Structures
- Files
- Examples

- File List
- Globals

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_ICroppedRectangle.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"
19#include "MyGUI_BackwardCompatibility.h"
20
21namespace MyGUI
22{
23
24 typedef delegates::CMultiDelegate3<Widget*, const std::string&, const std::string&> EventHandle_WidgetStringString;
25
29 class MYGUI_EXPORT Widget :
30 public IObject,
31 public ICroppedRectangle,
32 public UserData,
33 public WidgetInput,
34 public delegates::IDelegateUnlink,
35 public SkinItem,
36 public MemberObsolete<Widget>
37 {
38 // для вызова закрытых деструкторов
39 friend class WidgetManager;
40
41 MYGUI_RTTI_DERIVED( Widget )
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
192 IntSize getParentSize() const;
193
195 EnumeratorWidgetPtr getEnumerator() const;
196
198 size_t getChildCount() const;
199
201 Widget* getChildAt(size_t _index) const;
202
207 Widget* findWidget(const std::string& _name);
208
212 void findWidgets(const std::string& _name, VectorWidgetPtr& _result);
213
215 virtual void setEnabled(bool _value);
217 void setEnabledSilent(bool _value);
219 bool getEnabled() const;
220
222 bool getInheritedEnabled() const;
223
225 IntCoord getClientCoord() const;
226
228 Widget* getClientWidget();
229 const Widget* getClientWidget() const;
230
234 void detachFromWidget(const std::string& _layer = "");
235
241 void attachToWidget(Widget* _parent, WidgetStyle _style = WidgetStyle::Child, const std::string& _layer = "");
242
244 void changeWidgetSkin(const std::string& _skinName);
245
251 void setWidgetStyle(WidgetStyle _style, const std::string& _layer = "");
253 WidgetStyle getWidgetStyle() const;
254
259 void setProperty(const std::string& _key, const std::string& _value);
260
261
268 EventHandle_WidgetStringString eventChangeProperty;
269
274 EventHandle_WidgetVoid eventChangeCoord;
275
280 EventHandle_WidgetVoid eventWidgetDestroyed;
281
282 /*internal:*/
283 // метод для запроса номера айтема и контейнера
284 virtual size_t _getItemIndex(Widget* _item) const;
285
286 // дает приоритет виджету при пиккинге
287 void _forcePick(Widget* _widget);
288
289 void _initialise(WidgetStyle _style, const IntCoord& _coord, const std::string& _skinName, Widget* _parent, ICroppedRectangle* _croppedParent, const std::string& _name);
290 void _shutdown();
291
292 // удяляет неудачника
293 void _destroyChildWidget(Widget* _widget);
294
295 void _setContainer(Widget* _value);
296 Widget* _getContainer() const;
297
298 void _setAlign(const IntSize& _oldsize, const IntSize& _newSize);
299 bool _checkPoint(int _left, int _top) const;
300
301 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 = "");
302
303 // сброс всех данных контейнера, тултипы и все остальное
304 virtual void _resetContainer(bool _update);
305
306 bool _setWidgetState(const std::string& _value);
307
308 // перерисовывает детей
309 void _updateChilds();
310
311 protected:
312 // все создание только через фабрику
313 ~Widget() override = default;
314
315 virtual void shutdownOverride();
316 virtual void initialiseOverride();
317
318 void _updateView(); // обновления себя и детей
319
320 // создает виджет
321 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);
322
323 // удаляет всех детей
324 void _destroyAllChildWidget();
325
326 // запрашиваем у конейтера айтем по позиции мыши
327 virtual size_t _getContainerIndex(const IntPoint& _point) const;
328
329 virtual void baseUpdateEnable();
330
331 // наследуемся он LayerInfo
332 ILayerItem* getLayerItemByPoint(int _left, int _top) const override;
333 const IntCoord& getLayerItemCoord() const override;
334
335 template <typename T>
336 void assignWidget(T*& _widget, const std::string& _name)
337 {
338 _widget = nullptr;
339 for (VectorWidgetPtr::iterator iter = mWidgetChildSkin.begin(); iter != mWidgetChildSkin.end(); ++iter)
340 {
341 Widget* find = (*iter)->findWidget(_name);
342 if (nullptr != find)
343 {
344 _widget = find->castType<T>(false);
345 break;
346 }
347 }
348 }
349
350 VectorWidgetPtr getSkinWidgetsByName(const std::string& _name) const;
351
352 virtual void onWidgetCreated(Widget* _widget);
353 virtual void onWidgetDestroy(Widget* _widget);
354
355 void setWidgetClient(Widget* _widget);
357 Widget* _getClientWidget();
358 const Widget* _getClientWidget() const;
359
360 virtual void setPropertyOverride(const std::string& _key, const std::string& _value);
361
362 private:
363 const WidgetInfo* initialiseWidgetSkinBase(ResourceSkin* _info, ResourceLayout* _templateInfo);
364 void shutdownWidgetSkinBase();
365
366 void _updateAlpha();
367 void _updateAbsolutePoint();
368
369 // для внутреннего использования
370 void _updateVisible();
371
372 void _updateEnabled();
373
374 float _getRealAlpha() const;
375
376 void _createChildSkinWidget(ResourceSkin* _info);
377 void _destroyChildSkinWidget();
378
379 void _parseSkinProperties(ResourceSkin* _info);
380 void _checkInheristProperties();
381
382 void _linkChildWidget(Widget* _widget);
383 void _unlinkChildWidget(Widget* _widget);
384
385 void setSkinProperty(ResourceSkin* _info);
386
387 void resizeLayerItemView(const IntSize& _oldView, const IntSize& _newView) override;
388
389 void addWidget(Widget* _widget);
390
391 private:
392 // клиентская зона окна
393 // если виджет имеет пользовательские окна не в себе
394 // то обязательно проинициализировать Client
395 Widget* mWidgetClient;
396
397 // вектор всех детей виджетов
398 VectorWidgetPtr mWidgetChild;
399
400 // вектор детей скина
401 VectorWidgetPtr mWidgetChildSkin;
402
403 // availability for mouse/keyboard
404 bool mEnabled;
405 bool mInheritedEnabled;
406 // visibility on screen and for mouse
407 bool mVisible;
408 bool mInheritedVisible;
409 // transparency and transparency inheritance
410 float mAlpha;
411 float mRealAlpha;
412 bool mInheritsAlpha;
413 std::string mName;
414
415 // parent in widgets hierarchy
416 Widget* mParent;
417
418 WidgetStyle mWidgetStyle;
419
420 Widget* mContainer;
421
422 Align mAlign;
423 int mDepth;
424 };
425
426} // namespace MyGUI
427
428#endif // MYGUI_WIDGET_H_
MyGUI_Any.h
MyGUI_BackwardCompatibility.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:48
MyGUI_ResourceLayout.h
MyGUI_ResourceSkin.h
MyGUI_SkinItem.h
MyGUI_WidgetInput.h
MyGUI_WidgetUserData.h
MyGUI::Enumerator
Definition MyGUI_Enumerator.h:49
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:20
MyGUI::ResourceSkin
Definition MyGUI_ResourceSkin.h:23
MyGUI::SkinItem
Definition MyGUI_SkinItem.h:21
MyGUI::UserData
Definition MyGUI_WidgetUserData.h:18
MyGUI::Widget
widget description should be here.
Definition MyGUI_Widget.h:37
MyGUI::Widget::createWidget
T * createWidget(const std::string &_skin, const IntCoord &_coord, Align _align, const std::string &_name="")
Definition MyGUI_Widget.h:67
MyGUI::Widget::eventChangeProperty
EventHandle_WidgetStringString eventChangeProperty
Definition MyGUI_Widget.h:268
MyGUI::Widget::assignWidget
void assignWidget(T *&_widget, const std::string &_name)
Definition MyGUI_Widget.h:336
MyGUI::Widget::findWidget
Widget * findWidget(const std::string &_name)
Definition MyGUI_Widget.cpp:537
MyGUI::Widget::createWidgetReal
T * createWidgetReal(const std::string &_skin, const FloatCoord &_coord, Align _align, const std::string &_name="")
Definition MyGUI_Widget.h:81
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::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::Widget::eventChangeCoord
EventHandle_WidgetVoid eventChangeCoord
Definition MyGUI_Widget.h:274
MyGUI::Widget::~Widget
~Widget() override=default
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::Widget::eventWidgetDestroyed
EventHandle_WidgetVoid eventWidgetDestroyed
Definition MyGUI_Widget.h:280
MyGUI::WidgetInput
Definition MyGUI_WidgetInput.h:60
MyGUI::WidgetManager
Definition MyGUI_WidgetManager.h:22
MyGUI::delegates::IDelegateUnlink
Definition MyGUI_Delegate.h:23
MyGUI::delegates::MultiDelegate
Definition MyGUI_Delegate.h:200
MyGUI
Definition MyGUI_ActionController.h:15
MyGUI::EventHandle_WidgetStringString
delegates::CMultiDelegate3< Widget *, const std::string &, const std::string & > EventHandle_WidgetStringString
Definition MyGUI_Widget.h:24
MyGUI::VectorWidgetPtr
std::vector< Widget * > VectorWidgetPtr
Definition MyGUI_WidgetDefines.h:20
MyGUI::Align
Definition MyGUI_Align.h:20
MyGUI::Colour
Definition MyGUI_Colour.h:17
MyGUI::WidgetInfo
Definition MyGUI_LayoutData.h:23
MyGUI::WidgetStyle
Definition MyGUI_WidgetStyle.h:19
MyGUI::types::TCoord< int >
MyGUI::types::TPoint< int >
MyGUI::types::TSize< int >