MyGUI 3.2.0

- Main Page
- Related Pages
- Namespaces
- Data Structures
- Files
- Examples

- File List
- Globals

MyGUI_ControllerManager.cpp
Go to the documentation of this file.
1
6 /*
7 This file is part of MyGUI.
8
9 MyGUI is free software: you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 MyGUI is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public License
20 along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
21 */
22 #include "MyGUI_Precompiled.h"
23 #include "MyGUI_Gui.h"
24 #include "MyGUI_ControllerManager.h"
25 #include "MyGUI_WidgetManager.h"
26 #include "MyGUI_FactoryManager.h"
27
28 #include "MyGUI_ControllerEdgeHide.h"
29 #include "MyGUI_ControllerFadeAlpha.h"
30 #include "MyGUI_ControllerPosition.h"
31
32 namespace MyGUI
33 {
34
35 template <> ControllerManager* Singleton<ControllerManager>::msInstance = nullptr;
36 template <> const char* Singleton<ControllerManager>::mClassTypeName("ControllerManager");
37
38 ControllerManager::ControllerManager() :
39 mIsInitialise(false)
40 {
41 }
42
43 void ControllerManager::initialise()
44 {
45 MYGUI_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice");
46 MYGUI_LOG(Info, "* Initialise: " << getClassTypeName());
47
48 WidgetManager::getInstance().registerUnlinker(this);
49
50 const std::string factory_type = "Controller";
51
52 FactoryManager::getInstance().registerFactory<ControllerEdgeHide>(factory_type);
53 FactoryManager::getInstance().registerFactory<ControllerFadeAlpha>(factory_type);
54 FactoryManager::getInstance().registerFactory<ControllerPosition>(factory_type);
55
56 MYGUI_LOG(Info, getClassTypeName() << " successfully initialized");
57 mIsInitialise = true;
58 }
59
60 void ControllerManager::shutdown()
61 {
62 MYGUI_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised");
63 MYGUI_LOG(Info, "* Shutdown: " << getClassTypeName());
64
65 const std::string factory_type = "Controller";
66
67 FactoryManager::getInstance().unregisterFactory<ControllerEdgeHide>(factory_type);
68 FactoryManager::getInstance().unregisterFactory<ControllerFadeAlpha>(factory_type);
69 FactoryManager::getInstance().unregisterFactory<ControllerPosition>(factory_type);
70
71 WidgetManager::getInstance().unregisterUnlinker(this);
72 clear();
73
74 MYGUI_LOG(Info, getClassTypeName() << " successfully shutdown");
75 mIsInitialise = false;
76 }
77
78 void ControllerManager::clear()
79 {
80 for (ListControllerItem::iterator iter = mListItem.begin(); iter != mListItem.end(); ++iter)
81 {
82 delete (*iter).second;
83 }
84 mListItem.clear();
85 }
86
87 ControllerItem* ControllerManager::createItem(const std::string& _type)
88 {
89 IObject* object = FactoryManager::getInstance().createObject("Controller", _type);
90 return object == nullptr ? nullptr : object->castType<ControllerItem>();
91 }
92
93 void ControllerManager::addItem(Widget* _widget, ControllerItem* _item)
94 {
95 // если виджет первый, то подписываемся на кадры
96 if (mListItem.empty())
97 Gui::getInstance().eventFrameStart += newDelegate(this, &ControllerManager::frameEntered);
98
99 // подготавливаем
100 _item->prepareItem(_widget);
101
102 for (ListControllerItem::iterator iter = mListItem.begin(); iter != mListItem.end(); ++iter)
103 {
104 // такой уже в списке есть
105 if ((*iter).first == _widget)
106 {
107 if ((*iter).second->getTypeName() == _item->getTypeName())
108 {
109 delete (*iter).second;
110 (*iter).second = _item;
111 return;
112 }
113 }
114 }
115
116 // вставляем в самый конец
117 mListItem.push_back(PairControllerItem(_widget, _item));
118 }
119
120 void ControllerManager::removeItem(Widget* _widget)
121 {
122 // не удаляем из списка, а обнуляем, в цикле он будет удален
123 for (ListControllerItem::iterator iter = mListItem.begin(); iter != mListItem.end(); ++iter)
124 {
125 if ((*iter).first == _widget) (*iter).first = nullptr;
126 }
127 }
128
129 void ControllerManager::_unlinkWidget(Widget* _widget)
130 {
131 removeItem(_widget);
132 }
133
134 void ControllerManager::frameEntered(float _time)
135 {
136 for (ListControllerItem::iterator iter = mListItem.begin(); iter != mListItem.end(); /*added in body*/)
137 {
138 if (nullptr == (*iter).first)
139 {
140 delete (*iter).second;
141 // удаляем из списка, итератор не увеличиваем и на новый круг
142 iter = mListItem.erase(iter);
143 continue;
144 }
145
146 if ((*iter).second->addTime((*iter).first, _time))
147 {
148 ++iter;
149 continue;
150 }
151
152 // на следующей итерации виджет вылетит из списка
153 (*iter).first = nullptr;
154 }
155
156 if (mListItem.empty())
157 Gui::getInstance().eventFrameStart -= newDelegate(this, &ControllerManager::frameEntered);
158 }
159
160 } // namespace MyGUI
MyGUI::ControllerManager::addItem
void addItem(Widget *_widget, ControllerItem *_item)
Definition: MyGUI_ControllerManager.cpp:93
MyGUI::Widget
Definition: MyGUI_Widget.h:41
MyGUI_ControllerPosition.h
MyGUI_FactoryManager.h
MyGUI_ControllerEdgeHide.h
MyGUI::Gui::eventFrameStart
EventHandle_FrameEventDelegate eventFrameStart
Definition: MyGUI_Gui.h:166
MyGUI::ControllerEdgeHide
Definition: MyGUI_ControllerEdgeHide.h:39
MyGUI::ControllerItem::prepareItem
virtual void prepareItem(Widget *_widget)=0
MyGUI_Precompiled.h
MyGUI::newDelegate
delegates::IDelegate0 * newDelegate(void(*_func)())
Definition: MyGUI_Delegate.h:150
MyGUI::Singleton< WidgetManager >::getInstance
static WidgetManager & getInstance()
Definition: MyGUI_Singleton.h:53
MyGUI_WidgetManager.h
MyGUI::ControllerPosition
Definition: MyGUI_ControllerPosition.h:35
MyGUI::Singleton< ControllerManager >::getClassTypeName
static const char * getClassTypeName()
Definition: MyGUI_Singleton.h:64
MyGUI::ControllerManager::initialise
void initialise()
Definition: MyGUI_ControllerManager.cpp:43
MYGUI_LOG
#define MYGUI_LOG(level, text)
Definition: MyGUI_Diagnostic.h:38
MyGUI_ControllerManager.h
MYGUI_ASSERT
#define MYGUI_ASSERT(exp, dest)
Definition: MyGUI_Diagnostic.h:58
MyGUI::ControllerManager::ControllerManager
ControllerManager()
Definition: MyGUI_ControllerManager.cpp:38
MyGUI_ControllerFadeAlpha.h
MyGUI::ControllerItem::getTypeName
virtual const std::string & getTypeName() const
Definition: MyGUI_ControllerItem.h:37
MyGUI::IObject::castType
Type * castType(bool _throw=true)
Definition: MyGUI_IObject.h:33
MyGUI::WidgetManager::registerUnlinker
void registerUnlinker(IUnlinkWidget *_unlink)
Definition: MyGUI_WidgetManager.cpp:147
MyGUI::FactoryManager::unregisterFactory
void unregisterFactory(const std::string &_category, const std::string &_type)
Definition: MyGUI_FactoryManager.cpp:61
MyGUI::ControllerManager::removeItem
void removeItem(Widget *_widget)
Definition: MyGUI_ControllerManager.cpp:120
MyGUI::IObject
Definition: MyGUI_IObject.h:31
MyGUI::FactoryManager::registerFactory
void registerFactory(const std::string &_category, const std::string &_type, Delegate::IDelegate *_delegate)
Definition: MyGUI_FactoryManager.cpp:55
MyGUI::ControllerManager::shutdown
void shutdown()
Definition: MyGUI_ControllerManager.cpp:60
MyGUI::ControllerFadeAlpha
Definition: MyGUI_ControllerFadeAlpha.h:33
MyGUI::ControllerItem
Definition: MyGUI_ControllerItem.h:34
MyGUI_Gui.h
MyGUI::Singleton::mClassTypeName
static const char * mClassTypeName
Definition: MyGUI_Singleton.h:73
MyGUI::FactoryManager::createObject
IObject * createObject(const std::string &_category, const std::string &_type)
Definition: MyGUI_FactoryManager.cpp:87
MyGUI::WidgetManager::unregisterUnlinker
void unregisterUnlinker(IUnlinkWidget *_unlink)
Definition: MyGUI_WidgetManager.cpp:153
MyGUI::ControllerManager::createItem
ControllerItem * createItem(const std::string &_type)
Definition: MyGUI_ControllerManager.cpp:87