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