MyGUI: MyGUI_Gui.cpp Source File

MyGUI 3.4.3

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