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