MyGUI 3.5.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"
24#include "MyGUI_RenderManager.h"
29
30namespace MyGUI
31{
32
34
35 Gui::Gui() :
36 mSingletonHolder(this)
37 {
38 }
39
40 void Gui::initialise(const std::string& _core)
41 {
42 MYGUI_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice");
43 MYGUI_LOG(Info, "* Initialise: " << getClassTypeName());
44
46 Info,
47 "* MyGUI version " << MYGUI_VERSION_MAJOR << "." << MYGUI_VERSION_MINOR << "." << MYGUI_VERSION_PATCH);
48
49 mResourceManager = new ResourceManager();
50 mLayerManager = new LayerManager();
51 mWidgetManager = new WidgetManager();
52 mInputManager = new InputManager();
53 mSubWidgetManager = new SubWidgetManager();
54 mSkinManager = new SkinManager();
55 mFontManager = new FontManager();
56 mControllerManager = new ControllerManager();
57 mPointerManager = new PointerManager();
58 mClipboardManager = new ClipboardManager();
59 mLayoutManager = new LayoutManager();
60 mLanguageManager = new LanguageManager();
61 mFactoryManager = new FactoryManager();
62 mToolTipManager = new ToolTipManager();
63
64 mResourceManager->initialise();
65 mLayerManager->initialise();
66 mWidgetManager->initialise();
67 mInputManager->initialise();
68 mSubWidgetManager->initialise();
69 mSkinManager->initialise();
70 mFontManager->initialise();
71 mControllerManager->initialise();
72 mPointerManager->initialise();
73 mClipboardManager->initialise();
74 mLayoutManager->initialise();
75 mLanguageManager->initialise();
76 mFactoryManager->initialise();
77 mToolTipManager->initialise();
78
79 WidgetManager::getInstance().registerUnlinker(this);
80
81 // load default settings if needed
82 if (!_core.empty())
83 mResourceManager->load(_core);
84
85 BackwardCompatibility::initialise();
86
87 MYGUI_LOG(Info, getClassTypeName() << " successfully initialized");
88 mIsInitialise = true;
89 }
90
91 void Gui::shutdown()
92 {
93 MYGUI_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised");
94 MYGUI_LOG(Info, "* Shutdown: " << getClassTypeName());
95
96 BackwardCompatibility::shutdown();
97
98 _destroyAllChildWidget();
99
100 mPointerManager->shutdown();
101 mInputManager->shutdown();
102 mSkinManager->shutdown();
103 mSubWidgetManager->shutdown();
104 mLayerManager->shutdown();
105 mFontManager->shutdown();
106 mControllerManager->shutdown();
107 mClipboardManager->shutdown();
108 mLayoutManager->shutdown();
109 mLanguageManager->shutdown();
110 mResourceManager->shutdown();
111 mFactoryManager->shutdown();
112 mToolTipManager->shutdown();
113
114 WidgetManager::getInstance().unregisterUnlinker(this);
115 mWidgetManager->shutdown();
116
117 delete mPointerManager;
118 delete mWidgetManager;
119 delete mInputManager;
120 delete mSkinManager;
121 delete mSubWidgetManager;
122 delete mLayerManager;
123 delete mFontManager;
124 delete mControllerManager;
125 delete mClipboardManager;
126 delete mLayoutManager;
127 delete mLanguageManager;
128 delete mResourceManager;
129 delete mFactoryManager;
130 delete mToolTipManager;
131
132 MYGUI_LOG(Info, getClassTypeName() << " successfully shutdown");
133 mIsInitialise = false;
134 }
135
136 Widget* Gui::findWidgetT(std::string_view _name, bool _throw) const
137 {
138 for (const auto& iter : getChildWidgets())
139 {
140 Widget* widget = iter->findWidget(_name);
141 if (widget != nullptr)
142 return widget;
143 }
144 MYGUI_ASSERT(!_throw, "Widget '" << _name << "' not found");
145 return nullptr;
146 }
147
148 void Gui::destroyWidget(Widget* _widget)
149 {
150 Widget* parent = _widget->getParent();
151 if (parent != nullptr)
152 parent->_destroyChildWidget(_widget);
153 else
154 _destroyChildWidget(_widget);
155 }
156
157 void Gui::destroyWidgets(const VectorWidgetPtr& _widgets)
158 {
159 // create copy to avoid UB when _widgets is mWidgetChild
160 VectorWidgetPtr copy{_widgets};
161 for (auto* widget : copy)
162 destroyWidget(widget);
163 }
164
165 void Gui::_unlinkWidget(Widget* _widget)
166 {
167 eventFrameStart.clear(_widget);
168 }
169
170 Widget* Gui::createWidgetT(
171 std::string_view _type,
172 std::string_view _skin,
173 const IntCoord& _coord,
174 Align _align,
175 std::string_view _layer,
176 std::string_view _name)
177 {
178 return baseCreateWidget(WidgetStyle::Overlapped, _type, _skin, _coord, _align, _layer, _name);
179 }
181 Widget* Gui::createWidgetT(
182 std::string_view _type,
183 std::string_view _skin,
184 int _left,
185 int _top,
186 int _width,
187 int _height,
188 Align _align,
189 std::string_view _layer,
190 std::string_view _name)
191 {
192 return createWidgetT(_type, _skin, IntCoord(_left, _top, _width, _height), _align, _layer, _name);
193 }
195 Widget* Gui::createWidgetRealT(
196 std::string_view _type,
197 std::string_view _skin,
198 const FloatCoord& _coord,
199 Align _align,
200 std::string_view _layer,
201 std::string_view _name)
202 {
203 IntSize size = RenderManager::getInstance().getViewSize();
204 return createWidgetT(_type, _skin, CoordConverter::convertFromRelative(_coord, size), _align, _layer, _name);
205 }
207 Widget* Gui::createWidgetRealT(
208 std::string_view _type,
209 std::string_view _skin,
210 float _left,
211 float _top,
212 float _width,
213 float _height,
214 Align _align,
215 std::string_view _layer,
216 std::string_view _name)
217 {
218 return createWidgetRealT(_type, _skin, FloatCoord(_left, _top, _width, _height), _align, _layer, _name);
219 }
220
221 void Gui::destroyChildWidget(Widget* _widget)
222 {
223 _destroyChildWidget(_widget);
224 }
225
226 void Gui::destroyAllChildWidget()
227 {
228 _destroyAllChildWidget();
229 }
230
231 const VectorWidgetPtr& Gui::getRootWidgets() const
232 {
233 return getChildWidgets();
234 }
235
236 void Gui::frameEvent(float _time) const
237 {
238 eventFrameStart(_time);
239 }
240
241 void Gui::setDpiScale(float _value)
242 {
243 mDpiScale = _value;
244 }
245
246 float Gui::getDpiScale() const
247 {
248 return mDpiScale;
249 }
250
251} // namespace MyGUI
#define MYGUI_ASSERT(exp, dest)
#define MYGUI_LOG(level, text)
#define MYGUI_VERSION_PATCH
#define MYGUI_VERSION_MAJOR
#define MYGUI_VERSION_MINOR
types::TCoord< float > FloatCoord
Definition MyGUI_Types.h:36
types::TCoord< int > IntCoord
Definition MyGUI_Types.h:35
types::TSize< int > IntSize
Definition MyGUI_Types.h:29
std::vector< Widget * > VectorWidgetPtr
MYGUI_SINGLETON_DEFINITION(ClipboardManager)