MyGUI  3.2.1
MyGUI_Gui.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_GUI_H__
8 #define __MYGUI_GUI_H__
9 
10 #include "MyGUI_Prerequest.h"
11 #include "MyGUI_Types.h"
12 #include "MyGUI_Singleton.h"
13 #include "MyGUI_XmlDocument.h"
14 #include "MyGUI_IUnlinkWidget.h"
15 #include "MyGUI_Widget.h"
17 
18 namespace MyGUI
19 {
20 
22 
23  class MYGUI_EXPORT Gui :
24  public Singleton<Gui>,
25  public IUnlinkWidget,
26  public MemberObsolete<Gui>
27  {
28  friend class WidgetManager;
29 
30  public:
31  Gui();
32 
39  void initialise(const std::string& _core = "MyGUI_Core.xml");
40 
41 #ifndef MYGUI_DONT_USE_OBSOLETE
42  MYGUI_OBSOLETE(" is deprecated, use : void Gui::initialise(const std::string& _core) and set log filename in Platform")
43  void initialise(const std::string& _core, const std::string& _logFileName);
44 #endif // MYGUI_DONT_USE_OBSOLETE
45 
47  void shutdown();
48 
49  // methods for creating widgets
58  Widget* createWidgetT(const std::string& _type, const std::string& _skin, const IntCoord& _coord, Align _align, const std::string& _layer, const std::string& _name = "");
60  Widget* createWidgetT(const std::string& _type, const std::string& _skin, int _left, int _top, int _width, int _height, Align _align, const std::string& _layer, const std::string& _name = "");
62  Widget* createWidgetRealT(const std::string& _type, const std::string& _skin, const FloatCoord& _coord, Align _align, const std::string& _layer, const std::string& _name = "");
64  Widget* createWidgetRealT(const std::string& _type, const std::string& _skin, float _left, float _top, float _width, float _height, Align _align, const std::string& _layer, const std::string& _name = "");
65 
66  // templates for creating widgets by type
68  template <typename T>
69  T* createWidget(const std::string& _skin, const IntCoord& _coord, Align _align, const std::string& _layer, const std::string& _name = "")
70  {
71  return static_cast<T*>(createWidgetT(T::getClassTypeName(), _skin, _coord, _align, _layer, _name));
72  }
74  template <typename T>
75  T* createWidget(const std::string& _skin, int _left, int _top, int _width, int _height, Align _align, const std::string& _layer, const std::string& _name = "")
76  {
77  return static_cast<T*>(createWidgetT(T::getClassTypeName(), _skin, IntCoord(_left, _top, _width, _height), _align, _layer, _name));
78  }
80  template <typename T>
81  T* createWidgetReal(const std::string& _skin, const FloatCoord& _coord, Align _align, const std::string& _layer, const std::string& _name = "")
82  {
83  return static_cast<T*>(createWidgetRealT(T::getClassTypeName(), _skin, _coord, _align, _layer, _name));
84  }
86  template <typename T>
87  T* createWidgetReal(const std::string& _skin, float _left, float _top, float _width, float _height, Align _align, const std::string& _layer, const std::string& _name = "")
88  {
89  return static_cast<T*>(createWidgetRealT(T::getClassTypeName(), _skin, _left, _top, _width, _height, _align, _layer, _name));
90  }
91 
93  void destroyWidget(Widget* _widget);
94 
96  void destroyWidgets(const VectorWidgetPtr& _widgets);
97 
99  void destroyWidgets(EnumeratorWidgetPtr& _widgets);
100 
104  Widget* findWidgetT(const std::string& _name, bool _throw = true);
105 
109  Widget* findWidgetT(const std::string& _name, const std::string& _prefix, bool _throw = true);
110 
114  template <typename T>
115  T* findWidget(const std::string& _name, bool _throw = true)
116  {
117  Widget* widget = findWidgetT(_name, _throw);
118  if (nullptr == widget) return nullptr;
119  return widget->castType<T>(_throw);
120  }
121 
125  template <typename T>
126  T* findWidget(const std::string& _name, const std::string& _prefix, bool _throw = true)
127  {
128  return findWidget<T>(_prefix + _name, _throw);
129  }
130 
132  void destroyChildWidget(Widget* _widget);
133 
135  void destroyAllChildWidget();
136 
138  EnumeratorWidgetPtr getEnumerator() const;
139 
143  void frameEvent(float _time);
144 
145  /*events:*/
151 
152  /*internal:*/
153  void _linkChildWidget(Widget* _widget);
154  void _unlinkChildWidget(Widget* _widget);
155 
156  private:
157  // создает виджет
158  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);
159 
160  // удяляет неудачника
161  void _destroyChildWidget(Widget* _widget);
162 
163  // удаляет всех детей
164  void _destroyAllChildWidget();
165 
166  virtual void _unlinkWidget(Widget* _widget);
167 
168  private:
169  // вектор всех детей виджетов
170  VectorWidgetPtr mWidgetChild;
171 
172  // синглтоны гуя
173  InputManager* mInputManager;
174  SubWidgetManager* mSubWidgetManager;
175  LayerManager* mLayerManager;
176  SkinManager* mSkinManager;
177  WidgetManager* mWidgetManager;
178  FontManager* mFontManager;
179  ControllerManager* mControllerManager;
180  PointerManager* mPointerManager;
181  ClipboardManager* mClipboardManager;
182  LayoutManager* mLayoutManager;
183  DynLibManager* mDynLibManager;
184  PluginManager* mPluginManager;
185  LanguageManager* mLanguageManager;
186  ResourceManager* mResourceManager;
187  FactoryManager* mFactoryManager;
188  ToolTipManager* mToolTipManager;
189 
190  bool mIsInitialise;
191  };
192 
193 } // namespace MyGUI
194 
195 #endif // __MYGUI_GUI_H__