MyGUI  3.2.0
MyGUI_Gui.cpp
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 #include "MyGUI_Precompiled.h"
23 #include "MyGUI_Gui.h"
24 #include "MyGUI_Widget.h"
25 
26 #include "MyGUI_InputManager.h"
27 #include "MyGUI_SubWidgetManager.h"
28 #include "MyGUI_LogManager.h"
29 #include "MyGUI_SkinManager.h"
30 #include "MyGUI_WidgetManager.h"
31 #include "MyGUI_LayerManager.h"
32 #include "MyGUI_FontManager.h"
34 #include "MyGUI_PointerManager.h"
35 #include "MyGUI_ClipboardManager.h"
36 #include "MyGUI_LayoutManager.h"
37 #include "MyGUI_PluginManager.h"
38 #include "MyGUI_DynLibManager.h"
39 #include "MyGUI_LanguageManager.h"
40 #include "MyGUI_ResourceManager.h"
41 #include "MyGUI_RenderManager.h"
42 #include "MyGUI_FactoryManager.h"
43 #include "MyGUI_ToolTipManager.h"
44 
45 namespace MyGUI
46 {
47 
48  template <> Gui* Singleton<Gui>::msInstance = nullptr;
49  template <> const char* Singleton<Gui>::mClassTypeName("Gui");
50 
52  mInputManager(nullptr),
53  mSubWidgetManager(nullptr),
54  mLayerManager(nullptr),
55  mSkinManager(nullptr),
56  mWidgetManager(nullptr),
57  mFontManager(nullptr),
58  mControllerManager(nullptr),
59  mPointerManager(nullptr),
60  mClipboardManager(nullptr),
61  mLayoutManager(nullptr),
62  mDynLibManager(nullptr),
63  mPluginManager(nullptr),
64  mLanguageManager(nullptr),
65  mResourceManager(nullptr),
66  mFactoryManager(nullptr),
67  mToolTipManager(nullptr),
68  mIsInitialise(false)
69  {
70  }
71 
72  void Gui::initialise(const std::string& _core)
73  {
74  MYGUI_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice");
75  MYGUI_LOG(Info, "* Initialise: " << getClassTypeName());
76 
77 #ifdef MYGUI_SVN_REVISION
78  MYGUI_LOG(Info, "* MyGUI version "
79  << MYGUI_VERSION_MAJOR << "."
80  << MYGUI_VERSION_MINOR << "."
81  << MYGUI_VERSION_PATCH << "."
82  << MYGUI_SVN_REVISION);
83 #else
84  MYGUI_LOG(Info, "* MyGUI version "
85  << MYGUI_VERSION_MAJOR << "."
86  << MYGUI_VERSION_MINOR << "."
88 #endif
89 
90  // создаем и инициализируем синглтоны
91  mResourceManager = new ResourceManager();
92  mLayerManager = new LayerManager();
93  mWidgetManager = new WidgetManager();
94  mInputManager = new InputManager();
95  mSubWidgetManager = new SubWidgetManager();
96  mSkinManager = new SkinManager();
97  mFontManager = new FontManager();
98  mControllerManager = new ControllerManager();
99  mPointerManager = new PointerManager();
100  mClipboardManager = new ClipboardManager();
101  mLayoutManager = new LayoutManager();
102  mDynLibManager = new DynLibManager();
103  mPluginManager = new PluginManager();
104  mLanguageManager = new LanguageManager();
105  mFactoryManager = new FactoryManager();
106  mToolTipManager = new ToolTipManager();
107 
108  mResourceManager->initialise();
109  mLayerManager->initialise();
110  mWidgetManager->initialise();
111  mInputManager->initialise();
112  mSubWidgetManager->initialise();
113  mSkinManager->initialise();
114  mFontManager->initialise();
115  mControllerManager->initialise();
116  mPointerManager->initialise();
117  mClipboardManager->initialise();
118  mLayoutManager->initialise();
119  mDynLibManager->initialise();
120  mPluginManager->initialise();
121  mLanguageManager->initialise();
122  mFactoryManager->initialise();
123  mToolTipManager->initialise();
124 
126 
127  // загружаем дефолтные настройки если надо
128  if (!_core.empty())
129  mResourceManager->load(_core);
130 
132 
133  MYGUI_LOG(Info, getClassTypeName() << " successfully initialized");
134  mIsInitialise = true;
135  }
136 
137 #ifndef MYGUI_DONT_USE_OBSOLETE
138  void Gui::initialise(const std::string& _core, const std::string& _logFileName)
139  {
140  initialise(_core);
141  }
142 #endif // MYGUI_DONT_USE_OBSOLETE
143 
145  {
146  MYGUI_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised");
147  MYGUI_LOG(Info, "* Shutdown: " << getClassTypeName());
148 
150 
151  _destroyAllChildWidget();
152 
153  // деинициализируем и удаляем синглтоны
154  mPointerManager->shutdown();
155  mInputManager->shutdown();
156  mSkinManager->shutdown();
157  mSubWidgetManager->shutdown();
158  mLayerManager->shutdown();
159  mFontManager->shutdown();
160  mControllerManager->shutdown();
161  mClipboardManager->shutdown();
162  mLayoutManager->shutdown();
163  mPluginManager->shutdown();
164  mDynLibManager->shutdown();
165  mLanguageManager->shutdown();
166  mResourceManager->shutdown();
167  mFactoryManager->shutdown();
168  mToolTipManager->shutdown();
169 
171  mWidgetManager->shutdown();
172 
173  delete mPointerManager;
174  delete mWidgetManager;
175  delete mInputManager;
176  delete mSkinManager;
177  delete mSubWidgetManager;
178  delete mLayerManager;
179  delete mFontManager;
180  delete mControllerManager;
181  delete mClipboardManager;
182  delete mLayoutManager;
183  delete mDynLibManager;
184  delete mPluginManager;
185  delete mLanguageManager;
186  delete mResourceManager;
187  delete mFactoryManager;
188  delete mToolTipManager;
189 
190  MYGUI_LOG(Info, getClassTypeName() << " successfully shutdown");
191  mIsInitialise = false;
192  }
193 
194  Widget* Gui::baseCreateWidget(WidgetStyle _style, const std::string& _type, const std::string& _skin, const IntCoord& _coord, Align _align, const std::string& _layer, const std::string& _name)
195  {
196  Widget* widget = WidgetManager::getInstance().createWidget(_style, _type, _skin, _coord, /*_align, */nullptr, nullptr, _name);
197  mWidgetChild.push_back(widget);
198 
199  widget->setAlign(_align);
200 
201  // присоединяем виджет с уровню
202  if (!_layer.empty())
204  return widget;
205  }
206 
207  Widget* Gui::findWidgetT(const std::string& _name, bool _throw)
208  {
209  for (VectorWidgetPtr::iterator iter = mWidgetChild.begin(); iter != mWidgetChild.end(); ++iter)
210  {
211  Widget* widget = (*iter)->findWidget(_name);
212  if (widget != nullptr) return widget;
213  }
214  MYGUI_ASSERT(!_throw, "Widget '" << _name << "' not found");
215  return nullptr;
216  }
217 
218  // удяляет неудачника
219  void Gui::_destroyChildWidget(Widget* _widget)
220  {
221  MYGUI_ASSERT(nullptr != _widget, "invalid widget pointer");
222 
223  VectorWidgetPtr::iterator iter = std::find(mWidgetChild.begin(), mWidgetChild.end(), _widget);
224  if (iter != mWidgetChild.end())
225  {
226  // сохраняем указатель
227  MyGUI::Widget* widget = *iter;
228 
229  // удаляем из списка
230  mWidgetChild.erase(iter);
231 
232  // отписываем от всех
233  mWidgetManager->unlinkFromUnlinkers(_widget);
234 
235  // непосредственное удаление
237  }
238  else
239  {
240  MYGUI_EXCEPT("Widget '" << _widget->getName() << "' not found");
241  }
242  }
243 
244  // удаляет всех детей
245  void Gui::_destroyAllChildWidget()
246  {
247  while (!mWidgetChild.empty())
248  {
249  // сразу себя отписывем, иначе вложенной удаление убивает все
250  Widget* widget = mWidgetChild.back();
251  mWidgetChild.pop_back();
252 
253  // отписываем от всех
254  mWidgetManager->unlinkFromUnlinkers(widget);
255 
256  // и сами удалим, так как его больше в списке нет
258  }
259  }
260 
261  void Gui::destroyWidget(Widget* _widget)
262  {
263  Widget* parent = _widget->getParent();
264  if (parent != nullptr)
265  parent->_destroyChildWidget(_widget);
266  else
267  _destroyChildWidget(_widget);
268  }
269 
270  void Gui::destroyWidgets(const VectorWidgetPtr& _widgets)
271  {
272  for (VectorWidgetPtr::const_iterator iter = _widgets.begin(); iter != _widgets.end(); ++iter)
273  destroyWidget(*iter);
274  }
275 
277  {
278  VectorWidgetPtr widgets;
279  while (_widgets.next())
280  widgets.push_back(_widgets.current());
281  destroyWidgets(widgets);
282  }
283 
284  void Gui::_unlinkWidget(Widget* _widget)
285  {
286  eventFrameStart.clear(_widget);
287  }
288 
290  {
291  VectorWidgetPtr::iterator iter = std::find(mWidgetChild.begin(), mWidgetChild.end(), _widget);
292  MYGUI_ASSERT(iter == mWidgetChild.end(), "widget already exist");
293  mWidgetChild.push_back(_widget);
294  }
295 
297  {
298  VectorWidgetPtr::iterator iter = std::remove(mWidgetChild.begin(), mWidgetChild.end(), _widget);
299  MYGUI_ASSERT(iter != mWidgetChild.end(), "widget not found");
300  mWidgetChild.erase(iter);
301  }
302 
303  Widget* Gui::createWidgetT(const std::string& _type, const std::string& _skin, const IntCoord& _coord, Align _align, const std::string& _layer, const std::string& _name)
304  {
305  return baseCreateWidget(WidgetStyle::Overlapped, _type, _skin, _coord, _align, _layer, _name);
306  }
308  Widget* Gui::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)
309  {
310  return createWidgetT(_type, _skin, IntCoord(_left, _top, _width, _height), _align, _layer, _name);
311  }
313  Widget* Gui::createWidgetRealT(const std::string& _type, const std::string& _skin, const FloatCoord& _coord, Align _align, const std::string& _layer, const std::string& _name)
314  {
316  return createWidgetT(_type, _skin, IntCoord((int)(_coord.left * size.width), (int)(_coord.top * size.height), (int)(_coord.width * size.width), (int)(_coord.height * size.height)), _align, _layer, _name);
317  }
319  Widget* Gui::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)
320  {
322  return createWidgetT(_type, _skin, IntCoord((int)(_left * size.width), (int)(_top * size.height), (int)(_width * size.width), (int)(_height * size.height)), _align, _layer, _name);
323  }
324 
325  Widget* Gui::findWidgetT(const std::string& _name, const std::string& _prefix, bool _throw)
326  {
327  return findWidgetT(_prefix + _name, _throw);
328  }
329 
331  {
332  _destroyChildWidget(_widget);
333  }
334 
336  {
337  _destroyAllChildWidget();
338  }
339 
341  {
342  return EnumeratorWidgetPtr(mWidgetChild);
343  }
344 
345  void Gui::frameEvent(float _time)
346  {
347  eventFrameStart(_time);
348  }
349 
350 } // namespace MyGUI
void destroyWidget(Widget *_widget)
Definition: MyGUI_Gui.cpp:261
EventHandle_FrameEventDelegate eventFrameStart
Definition: MyGUI_Gui.h:166
void shutdown()
Definition: MyGUI_Gui.cpp:144
static WidgetManager & getInstance()
void _unlinkChildWidget(Widget *_widget)
Definition: MyGUI_Gui.cpp:296
Widget * createWidgetRealT(const std::string &_type, const std::string &_skin, const FloatCoord &_coord, Align _align, const std::string &_layer, const std::string &_name="")
Definition: MyGUI_Gui.cpp:313
void _destroyChildWidget(Widget *_widget)
Widget * findWidgetT(const std::string &_name, bool _throw=true)
Definition: MyGUI_Gui.cpp:207
static const char * getClassTypeName()
void frameEvent(float _time)
Definition: MyGUI_Gui.cpp:345
#define MYGUI_VERSION_PATCH
#define nullptr
virtual const IntSize & getViewSize() const =0
void unlinkFromUnlinkers(Widget *_widget)
types::TCoord< int > IntCoord
Definition: MyGUI_Types.h:50
Plugin manager. Load/unload and register plugins.
#define MYGUI_VERSION_MAJOR
#define MYGUI_LOG(level, text)
Manager of dynamic libraries.
Widget * findWidget(const std::string &_name)
#define MYGUI_EXCEPT(dest)
void destroyWidgets(const VectorWidgetPtr &_widgets)
Definition: MyGUI_Gui.cpp:270
void destroyAllChildWidget()
Definition: MyGUI_Gui.cpp:335
bool load(const std::string &_file)
#define MYGUI_VERSION_MINOR
EnumeratorWidgetPtr getEnumerator() const
Definition: MyGUI_Gui.cpp:340
std::vector< Widget * > VectorWidgetPtr
#define MYGUI_ASSERT(exp, dest)
void attachToLayerNode(const std::string &_name, Widget *_item)
const std::string & getName() const
Get name of widget.
void _deleteWidget(Widget *_widget)
Enumerator< VectorWidgetPtr > EnumeratorWidgetPtr
void registerUnlinker(IUnlinkWidget *_unlink)
Widget * createWidget(WidgetStyle _style, const std::string &_type, const std::string &_skin, const IntCoord &_coord, Widget *_parent, ICroppedRectangle *_cropeedParent, const std::string &_name)
virtual void setAlign(Align _value)
Widget * getParent() const
void destroyChildWidget(Widget *_widget)
Definition: MyGUI_Gui.cpp:330
Widget * createWidgetT(const std::string &_type, const std::string &_skin, const IntCoord &_coord, Align _align, const std::string &_layer, const std::string &_name="")
Definition: MyGUI_Gui.cpp:303
static const char * mClassTypeName
friend class WidgetManager
Definition: MyGUI_Gui.h:43
T::const_reference current()
void unregisterUnlinker(IUnlinkWidget *_unlink)
void initialise(const std::string &_core="MyGUI_Core.xml")
Definition: MyGUI_Gui.cpp:72
void _linkChildWidget(Widget *_widget)
Definition: MyGUI_Gui.cpp:289