MyGUI 3.2.0

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

- File List
- Globals

MyGUI_Widget.h
Go to the documentation of this file.
1
6 /*
7 This file is part of MyGUI.
8
9 MyGUI is free software: you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 MyGUI is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public License
20 along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
21 */
22 #ifndef __MYGUI_WIDGET_H__
23 #define __MYGUI_WIDGET_H__
24
25 #include "MyGUI_Prerequest.h"
26 #include "MyGUI_Any.h"
27 #include "MyGUI_ICroppedRectangle.h"
28 #include "MyGUI_WidgetUserData.h"
29 #include "MyGUI_WidgetInput.h"
30 #include "MyGUI_ResourceSkin.h"
31 #include "MyGUI_ResourceLayout.h"
32 #include "MyGUI_IObject.h"
33 #include "MyGUI_SkinItem.h"
34 #include "MyGUI_BackwardCompatibility.h"
35
36 namespace MyGUI
37 {
38
39 typedef delegates::CMultiDelegate3<Widget*, const std::string&, const std::string&> EventHandle_WidgetStringString;
40
41 class MYGUI_EXPORT Widget :
42 public IObject,
43 public ICroppedRectangle,
44 public UserData,
45 public WidgetInput,
46 public delegates::IDelegateUnlink,
47 public SkinItem,
48 public MemberObsolete<Widget>
49 {
50 // для вызова закрытых деструкторов
51 friend class WidgetManager;
52
53 MYGUI_RTTI_DERIVED( Widget )
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
114 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 = "");
115
117 template <typename T>
118 T* createWidget(WidgetStyle _style, const std::string& _skin, const IntCoord& _coord, Align _align, const std::string& _layer = "", const std::string& _name = "")
119 {
120 return static_cast<T*>(createWidgetT(_style, T::getClassTypeName(), _skin, _coord, _align, _layer, _name));
121 }
122
124 virtual void setPosition(const IntPoint& _value);
126 virtual void setSize(const IntSize& _value);
128 virtual void setCoord(const IntCoord& _value);
129
131 void setPosition(int _left, int _top);
133 void setSize(int _width, int _height);
135 void setCoord(int _left, int _top, int _width, int _height);
136
138 void setRealPosition(const FloatPoint& _value);
140 void setRealSize(const FloatSize& _value);
142 void setRealCoord(const FloatCoord& _value);
143
145 void setRealPosition(float _left, float _top);
147 void setRealSize(float _width, float _height);
149 void setRealCoord(float _left, float _top, float _width, float _height);
150
152 const std::string& getName() const;
153
155 virtual void setVisible(bool _value);
157 bool getVisible() const;
158
160 bool getInheritedVisible() const;
161
163 virtual void setAlign(Align _value);
165 Align getAlign() const;
166
168 void setAlpha(float _value);
170 float getAlpha() const;
171
182 void setInheritsAlpha(bool _value);
184 bool getInheritsAlpha() const;
185
186 void setColour(const Colour& _value);
187
188 // являемся ли мы рутовым виджетом
190 bool isRootWidget() const;
191
193 Widget* getParent() const;
194
195 IntSize getParentSize() const;
196
198 EnumeratorWidgetPtr getEnumerator() const;
199
201 size_t getChildCount();
202
204 Widget* getChildAt(size_t _index);
205
210 Widget* findWidget(const std::string& _name);
211
215 void findWidgets(const std::string& _name, VectorWidgetPtr& _result);
216
218 virtual void setEnabled(bool _value);
220 void setEnabledSilent(bool _value);
222 bool getEnabled() const;
223
225 bool getInheritedEnabled() const;
226
228 IntCoord getClientCoord();
229
231 Widget* getClientWidget();
232
236 void detachFromWidget(const std::string& _layer = "");
237
243 void attachToWidget(Widget* _parent, WidgetStyle _style = WidgetStyle::Child, const std::string& _layer = "");
244
246 void changeWidgetSkin(const std::string& _skinName);
247
253 void setWidgetStyle(WidgetStyle _style, const std::string& _layer = "");
255 WidgetStyle getWidgetStyle() const;
256
261 void setProperty(const std::string& _key, const std::string& _value);
262
263
270 EventHandle_WidgetStringString
271 eventChangeProperty;
272
273 /*internal:*/
274 // метод для запроса номера айтема и контейнера
275 virtual size_t _getItemIndex(Widget* _item);
276
277 // дает приоритет виджету при пиккинге
278 void _forcePick(Widget* _widget);
279
280 void _initialise(WidgetStyle _style, const IntCoord& _coord, const std::string& _skinName, Widget* _parent, ICroppedRectangle* _croppedParent, const std::string& _name);
281 void _shutdown();
282
283 // удяляет неудачника
284 void _destroyChildWidget(Widget* _widget);
285
286 void _setContainer(Widget* _value);
287 Widget* _getContainer();
288
289 void _setAlign(const IntSize& _oldsize, const IntSize& _newSize);
290 bool _checkPoint(int _left, int _top) const;
291
292 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 = "");
293
294 // сброс всех данных контейнера, тултипы и все остальное
295 virtual void _resetContainer(bool _update);
296
297 bool _setWidgetState(const std::string& _value);
298
299 protected:
300 // все создание только через фабрику
301 virtual ~Widget();
302
303 virtual void shutdownOverride();
304 virtual void initialiseOverride();
305
306 void _updateView(); // обновления себя и детей
307
308 // создает виджет
309 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);
310
311 // удаляет всех детей
312 void _destroyAllChildWidget();
313
314 // запрашиваем у конейтера айтем по позиции мыши
315 virtual size_t _getContainerIndex(const IntPoint& _point);
316
317 virtual void baseUpdateEnable();
318
319 // наследуемся он LayerInfo
320 virtual ILayerItem* getLayerItemByPoint(int _left, int _top) const;
321 virtual const IntCoord& getLayerItemCoord() const;
322
323 template <typename T>
324 void assignWidget(T * & _widget, const std::string& _name)
325 {
326 _widget = nullptr;
327 for (VectorWidgetPtr::iterator iter = mWidgetChildSkin.begin(); iter != mWidgetChildSkin.end(); ++iter)
328 {
329 Widget* find = (*iter)->findWidget(_name);
330 if (nullptr != find)
331 {
332 _widget = find->castType<T>(false);
333 break;
334 }
335 }
336 }
337
338 VectorWidgetPtr getSkinWidgetsByName(const std::string& _name);
339
340 void destroySkinWidget(Widget* _widget);
341
342 virtual void onWidgetCreated(Widget* _widget);
343 virtual void onWidgetDestroy(Widget* _widget);
344
345 void setWidgetClient(Widget* _widget);
346
347 virtual void setPropertyOverride(const std::string& _key, const std::string& _value);
348
349 private:
350 void frameEntered(float _frame);
351
352 const WidgetInfo* initialiseWidgetSkinBase(ResourceSkin* _info, ResourceLayout* _templateInfo);
353 void shutdownWidgetSkinBase();
354
355 void _updateAlpha();
356 void _updateAbsolutePoint();
357
358 // для внутреннего использования
359 void _updateVisible();
360
361 void _updateEnabled();
362
363 float _getRealAlpha() const;
364
365 void _createChildSkinWidget(ResourceSkin* _info);
366 void _destroyChildSkinWidget();
367
368 void _parseSkinProperties(ResourceSkin* _info);
369 void _checkInheristProperties();
370
371 void _linkChildWidget(Widget* _widget);
372 void _unlinkChildWidget(Widget* _widget);
373
374 void setSkinProperty(ResourceSkin* _info);
375
376 virtual void resizeLayerItemView(const IntSize& _oldView, const IntSize& _newView);
377
378 private:
379 // клиентская зона окна
380 // если виджет имеет пользовательские окна не в себе
381 // то обязательно проинициализировать Client
382 Widget* mWidgetClient;
383
384 // вектор всех детей виджетов
385 VectorWidgetPtr mWidgetChild;
386
387 // вектор детей скина
388 VectorWidgetPtr mWidgetChildSkin;
389
390 // доступен ли на виджет
391 bool mEnabled;
392 bool mInheritsEnabled;
393 // для иерархического скрытия
394 bool mInheritsVisible;
395 // прозрачность и флаг наследования альфы нашего оверлея
396 float mAlpha;
397 float mRealAlpha;
398 bool mInheritsAlpha;
399 // имя виджета
400 std::string mName;
401
402 // наш отец в иерархии виджетов
403 Widget* mParent;
404
405 // поведение виджета, перекрывающийся дочерний или всплывающий
406 WidgetStyle mWidgetStyle;
407
408 Widget* mContainer;
409
410 Align mAlign;
411 bool mVisible;
412 };
413
414 } // namespace MyGUI
415
416 #endif // __MYGUI_WIDGET_H__
MyGUI::types::TCoord< int >
MyGUI_SkinItem.h
MyGUI::Widget
Definition: MyGUI_Widget.h:41
MyGUI::ResourceSkin
Definition: MyGUI_ResourceSkin.h:36
MyGUI::delegates::IDelegateUnlink
Definition: MyGUI_Delegate.h:42
MyGUI::types::TPoint< int >
MyGUI_Prerequest.h
MyGUI::types::TSize< int >
MyGUI_WidgetInput.h
MyGUI::Widget::createWidgetReal
T * createWidgetReal(const std::string &_skin, const FloatCoord &_coord, Align _align, const std::string &_name="")
Definition: MyGUI_Widget.h:93
MyGUI::Widget::assignWidget
void assignWidget(T *&_widget, const std::string &_name)
Definition: MyGUI_Widget.h:324
MyGUI::WidgetManager
Definition: MyGUI_WidgetManager.h:35
MyGUI::delegates::CMultiDelegate3< Widget *, const std::string &, const std::string & >
MyGUI::SkinItem
Definition: MyGUI_SkinItem.h:34
MyGUI::EventHandle_WidgetStringString
delegates::CMultiDelegate3< Widget *, const std::string &, const std::string & > EventHandle_WidgetStringString
Definition: MyGUI_Widget.h:39
MyGUI::IntCoord
types::TCoord< int > IntCoord
Definition: MyGUI_Types.h:50
MyGUI::WidgetInput
Definition: MyGUI_WidgetInput.h:74
MyGUI::Enumerator
Definition: MyGUI_Enumerator.h:63
MyGUI_ICroppedRectangle.h
MyGUI::ResourceLayout
Definition: MyGUI_ResourceLayout.h:33
MyGUI::Widget::findWidget
Widget * findWidget(const std::string &_name)
Definition: MyGUI_Widget.cpp:545
MyGUI::WidgetStyle::Child
Definition: MyGUI_WidgetStyle.h:35
MYGUI_RTTI_DERIVED
#define MYGUI_RTTI_DERIVED(DerivedType)
Definition: MyGUI_RTTI.h:88
MyGUI::Widget::eventChangeProperty
EventHandle_WidgetStringString eventChangeProperty
Definition: MyGUI_Widget.h:271
MYGUI_EXPORT
#define MYGUI_EXPORT
Definition: MyGUI_Platform.h:120
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:86
MyGUI::VectorWidgetPtr
std::vector< Widget * > VectorWidgetPtr
Definition: MyGUI_WidgetDefines.h:33
MyGUI_BackwardCompatibility.h
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:100
MyGUI::WidgetInfo
Definition: MyGUI_LayoutData.h:37
MyGUI_ResourceSkin.h
MyGUI_Any.h
MyGUI::IObject::castType
Type * castType(bool _throw=true)
Definition: MyGUI_IObject.h:33
MyGUI_IObject.h
MyGUI_ResourceLayout.h
MyGUI::UserData
Definition: MyGUI_WidgetUserData.h:32
MyGUI::ILayerItem
Definition: MyGUI_ILayerItem.h:33
MyGUI::IObject
Definition: MyGUI_IObject.h:31
MyGUI::WidgetStyle
Definition: MyGUI_WidgetStyle.h:31
MyGUI::ICroppedRectangle
Definition: MyGUI_ICroppedRectangle.h:31
MyGUI::MemberObsolete
Definition: MyGUI_DeprecatedTypes.h:28
MyGUI_WidgetUserData.h
MyGUI::Align
Definition: MyGUI_Align.h:34
MyGUI::Colour
Definition: MyGUI_Colour.h:31
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:118