MyGUI: MyGUI_ControllerManager.cpp Source File

MyGUI 3.4.2

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

- File List
- Globals

MyGUI_ControllerManager.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_ControllerManager.h"
10#include "MyGUI_WidgetManager.h"
11#include "MyGUI_FactoryManager.h"
12
13#include "MyGUI_ControllerEdgeHide.h"
14#include "MyGUI_ControllerFadeAlpha.h"
15#include "MyGUI_ControllerPosition.h"
16#include "MyGUI_ControllerRepeatClick.h"
17
18namespace MyGUI
19{
20
21 MYGUI_SINGLETON_DEFINITION(ControllerManager);
22
23 ControllerManager::ControllerManager() :
24 mIsInitialise(false),
25 mCategoryName("Controller"),
26 mSingletonHolder(this)
27 {
28 }
29
30 void ControllerManager::initialise()
31 {
32 MYGUI_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice");
33 MYGUI_LOG(Info, "* Initialise: " << getClassTypeName());
34
35 WidgetManager::getInstance().registerUnlinker(this);
36
37 FactoryManager::getInstance().registerFactory<ControllerEdgeHide>(mCategoryName);
38 FactoryManager::getInstance().registerFactory<ControllerFadeAlpha>(mCategoryName);
39 FactoryManager::getInstance().registerFactory<ControllerPosition>(mCategoryName);
40 FactoryManager::getInstance().registerFactory<ControllerRepeatClick>(mCategoryName);
41
42 MYGUI_LOG(Info, getClassTypeName() << " successfully initialized");
43 mIsInitialise = true;
44 }
45
46 void ControllerManager::shutdown()
47 {
48 MYGUI_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised");
49 MYGUI_LOG(Info, "* Shutdown: " << getClassTypeName());
50
51 FactoryManager::getInstance().unregisterFactory<ControllerEdgeHide>(mCategoryName);
52 FactoryManager::getInstance().unregisterFactory<ControllerFadeAlpha>(mCategoryName);
53 FactoryManager::getInstance().unregisterFactory<ControllerPosition>(mCategoryName);
54 FactoryManager::getInstance().unregisterFactory<ControllerRepeatClick>(mCategoryName);
55
56 WidgetManager::getInstance().unregisterUnlinker(this);
57 clear();
58
59 MYGUI_LOG(Info, getClassTypeName() << " successfully shutdown");
60 mIsInitialise = false;
61 }
62
63 void ControllerManager::clear()
64 {
65 for (ListControllerItem::iterator iter = mListItem.begin(); iter != mListItem.end(); ++iter)
66 {
67 delete (*iter).second;
68 }
69 mListItem.clear();
70 }
71
72 ControllerItem* ControllerManager::createItem(const std::string& _type)
73 {
74 IObject* object = FactoryManager::getInstance().createObject(mCategoryName, _type);
75 return object == nullptr ? nullptr : object->castType<ControllerItem>();
76 }
77
78 void ControllerManager::addItem(Widget* _widget, ControllerItem* _item)
79 {
80 // подготавливаем
81 _item->prepareItem(_widget);
82
83 for (ListControllerItem::iterator iter = mListItem.begin(); iter != mListItem.end(); ++iter)
84 {
85 // такой уже в списке есть
86 if ((*iter).first == _widget)
87 {
88 if ((*iter).second->getTypeName() == _item->getTypeName())
89 {
90 delete (*iter).second;
91 (*iter).second = _item;
92 return;
93 }
94 }
95 }
96
97 // если виджет первый, то подписываемся на кадры
98 if (mListItem.empty())
99 Gui::getInstance().eventFrameStart += newDelegate(this, &ControllerManager::frameEntered);
100
101 // вставляем в самый конец
102 mListItem.push_back(PairControllerItem(_widget, _item));
103 }
104
105 void ControllerManager::removeItem(Widget* _widget)
106 {
107 // не удаляем из списка, а обнуляем, в цикле он будет удален
108 for (ListControllerItem::iterator iter = mListItem.begin(); iter != mListItem.end(); ++iter)
109 {
110 if ((*iter).first == _widget) (*iter).first = nullptr;
111 }
112 }
113
114 void ControllerManager::_unlinkWidget(Widget* _widget)
115 {
116 removeItem(_widget);
117 }
118
119 void ControllerManager::frameEntered(float _time)
120 {
121 for (ListControllerItem::iterator iter = mListItem.begin(); iter != mListItem.end(); /*added in body*/)
122 {
123 if (nullptr == (*iter).first)
124 {
125 delete (*iter).second;
126 // удаляем из списка, итератор не увеличиваем и на новый круг
127 iter = mListItem.erase(iter);
128 continue;
129 }
130
131 if ((*iter).second->addTime((*iter).first, _time))
132 {
133 ++iter;
134 continue;
135 }
136
137 // на следующей итерации виджет вылетит из списка
138 (*iter).first = nullptr;
139 }
140
141 if (mListItem.empty())
142 Gui::getInstance().eventFrameStart -= newDelegate(this, &ControllerManager::frameEntered);
143 }
144
145 const std::string& ControllerManager::getCategoryName() const
146 {
147 return mCategoryName;
148 }
149
150} // namespace MyGUI
MyGUI_ControllerEdgeHide.h
MyGUI_ControllerFadeAlpha.h
MyGUI_ControllerManager.h
MyGUI_ControllerPosition.h
MyGUI_ControllerRepeatClick.h
MYGUI_ASSERT
#define MYGUI_ASSERT(exp, dest)
Definition MyGUI_Diagnostic.h:29
MYGUI_LOG
#define MYGUI_LOG(level, text)
Definition MyGUI_Diagnostic.h:17
MyGUI_FactoryManager.h
MyGUI_Gui.h
MyGUI_Precompiled.h
MYGUI_SINGLETON_DEFINITION
#define MYGUI_SINGLETON_DEFINITION(ClassName)
Definition MyGUI_Singleton.h:123
MyGUI_WidgetManager.h
MyGUI::ControllerEdgeHide
Definition MyGUI_ControllerEdgeHide.h:26
MyGUI::ControllerFadeAlpha
Definition MyGUI_ControllerFadeAlpha.h:20
MyGUI::ControllerItem
Definition MyGUI_ControllerItem.h:27
MyGUI::ControllerItem::getTypeName
virtual const std::string & getTypeName() const override
Definition MyGUI_ControllerItem.h:28
MyGUI::ControllerItem::prepareItem
virtual void prepareItem(Widget *_widget)=0
MyGUI::ControllerManager
Definition MyGUI_ControllerManager.h:22
MyGUI::ControllerManager::createItem
ControllerItem * createItem(const std::string &_type)
Definition MyGUI_ControllerManager.cpp:72
MyGUI::ControllerManager::shutdown
void shutdown()
Definition MyGUI_ControllerManager.cpp:46
MyGUI::ControllerManager::ControllerManager
ControllerManager()
Definition MyGUI_ControllerManager.cpp:23
MyGUI::ControllerManager::getCategoryName
const std::string & getCategoryName() const
Definition MyGUI_ControllerManager.cpp:145
MyGUI::ControllerManager::removeItem
void removeItem(Widget *_widget)
Definition MyGUI_ControllerManager.cpp:105
MyGUI::ControllerManager::getClassTypeName
static const char * getClassTypeName()
MyGUI::ControllerManager::addItem
void addItem(Widget *_widget, ControllerItem *_item)
Definition MyGUI_ControllerManager.cpp:78
MyGUI::ControllerManager::initialise
void initialise()
Definition MyGUI_ControllerManager.cpp:30
MyGUI::ControllerPosition
Definition MyGUI_ControllerPosition.h:22
MyGUI::ControllerRepeatClick
Definition MyGUI_ControllerRepeatClick.h:23
MyGUI::FactoryManager::unregisterFactory
void unregisterFactory(const std::string &_category, const std::string &_type)
Definition MyGUI_FactoryManager.cpp:46
MyGUI::FactoryManager::getInstance
static FactoryManager & getInstance()
MyGUI::FactoryManager::registerFactory
void registerFactory(const std::string &_category, const std::string &_type, Delegate::IDelegate *_delegate)
Definition MyGUI_FactoryManager.cpp:40
MyGUI::FactoryManager::createObject
IObject * createObject(const std::string &_category, const std::string &_type)
Definition MyGUI_FactoryManager.cpp:72
MyGUI::Gui::getInstance
static Gui & getInstance()
Definition MyGUI_Gui.cpp:34
MyGUI::Gui::eventFrameStart
EventHandle_FrameEventDelegate eventFrameStart
Definition MyGUI_Gui.h:150
MyGUI::IObject
Definition MyGUI_IObject.h:17
MyGUI::IObject::castType
Type * castType(bool _throw=true)
Definition MyGUI_IObject.h:18
MyGUI::Widget
widget description should be here.
Definition MyGUI_Widget.h:37
MyGUI::WidgetManager::unregisterUnlinker
void unregisterUnlinker(IUnlinkWidget *_unlink)
Definition MyGUI_WidgetManager.cpp:139
MyGUI::WidgetManager::getInstance
static WidgetManager & getInstance()
MyGUI::WidgetManager::registerUnlinker
void registerUnlinker(IUnlinkWidget *_unlink)
Definition MyGUI_WidgetManager.cpp:133
MyGUI
Definition MyGUI_ActionController.h:15
MyGUI::newDelegate
delegates::DelegateFunction< Args... > * newDelegate(void(*_func)(Args... args))
Definition MyGUI_Delegate.h:99