MyGUI 3.4.1
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"
14#include "MyGUI_WidgetInput.h"
15#include "MyGUI_ResourceSkin.h"
17#include "MyGUI_IObject.h"
18#include "MyGUI_SkinItem.h"
20
21namespace 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() const;
198
200 Widget* getChildAt(size_t _index) const;
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() const;
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
280
281 /*internal:*/
282 // метод для запроса номера айтема и контейнера
283 virtual size_t _getItemIndex(Widget* _item) const;
284
285 // дает приоритет виджету при пиккинге
286 void _forcePick(Widget* _widget);
287
288 void _initialise(WidgetStyle _style, const IntCoord& _coord, const std::string& _skinName, Widget* _parent, ICroppedRectangle* _croppedParent, const std::string& _name);
289 void _shutdown();
290
291 // удяляет неудачника
292 void _destroyChildWidget(Widget* _widget);
293
294 void _setContainer(Widget* _value);
295 Widget* _getContainer() const;
296
297 void _setAlign(const IntSize& _oldsize, const IntSize& _newSize);
298 bool _checkPoint(int _left, int _top) const;
299
300 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 = "");
301
302 // сброс всех данных контейнера, тултипы и все остальное
303 virtual void _resetContainer(bool _update);
304
305 bool _setWidgetState(const std::string& _value);
306
307 // перерисовывает детей
308 void _updateChilds();
309
310 protected:
311 // все создание только через фабрику
312 ~Widget() override = default;
313
314 virtual void shutdownOverride();
315 virtual void initialiseOverride();
316
317 void _updateView(); // обновления себя и детей
318
319 // создает виджет
320 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);
321
322 // удаляет всех детей
323 void _destroyAllChildWidget();
324
325 // запрашиваем у конейтера айтем по позиции мыши
326 virtual size_t _getContainerIndex(const IntPoint& _point) const;
327
328 virtual void baseUpdateEnable();
329
330 // наследуемся он LayerInfo
331 ILayerItem* getLayerItemByPoint(int _left, int _top) const override;
332 const IntCoord& getLayerItemCoord() const override;
333
334 template <typename T>
335 void assignWidget(T*& _widget, const std::string& _name)
336 {
337 _widget = nullptr;
338 for (VectorWidgetPtr::iterator iter = mWidgetChildSkin.begin(); iter != mWidgetChildSkin.end(); ++iter)
339 {
340 Widget* find = (*iter)->findWidget(_name);
341 if (nullptr != find)
342 {
343 _widget = find->castType<T>(false);
344 break;
345 }
346 }
347 }
348
349 VectorWidgetPtr getSkinWidgetsByName(const std::string& _name) const;
350
351 virtual void onWidgetCreated(Widget* _widget);
352 virtual void onWidgetDestroy(Widget* _widget);
353
354 void setWidgetClient(Widget* _widget);
356 Widget* _getClientWidget();
357 const Widget* _getClientWidget() const;
358
359 virtual void setPropertyOverride(const std::string& _key, const std::string& _value);
360
361 private:
362 const WidgetInfo* initialiseWidgetSkinBase(ResourceSkin* _info, ResourceLayout* _templateInfo);
363 void shutdownWidgetSkinBase();
364
365 void _updateAlpha();
366 void _updateAbsolutePoint();
367
368 // для внутреннего использования
369 void _updateVisible();
370
371 void _updateEnabled();
372
373 float _getRealAlpha() const;
374
375 void _createChildSkinWidget(ResourceSkin* _info);
376 void _destroyChildSkinWidget();
377
378 void _parseSkinProperties(ResourceSkin* _info);
379 void _checkInheristProperties();
380
381 void _linkChildWidget(Widget* _widget);
382 void _unlinkChildWidget(Widget* _widget);
383
384 void setSkinProperty(ResourceSkin* _info);
385
386 void resizeLayerItemView(const IntSize& _oldView, const IntSize& _newView) override;
387
388 void addWidget(Widget* _widget);
389
390 private:
391 // клиентская зона окна
392 // если виджет имеет пользовательские окна не в себе
393 // то обязательно проинициализировать Client
394 Widget* mWidgetClient;
395
396 // вектор всех детей виджетов
397 VectorWidgetPtr mWidgetChild;
398
399 // вектор детей скина
400 VectorWidgetPtr mWidgetChildSkin;
401
402 // availability for mouse/keyboard
403 bool mEnabled;
404 bool mInheritedEnabled;
405 // visibility on screen and for mouse
406 bool mVisible;
407 bool mInheritedVisible;
408 // transparency and transparency inheritance
409 float mAlpha;
410 float mRealAlpha;
411 bool mInheritsAlpha;
412 std::string mName;
413
414 // parent in widgets hierarchy
415 Widget* mParent;
416
417 WidgetStyle mWidgetStyle;
418
419 Widget* mContainer;
420
421 Align mAlign;
422 int mDepth;
423 };
424
425} // namespace MyGUI
426
427#endif // MYGUI_WIDGET_H_
#define MYGUI_EXPORT
#define MYGUI_RTTI_DERIVED(DerivedType)
Definition: MyGUI_RTTI.h:48
Type * castType(bool _throw=true)
Definition: MyGUI_IObject.h:18
widget description should be here.
Definition: MyGUI_Widget.h:37
T * createWidget(const std::string &_skin, const IntCoord &_coord, Align _align, const std::string &_name="")
Definition: MyGUI_Widget.h:67
EventHandle_WidgetStringString eventChangeProperty
Definition: MyGUI_Widget.h:267
void assignWidget(T *&_widget, const std::string &_name)
Definition: MyGUI_Widget.h:335
Widget * findWidget(const std::string &_name)
T * createWidgetReal(const std::string &_skin, const FloatCoord &_coord, Align _align, const std::string &_name="")
Definition: MyGUI_Widget.h:81
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
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
EventHandle_WidgetVoid eventChangeCoord
Definition: MyGUI_Widget.h:273
~Widget() override=default
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
EventHandle_WidgetVoid eventWidgetDestroyed
Definition: MyGUI_Widget.h:279
delegates::CMultiDelegate3< Widget *, const std::string &, const std::string & > EventHandle_WidgetStringString
Definition: MyGUI_Widget.h:24
types::TCoord< int > IntCoord
Definition: MyGUI_Types.h:35
std::vector< Widget * > VectorWidgetPtr