MyGUI: MyGUI_WidgetManager.cpp Source File

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"
8#include "MyGUI_WidgetManager.h"
9#include "MyGUI_Gui.h"
10#include "MyGUI_Widget.h"
11#include "MyGUI_FactoryManager.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
35#include "MyGUI_BackwardCompatibility.h"
36
37namespace MyGUI
38{
39
40 MYGUI_SINGLETON_DEFINITION(WidgetManager);
41
42 WidgetManager::WidgetManager() :
43 mCategoryName("Widget"),
44 mSingletonHolder(this)
45 {
46 }
47
48 void WidgetManager::initialise()
49 {
50 MYGUI_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice");
51 MYGUI_LOG(Info, "* Initialise: " << getClassTypeName());
52
53 FactoryManager& factory = FactoryManager::getInstance();
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
78 BackwardCompatibility::registerWidgetTypes();
79
80 Gui::getInstance().eventFrameStart += newDelegate(this, &WidgetManager::notifyEventFrameStart);
81
82 MYGUI_LOG(Info, getClassTypeName() << " successfully initialized");
83 mIsInitialise = true;
84 }
85
86 void WidgetManager::shutdown()
87 {
88 MYGUI_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised");
89 MYGUI_LOG(Info, "* Shutdown: " << getClassTypeName());
90
91 Gui::getInstance().eventFrameStart -= newDelegate(this, &WidgetManager::notifyEventFrameStart);
92 _deleteDelayWidgets();
93
94 mVectorIUnlinkWidget.clear();
95
96 FactoryManager::getInstance().unregisterFactory(mCategoryName);
97
98 MYGUI_LOG(Info, getClassTypeName() << " successfully shutdown");
99 mIsInitialise = false;
100 }
101
102 Widget* WidgetManager::createWidget(
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
123 void WidgetManager::destroyWidget(Widget* _widget)
124 {
125 Gui::getInstance().destroyWidget(_widget);
126 }
127
128 void WidgetManager::destroyWidgets(const VectorWidgetPtr& _widgets)
129 {
130 Gui::getInstance().destroyWidgets(_widgets);
131 }
132
133 void WidgetManager::destroyWidgets(EnumeratorWidgetPtr _widgets)
134 {
135 Gui::getInstance().destroyWidgets(_widgets);
136 }
137
138 void WidgetManager::registerUnlinker(IUnlinkWidget* _unlink)
139 {
140 unregisterUnlinker(_unlink);
141 mVectorIUnlinkWidget.push_back(_unlink);
142 }
143
144 void WidgetManager::unregisterUnlinker(IUnlinkWidget* _unlink)
145 {
146 VectorIUnlinkWidget::iterator iter =
147 std::remove(mVectorIUnlinkWidget.begin(), mVectorIUnlinkWidget.end(), _unlink);
148 if (iter != mVectorIUnlinkWidget.end())
149 mVectorIUnlinkWidget.erase(iter);
150 }
151
152 void WidgetManager::unlinkFromUnlinkers(Widget* _widget)
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 {
167 _deleteDelayWidgets();
168 }
169
170 void WidgetManager::_deleteWidget(Widget* _widget)
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
184 void WidgetManager::_deleteDelayWidgets()
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
MyGUI_BackwardCompatibility.h
MyGUI_Button.h
MyGUI_Canvas.h
MyGUI_ComboBox.h
MyGUI_DDContainer.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_EditBox.h
MyGUI_FactoryManager.h
MyGUI_Gui.h
MyGUI_ImageBox.h
MyGUI_ItemBox.h
MyGUI_ListBox.h
MyGUI_MultiListBox.h
MyGUI_MultiListItem.h
MyGUI_Precompiled.h
MyGUI_ProgressBar.h
MyGUI_ScrollBar.h
MyGUI_ScrollView.h
MYGUI_SINGLETON_DEFINITION
#define MYGUI_SINGLETON_DEFINITION(ClassName)
Definition MyGUI_Singleton.h:126
MyGUI_TabControl.h
MyGUI_TabItem.h
MyGUI_TextBox.h
MyGUI_Widget.h
MyGUI_WidgetManager.h
MyGUI_Window.h
MyGUI::BackwardCompatibility::registerWidgetTypes
static void registerWidgetTypes()
Definition MyGUI_BackwardCompatibility.cpp:1440
MyGUI::Button
widget description should be here.
Definition MyGUI_Button.h:20
MyGUI::Canvas
wrapper over Texture - shows the texture. Implemented: resizing of texture (see TextureResizeMode); r...
Definition MyGUI_Canvas.h:22
MyGUI::ComboBox
widget description should be here.
Definition MyGUI_ComboBox.h:29
MyGUI::DDContainer
widget description should be here.
Definition MyGUI_DDContainer.h:31
MyGUI::EditBox
widget description should be here.
Definition MyGUI_EditBox.h:26
MyGUI::FactoryManager
Definition MyGUI_FactoryManager.h:19
MyGUI::FactoryManager::registerFactory
void registerFactory(std::string_view _category, std::string_view _type, Delegate::IDelegate *_delegate)
Definition MyGUI_FactoryManager.cpp:39
MyGUI::FactoryManager::isFactoryExist
bool isFactoryExist(std::string_view _category, std::string_view _type)
Definition MyGUI_FactoryManager.cpp:126
MyGUI::FactoryManager::getInstance
static FactoryManager & getInstance()
MyGUI::FactoryManager::unregisterFactory
void unregisterFactory(std::string_view _category, std::string_view _type)
Definition MyGUI_FactoryManager.cpp:54
MyGUI::FactoryManager::createObject
IObject * createObject(std::string_view _category, std::string_view _type)
Definition MyGUI_FactoryManager.cpp:80
MyGUI::Gui::destroyWidget
void destroyWidget(Widget *_widget)
Definition MyGUI_Gui.cpp:233
MyGUI::Gui::destroyWidgets
void destroyWidgets(const VectorWidgetPtr &_widgets)
Definition MyGUI_Gui.cpp:242
MyGUI::Gui::getInstance
static Gui & getInstance()
Definition MyGUI_Gui.cpp:34
MyGUI::Gui::eventFrameStart
EventHandle_FrameEventDelegate eventFrameStart
Definition MyGUI_Gui.h:215
MyGUI::ICroppedRectangle
Definition MyGUI_ICroppedRectangle.h:17
MyGUI::IObject
Definition MyGUI_IObject.h:17
MyGUI::IObject::castType
Type * castType(bool _throw=true)
Definition MyGUI_IObject.h:18
MyGUI::IUnlinkWidget
Definition MyGUI_IUnlinkWidget.h:17
MyGUI::ImageBox
widget description should be here.
Definition MyGUI_ImageBox.h:22
MyGUI::ItemBox
widget description should be here.
Definition MyGUI_ItemBox.h:31
MyGUI::ListBox
widget description should be here.
Definition MyGUI_ListBox.h:28
MyGUI::MultiListBox
widget description should be here.
Definition MyGUI_MultiListBox.h:43
MyGUI::MultiListItem
widget description should be here.
Definition MyGUI_MultiListItem.h:22
MyGUI::ProgressBar
widget description should be here.
Definition MyGUI_ProgressBar.h:22
MyGUI::ScrollBar
widget description should be here.
Definition MyGUI_ScrollBar.h:24
MyGUI::ScrollView
widget description should be here.
Definition MyGUI_ScrollView.h:21
MyGUI::TabControl
widget description should be here.
Definition MyGUI_TabControl.h:27
MyGUI::TabItem
widget description should be here.
Definition MyGUI_TabItem.h:21
MyGUI::TextBox
widget description should be here.
Definition MyGUI_TextBox.h:20
MyGUI::Widget
widget description should be here.
Definition MyGUI_Widget.h:40
MyGUI::Widget::_shutdown
void _shutdown()
Definition MyGUI_Widget.cpp:112
MyGUI::Widget::_initialise
void _initialise(WidgetStyle _style, const IntCoord &_coord, std::string_view _skinName, Widget *_parent, ICroppedRectangle *_croppedParent, std::string_view _name)
Definition MyGUI_Widget.cpp:31
MyGUI::WidgetManager
Definition MyGUI_WidgetManager.h:21
MyGUI::WidgetManager::unregisterUnlinker
void unregisterUnlinker(IUnlinkWidget *_unlink)
Definition MyGUI_WidgetManager.cpp:144
MyGUI::WidgetManager::getCategoryName
const std::string & getCategoryName() const
Definition MyGUI_WidgetManager.cpp:194
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::getClassTypeName
static std::string_view getClassTypeName()
MyGUI::WidgetManager::shutdown
void shutdown()
Definition MyGUI_WidgetManager.cpp:86
MyGUI::WidgetManager::initialise
void initialise()
Definition MyGUI_WidgetManager.cpp:48
MyGUI::WidgetManager::WidgetManager
WidgetManager()
Definition MyGUI_WidgetManager.cpp:42
MyGUI::WidgetManager::isFactoryExist
bool isFactoryExist(std::string_view _type)
Definition MyGUI_WidgetManager.cpp:160
MyGUI::WidgetManager::destroyWidgets
void destroyWidgets(const VectorWidgetPtr &_widgets)
Definition MyGUI_WidgetManager.cpp:128
MyGUI::WidgetManager::_deleteWidget
void _deleteWidget(Widget *_widget)
Definition MyGUI_WidgetManager.cpp:170
MyGUI::WidgetManager::_deleteDelayWidgets
void _deleteDelayWidgets()
Definition MyGUI_WidgetManager.cpp:184
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::WidgetManager::destroyWidget
void destroyWidget(Widget *_widget)
Definition MyGUI_WidgetManager.cpp:123
MyGUI::Window
widget description should be here.
Definition MyGUI_Window.h:34
MyGUI
Definition MyGUI_ActionController.h:15
MyGUI::EnumeratorWidgetPtr
Enumerator< VectorWidgetPtr > EnumeratorWidgetPtr
Definition MyGUI_WidgetDefines.h:22
MyGUI::IntCoord
types::TCoord< int > IntCoord
Definition MyGUI_Types.h:36
MyGUI::newDelegate
delegates::DelegateFunction< Args... > * newDelegate(void(*_func)(Args... args))
Definition MyGUI_Delegate.h:100
MyGUI::VectorWidgetPtr
std::vector< Widget * > VectorWidgetPtr
Definition MyGUI_WidgetDefines.h:20
MyGUI::WidgetStyle
Definition MyGUI_WidgetStyle.h:19