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"
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"
21#include "MyGUI_LayoutManager.h"
22#include "MyGUI_PluginManager.h"
23#include "MyGUI_DynLibManager.h"
26#include "MyGUI_RenderManager.h"
30
31namespace MyGUI
32{
33
35
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
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
86
87 // загружаем дефолтные настройки если надо
88 if (!_core.empty())
89 mResourceManager->load(_core);
90
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
105 {
106 MYGUI_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised");
107 MYGUI_LOG(Info, "* Shutdown: " << getClassTypeName());
108
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
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 {
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())
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 // непосредственное удаление
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 // и сами удалим, так как его больше в списке нет
230 }
231 }
232
234 {
235 Widget* parent = _widget->getParent();
236 if (parent != nullptr)
237 parent->_destroyChildWidget(_widget);
238 else
239 _destroyChildWidget(_widget);
240 }
241
243 {
244 for (auto* widget : _widgets)
245 destroyWidget(widget);
246 }
247
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
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
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
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
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
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 {
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
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 {
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
355 {
356 _destroyChildWidget(_widget);
357 }
358
360 {
361 _destroyAllChildWidget();
362 }
363
365 {
366 return EnumeratorWidgetPtr(mWidgetChild);
367 }
368
369 void Gui::frameEvent(float _time) const
370 {
371 eventFrameStart(_time);
372 }
373
374} // namespace MyGUI
#define MYGUI_ASSERT(exp, dest)
#define MYGUI_EXCEPT(dest)
#define MYGUI_LOG(level, text)
#define MYGUI_VERSION_PATCH
#define MYGUI_VERSION_MAJOR
#define MYGUI_VERSION_MINOR
#define MYGUI_SINGLETON_DEFINITION(ClassName)
Manager of dynamic libraries.
T::const_reference current()
void _unlinkChildWidget(Widget *_widget)
void destroyWidget(Widget *_widget)
void shutdown()
Widget * createWidgetRealT(std::string_view _type, std::string_view _skin, const FloatCoord &_coord, Align _align, std::string_view _layer, std::string_view _name={})
static std::string_view getClassTypeName()
Definition MyGUI_Gui.cpp:34
void frameEvent(float _time) const
void initialise(const std::string &_core="MyGUI_Core.xml")
Definition MyGUI_Gui.cpp:41
void destroyAllChildWidget()
void destroyWidgets(const VectorWidgetPtr &_widgets)
void _linkChildWidget(Widget *_widget)
friend class WidgetManager
Definition MyGUI_Gui.h:26
Widget * findWidgetT(std::string_view _name, bool _throw=true) const
Gui(const Gui &)=delete
Widget * createWidgetT(std::string_view _type, std::string_view _skin, const IntCoord &_coord, Align _align, std::string_view _layer, std::string_view _name={})
void destroyChildWidget(Widget *_widget)
EventHandle_FrameEventDelegate eventFrameStart
Definition MyGUI_Gui.h:215
EnumeratorWidgetPtr getEnumerator() const
static LayerManager & getInstance()
void attachToLayerNode(std::string_view _name, Widget *_item)
Plugin manager. Load/unload and register plugins.
virtual const IntSize & getViewSize() const =0
static RenderManager & getInstance()
widget description should be here.
Widget * getParent() const
void _destroyChildWidget(Widget *_widget)
const std::string & getName() const
Get name of widget.
Widget * findWidget(std::string_view _name)
virtual void setAlign(Align _value)
void unregisterUnlinker(IUnlinkWidget *_unlink)
Widget * createWidget(WidgetStyle _style, std::string_view _type, std::string_view _skin, const IntCoord &_coord, Widget *_parent, ICroppedRectangle *_cropeedParent, std::string_view _name)
static WidgetManager & getInstance()
void _deleteWidget(Widget *_widget)
void unlinkFromUnlinkers(Widget *_widget)
void registerUnlinker(IUnlinkWidget *_unlink)
const IntSize & getTextureSize(const std::string &_texture, bool _cache=true)
types::TCoord< float > FloatCoord
Definition MyGUI_Types.h:37
Enumerator< VectorWidgetPtr > EnumeratorWidgetPtr
types::TCoord< int > IntCoord
Definition MyGUI_Types.h:36
types::TSize< int > IntSize
Definition MyGUI_Types.h:30
std::vector< Widget * > VectorWidgetPtr