MyGUI 3.4.3
MyGUI_WidgetManager.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"
9#include "MyGUI_Gui.h"
10#include "MyGUI_Widget.h"
12
13#include "MyGUI_Button.h"
14#include "MyGUI_Canvas.h"
15#include "MyGUI_ComboBox.h"
16#include "MyGUI_DDContainer.h"
17#include "MyGUI_EditBox.h"
18#include "MyGUI_ItemBox.h"
19#include "MyGUI_ListBox.h"
20#include "MyGUI_MenuBar.h"
21#include "MyGUI_MenuControl.h"
22#include "MyGUI_MenuItem.h"
23#include "MyGUI_MultiListBox.h"
24#include "MyGUI_MultiListItem.h"
25#include "MyGUI_PopupMenu.h"
26#include "MyGUI_ProgressBar.h"
27#include "MyGUI_ScrollBar.h"
28#include "MyGUI_ScrollView.h"
29#include "MyGUI_ImageBox.h"
30#include "MyGUI_TextBox.h"
31#include "MyGUI_TabControl.h"
32#include "MyGUI_TabItem.h"
33#include "MyGUI_Window.h"
34
36
37namespace MyGUI
38{
39
41
43 mCategoryName("Widget"),
44 mSingletonHolder(this)
45 {
46 }
47
49 {
50 MYGUI_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice");
51 MYGUI_LOG(Info, "* Initialise: " << getClassTypeName());
52
54
55 factory.registerFactory<Button>(mCategoryName);
56 factory.registerFactory<Canvas>(mCategoryName);
57 factory.registerFactory<ComboBox>(mCategoryName);
58 factory.registerFactory<DDContainer>(mCategoryName);
59 factory.registerFactory<EditBox>(mCategoryName);
60 factory.registerFactory<ItemBox>(mCategoryName);
61 factory.registerFactory<ListBox>(mCategoryName);
62 factory.registerFactory<MenuBar>(mCategoryName);
63 factory.registerFactory<MenuControl>(mCategoryName);
64 factory.registerFactory<MenuItem>(mCategoryName);
65 factory.registerFactory<MultiListBox>(mCategoryName);
66 factory.registerFactory<MultiListItem>(mCategoryName);
67 factory.registerFactory<PopupMenu>(mCategoryName);
68 factory.registerFactory<ProgressBar>(mCategoryName);
69 factory.registerFactory<ScrollBar>(mCategoryName);
70 factory.registerFactory<ScrollView>(mCategoryName);
71 factory.registerFactory<ImageBox>(mCategoryName);
72 factory.registerFactory<TextBox>(mCategoryName);
73 factory.registerFactory<TabControl>(mCategoryName);
74 factory.registerFactory<TabItem>(mCategoryName);
75 factory.registerFactory<Widget>(mCategoryName);
76 factory.registerFactory<Window>(mCategoryName);
77
79
80 Gui::getInstance().eventFrameStart += newDelegate(this, &WidgetManager::notifyEventFrameStart);
81
82 MYGUI_LOG(Info, getClassTypeName() << " successfully initialized");
83 mIsInitialise = true;
84 }
85
87 {
88 MYGUI_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised");
89 MYGUI_LOG(Info, "* Shutdown: " << getClassTypeName());
90
91 Gui::getInstance().eventFrameStart -= newDelegate(this, &WidgetManager::notifyEventFrameStart);
93
94 mVectorIUnlinkWidget.clear();
95
97
98 MYGUI_LOG(Info, getClassTypeName() << " successfully shutdown");
99 mIsInitialise = false;
100 }
101
103 WidgetStyle _style,
104 std::string_view _type,
105 std::string_view _skin,
106 const IntCoord& _coord,
107 Widget* _parent,
108 ICroppedRectangle* _cropeedParent,
109 std::string_view _name)
110 {
111 IObject* object = FactoryManager::getInstance().createObject(mCategoryName, _type);
112 if (object != nullptr)
113 {
114 Widget* widget = object->castType<Widget>();
115 widget->_initialise(_style, _coord, _skin, _parent, _cropeedParent, _name);
116
117 return widget;
118 }
119
120 MYGUI_EXCEPT("factory '" << _type << "' not found");
121 }
122
124 {
126 }
127
129 {
131 }
132
137
139 {
140 unregisterUnlinker(_unlink);
141 mVectorIUnlinkWidget.push_back(_unlink);
142 }
143
145 {
146 VectorIUnlinkWidget::iterator iter =
147 std::remove(mVectorIUnlinkWidget.begin(), mVectorIUnlinkWidget.end(), _unlink);
148 if (iter != mVectorIUnlinkWidget.end())
149 mVectorIUnlinkWidget.erase(iter);
150 }
151
153 {
154 for (auto& iter : mVectorIUnlinkWidget)
155 {
156 iter->_unlinkWidget(_widget);
157 }
158 }
159
160 bool WidgetManager::isFactoryExist(std::string_view _type)
161 {
162 return FactoryManager::getInstance().isFactoryExist(mCategoryName, _type);
163 }
164
165 void WidgetManager::notifyEventFrameStart(float _time)
166 {
168 }
169
171 {
172 _widget->_shutdown();
173
174 for (auto& widget : mDestroyWidgets)
175 {
176 /*if ((*entry) == _widget)
177 return;*/
178 MYGUI_ASSERT(widget != _widget, "double delete widget");
179 }
180
181 mDestroyWidgets.push_back(_widget);
182 }
183
185 {
186 if (!mDestroyWidgets.empty())
187 {
188 for (auto& widget : mDestroyWidgets)
189 delete widget;
190 mDestroyWidgets.clear();
191 }
192 }
193
194 const std::string& WidgetManager::getCategoryName() const
195 {
196 return mCategoryName;
197 }
198
199} // namespace MyGUI
#define MYGUI_ASSERT(exp, dest)
#define MYGUI_EXCEPT(dest)
#define MYGUI_LOG(level, text)
#define MYGUI_SINGLETON_DEFINITION(ClassName)
widget description should be here.
wrapper over Texture - shows the texture. Implemented: resizing of texture (see TextureResizeMode); r...
widget description should be here.
widget description should be here.
widget description should be here.
void registerFactory(std::string_view _category, std::string_view _type, Delegate::IDelegate *_delegate)
bool isFactoryExist(std::string_view _category, std::string_view _type)
static FactoryManager & getInstance()
void unregisterFactory(std::string_view _category, std::string_view _type)
IObject * createObject(std::string_view _category, std::string_view _type)
void destroyWidget(Widget *_widget)
void destroyWidgets(const VectorWidgetPtr &_widgets)
static Gui & getInstance()
Definition MyGUI_Gui.cpp:34
EventHandle_FrameEventDelegate eventFrameStart
Definition MyGUI_Gui.h:215
Type * castType(bool _throw=true)
widget description should be here.
widget description should be here.
widget description should be here.
widget description should be here.
widget description should be here.
widget description should be here.
widget description should be here.
widget description should be here.
widget description should be here.
widget description should be here.
widget description should be here.
widget description should be here.
widget description should be here.
widget description should be here.
widget description should be here.
widget description should be here.
void _initialise(WidgetStyle _style, const IntCoord &_coord, std::string_view _skinName, Widget *_parent, ICroppedRectangle *_croppedParent, std::string_view _name)
void unregisterUnlinker(IUnlinkWidget *_unlink)
const std::string & getCategoryName() const
Widget * createWidget(WidgetStyle _style, std::string_view _type, std::string_view _skin, const IntCoord &_coord, Widget *_parent, ICroppedRectangle *_cropeedParent, std::string_view _name)
static std::string_view getClassTypeName()
bool isFactoryExist(std::string_view _type)
void destroyWidgets(const VectorWidgetPtr &_widgets)
void _deleteWidget(Widget *_widget)
void unlinkFromUnlinkers(Widget *_widget)
void registerUnlinker(IUnlinkWidget *_unlink)
void destroyWidget(Widget *_widget)
widget description should be here.
delegates::DelegateFunction< Args... > * newDelegate(void(*_func)(Args... args))
std::vector< Widget * > VectorWidgetPtr