MyGUI 3.4.1
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"
10#include "MyGUI_WidgetManager.h"
12
17
18namespace MyGUI
19{
20
22
24 mIsInitialise(false),
25 mCategoryName("Controller"),
26 mSingletonHolder(this)
27 {
28 }
29
31 {
32 MYGUI_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice");
33 MYGUI_LOG(Info, "* Initialise: " << getClassTypeName());
34
36
41
42 MYGUI_LOG(Info, getClassTypeName() << " successfully initialized");
43 mIsInitialise = true;
44 }
45
47 {
48 MYGUI_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised");
49 MYGUI_LOG(Info, "* Shutdown: " << getClassTypeName());
50
55
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
73 {
74 IObject* object = FactoryManager::getInstance().createObject(mCategoryName, _type);
75 return object == nullptr ? nullptr : object->castType<ControllerItem>();
76 }
77
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
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
#define MYGUI_ASSERT(exp, dest)
#define MYGUI_LOG(level, text)
virtual const std::string & getTypeName() const override
virtual void prepareItem(Widget *_widget)=0
ControllerItem * createItem(const std::string &_type)
const std::string & getCategoryName() const
static const char * getClassTypeName()
void addItem(Widget *_widget, ControllerItem *_item)
void unregisterFactory(const std::string &_category, const std::string &_type)
static FactoryManager & getInstance()
void registerFactory(const std::string &_category, const std::string &_type, Delegate::IDelegate *_delegate)
IObject * createObject(const std::string &_category, const std::string &_type)
static Gui & getInstance()
EventHandle_FrameEventDelegate eventFrameStart
Definition: MyGUI_Gui.h:150
Type * castType(bool _throw=true)
Definition: MyGUI_IObject.h:18
widget description should be here.
Definition: MyGUI_Widget.h:37
void unregisterUnlinker(IUnlinkWidget *_unlink)
static WidgetManager & getInstance()
void registerUnlinker(IUnlinkWidget *_unlink)
delegates::DelegateFunction< Args... > * newDelegate(void(*_func)(Args... args))
MYGUI_SINGLETON_DEFINITION(ClipboardManager)