MyGUI  3.0.1
MyGUI_Gui.h
Go to the documentation of this file.
1 
7 /*
8  This file is part of MyGUI.
9 
10  MyGUI is free software: you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  MyGUI is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
22 */
23 #ifndef __MYGUI_GUI_H__
24 #define __MYGUI_GUI_H__
25 
26 #include "MyGUI_Prerequest.h"
27 #include "MyGUI_Types.h"
28 #include "MyGUI_Instance.h"
29 #include "MyGUI_XmlDocument.h"
30 #include "MyGUI_IWidgetCreator.h"
31 #include "MyGUI_IUnlinkWidget.h"
32 #include "MyGUI_Widget.h"
33 
34 namespace MyGUI
35 {
36 
38 
40  {
41  friend class WidgetManager;
43 
44  public:
51  void initialise(const std::string& _core = "core.xml", const std::string& _logFileName = MYGUI_LOG_FILENAME);
52 
54  void shutdown();
55 
56  // methods for creating widgets
66  Widget* createWidgetT(const std::string& _type, const std::string& _skin, const IntCoord& _coord, Align _align, const std::string& _layer, const std::string& _name = "")
67  {
68  return baseCreateWidget(WidgetStyle::Overlapped, _type, _skin, _coord, _align, _layer, _name);
69  }
71  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 = "")
72  {
73  return createWidgetT(_type, _skin, IntCoord(_left, _top, _width, _height), _align, _layer, _name);
74  }
76  Widget* createWidgetRealT(const std::string& _type, const std::string& _skin, const FloatCoord& _coord, Align _align, const std::string& _layer, const std::string& _name = "")
77  {
78  return createWidgetT(_type, _skin, IntCoord((int)(_coord.left*mViewSize.width), (int)(_coord.top*mViewSize.height), (int)(_coord.width*mViewSize.width), (int)(_coord.height*mViewSize.height)), _align, _layer, _name);
79  }
81  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 = "")
82  {
83  return createWidgetT(_type, _skin, IntCoord((int)(_left*mViewSize.width), (int)(_top*mViewSize.height), (int)(_width*mViewSize.width), (int)(_height*mViewSize.height)), _align, _layer, _name);
84  }
85 
86  // templates for creating widgets by type
88  template <typename T>
89  T* createWidget(const std::string& _skin, const IntCoord& _coord, Align _align, const std::string& _layer, const std::string& _name = "")
90  {
91  return static_cast<T*>(createWidgetT(T::getClassTypeName(), _skin, _coord, _align, _layer, _name));
92  }
94  template <typename T>
95  T* createWidget(const std::string& _skin, int _left, int _top, int _width, int _height, Align _align, const std::string& _layer, const std::string& _name = "")
96  {
97  return static_cast<T*>(createWidgetT(T::getClassTypeName(), _skin, IntCoord(_left, _top, _width, _height), _align, _layer, _name));
98  }
100  template <typename T>
101  T* createWidgetReal(const std::string& _skin, const FloatCoord& _coord, Align _align, const std::string& _layer, const std::string& _name = "")
102  {
103  return static_cast<T*>(createWidgetRealT(T::getClassTypeName(), _skin, _coord, _align, _layer, _name));
104  }
106  template <typename T>
107  T* createWidgetReal(const std::string& _skin, float _left, float _top, float _width, float _height, Align _align, const std::string& _layer, const std::string& _name = "")
108  {
109  return static_cast<T*>(createWidgetRealT(T::getClassTypeName(), _skin, _left, _top, _width, _height, _align, _layer, _name));
110  }
111 
113  const IntSize& getViewSize() const { return mViewSize; }
114 
115  int getViewWidth() { return mViewSize.width; }
116  int getViewHeight() { return mViewSize.height; }
117 
118  // mirror of InputManager methods
122  bool injectMouseMove(int _absx, int _absy, int _absz);
126  bool injectMousePress(int _absx, int _absy, MouseButton _id);
130  bool injectMouseRelease(int _absx, int _absy, MouseButton _id);
131 
135  bool injectKeyPress(KeyCode _key, Char _text = 0);
139  bool injectKeyRelease(KeyCode _key);
140 
142  void destroyWidget(Widget* _widget);
143 
145  void destroyWidgets(VectorWidgetPtr& _widgets);
146 
148  void destroyWidgets(EnumeratorWidgetPtr& _widgets);
149 
153  Widget* findWidgetT(const std::string& _name, bool _throw = true);
154 
158  Widget* findWidgetT(const std::string& _name, const std::string& _prefix, bool _throw = true)
159  {
160  return findWidgetT(_prefix + _name, _throw);
161  }
162 
163  // mirror WidgetManager
167  template <typename T>
168  T* findWidget(const std::string& _name, bool _throw = true)
169  {
170  Widget* widget = findWidgetT(_name, _throw);
171  if (nullptr == widget) return nullptr;
172  return widget->castType<T>(_throw);
173  }
174 
178  template <typename T>
179  T* findWidget(const std::string& _name, const std::string& _prefix, bool _throw = true)
180  {
181  return findWidget<T>(_prefix + _name, _throw);
182  }
183 
184 
186  void setVisiblePointer(bool _visible);
188  bool isVisiblePointer();
189 
190 
191  // mirror ResourceManager
193  bool load(const std::string& _file);
194 
195  void resizeWindow(const IntSize& _size);
196 
198  void destroyChildWidget(Widget* _widget) { _destroyChildWidget(_widget); }
199 
201  void destroyAllChildWidget() { _destroyAllChildWidget(); }
202 
204  //static const std::string& getResourceGroup();
205 
208 
209  /*internal:*/
210 
214  void _injectFrameEntered(float _time);
215 
216  /*event:*/
222 
223  /*obsolete:*/
224 #ifndef MYGUI_DONT_USE_OBSOLETE
225 
226  MYGUI_OBSOLETE("use : void Gui::destroyWidgets(VectorWidgetPtr &_widgets)")
227  void destroyWidgetsVector(VectorWidgetPtr& _widgets) { destroyWidgets(_widgets); }
228 
229  MYGUI_OBSOLETE("use : void Gui::setVisiblePointer(bool _value)")
230  void hidePointer() { setVisiblePointer(false); }
231  MYGUI_OBSOLETE("use : void Gui::setVisiblePointer(bool _value)")
232  void showPointer() { setVisiblePointer(true); }
233  MYGUI_OBSOLETE("use : bool Gui::isVisiblePointer()")
234  bool isShowPointer() { return isVisiblePointer(); }
235  MYGUI_OBSOLETE("called be renderer, do not call it manually")
236  void injectFrameEntered(float _time) { }
237 
238 #endif // MYGUI_DONT_USE_OBSOLETE
239 
240  private:
241  // создает виджет
242  virtual 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);
243 
244  // удяляет неудачника
245  void _destroyChildWidget(Widget* _widget);
246 
247  // удаляет всех детей
248  void _destroyAllChildWidget();
249 
250  virtual void _unlinkWidget(Widget* _widget);
251 
252  // добавляет в список виджет
253  virtual void _linkChildWidget(Widget* _widget);
254 
255  // удаляет из списка
256  virtual void _unlinkChildWidget(Widget* _widget);
257 
258 
259  private:
260  // вектор всех детей виджетов
261  VectorWidgetPtr mWidgetChild;
262 
263  // размеры экрана
264  IntSize mViewSize;
265 
266  // синглтоны гуя
267  InputManager * mInputManager;
268  SubWidgetManager * mSubWidgetManager;
269  LayerManager* mLayerManager;
270  SkinManager* mSkinManager;
271  WidgetManager* mWidgetManager;
272  FontManager* mFontManager;
273  ControllerManager* mControllerManager;
274  PointerManager* mPointerManager;
275  ClipboardManager* mClipboardManager;
276  LayoutManager* mLayoutManager;
277  DynLibManager* mDynLibManager;
278  PluginManager* mPluginManager;
279  LanguageManager* mLanguageManager;
280  ResourceManager* mResourceManager;
281  FactoryManager* mFactoryManager;
282 
283  };
284 
285 } // namespace MyGUI
286 
287 #endif // __MYGUI_GUI_H__