MyGUI_ControllerManager.cpp
Go to the documentation of this file.
/*
* This source file is part of MyGUI. For the latest info, see http://mygui.info/
* Distributed under the MIT License
* (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
*/
#include "MyGUI_Precompiled.h"
#include "MyGUI_Gui.h"
#include "MyGUI_ControllerManager.h"
#include "MyGUI_WidgetManager.h"
#include "MyGUI_FactoryManager.h"
#include "MyGUI_ControllerEdgeHide.h"
#include "MyGUI_ControllerFadeAlpha.h"
#include "MyGUI_ControllerPosition.h"
#include "MyGUI_ControllerRepeatClick.h"
namespace MyGUI
{
MYGUI_SINGLETON_DEFINITION(ControllerManager);
ControllerManager::ControllerManager() :
mCategoryName("Controller"),
mSingletonHolder(this)
{
}
void ControllerManager::initialise()
{
MYGUI_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice");
MYGUI_LOG(Info, "* Initialise: " << getClassTypeName());
WidgetManager::getInstance().registerUnlinker(this);
FactoryManager::getInstance().registerFactory<ControllerEdgeHide>(mCategoryName);
FactoryManager::getInstance().registerFactory<ControllerFadeAlpha>(mCategoryName);
FactoryManager::getInstance().registerFactory<ControllerPosition>(mCategoryName);
FactoryManager::getInstance().registerFactory<ControllerRepeatClick>(mCategoryName);
MYGUI_LOG(Info, getClassTypeName() << " successfully initialized");
mIsInitialise = true;
}
void ControllerManager::shutdown()
{
MYGUI_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised");
MYGUI_LOG(Info, "* Shutdown: " << getClassTypeName());
FactoryManager::getInstance().unregisterFactory<ControllerEdgeHide>(mCategoryName);
FactoryManager::getInstance().unregisterFactory<ControllerFadeAlpha>(mCategoryName);
FactoryManager::getInstance().unregisterFactory<ControllerPosition>(mCategoryName);
FactoryManager::getInstance().unregisterFactory<ControllerRepeatClick>(mCategoryName);
WidgetManager::getInstance().unregisterUnlinker(this);
clear();
MYGUI_LOG(Info, getClassTypeName() << " successfully shutdown");
mIsInitialise = false;
}
void ControllerManager::clear()
{
for (auto& iter : mListItem)
{
delete iter.second;
}
mListItem.clear();
}
ControllerItem* ControllerManager::createItem(std::string_view _type)
{
IObject* object = FactoryManager::getInstance().createObject(mCategoryName, _type);
return object == nullptr ? nullptr : object->castType<ControllerItem>();
}
void ControllerManager::addItem(Widget* _widget, ControllerItem* _item)
{
_item->prepareItem(_widget);
for (auto& iter : mListItem)
{
// already in the list
if (iter.first == _widget)
{
if (iter.second->getTypeName() == _item->getTypeName())
{
delete iter.second;
iter.second = _item;
return;
}
}
}
// subscribe to events only for first item
if (mListItem.empty())
Gui::getInstance().eventFrameStart += newDelegate(this, &ControllerManager::frameEntered);
mListItem.emplace_back(_widget, _item);
}
void ControllerManager::removeItem(Widget* _widget)
{
// replace with nullptr instead of removing, will be deleted in frameEntered
for (auto& iter : mListItem)
{
if (iter.first == _widget)
iter.first = nullptr;
}
}
void ControllerManager::_unlinkWidget(Widget* _widget)
{
removeItem(_widget);
}
void ControllerManager::frameEntered(float _time)
{
for (ListControllerItem::iterator iter = mListItem.begin(); iter != mListItem.end(); /*added in body*/)
{
if (nullptr == (*iter).first)
{
delete (*iter).second;
iter = mListItem.erase(iter);
continue;
}
if ((*iter).second->addTime((*iter).first, _time))
{
++iter;
continue;
}
// will be removed in next iteration
(*iter).first = nullptr;
}
if (mListItem.empty())
Gui::getInstance().eventFrameStart -= newDelegate(this, &ControllerManager::frameEntered);
}
const std::string& ControllerManager::getCategoryName() const
{
return mCategoryName;
}
} // 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:31
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:126
MyGUI_WidgetManager.h
MyGUI::ControllerEdgeHide
Definition MyGUI_ControllerEdgeHide.h:25
MyGUI::ControllerFadeAlpha
Definition MyGUI_ControllerFadeAlpha.h:19
MyGUI::ControllerItem
Definition MyGUI_ControllerItem.h:26
MyGUI::ControllerItem::getTypeName
virtual std::string_view getTypeName() const override
Definition MyGUI_ControllerItem.h:27
MyGUI::ControllerItem::prepareItem
virtual void prepareItem(Widget *_widget)=0
MyGUI::ControllerManager
Definition MyGUI_ControllerManager.h:21
MyGUI::ControllerManager::createItem
ControllerItem * createItem(std::string_view _type)
Definition MyGUI_ControllerManager.cpp:71
MyGUI::ControllerManager::shutdown
void shutdown()
Definition MyGUI_ControllerManager.cpp:45
MyGUI::ControllerManager::ControllerManager
ControllerManager()
Definition MyGUI_ControllerManager.cpp:23
MyGUI::ControllerManager::getClassTypeName
static std::string_view getClassTypeName()
MyGUI::ControllerManager::getCategoryName
const std::string & getCategoryName() const
Definition MyGUI_ControllerManager.cpp:142
MyGUI::ControllerManager::removeItem
void removeItem(Widget *_widget)
Definition MyGUI_ControllerManager.cpp:102
MyGUI::ControllerManager::addItem
void addItem(Widget *_widget, ControllerItem *_item)
Definition MyGUI_ControllerManager.cpp:77
MyGUI::ControllerManager::initialise
void initialise()
Definition MyGUI_ControllerManager.cpp:29
MyGUI::ControllerPosition
Definition MyGUI_ControllerPosition.h:21
MyGUI::ControllerRepeatClick
Definition MyGUI_ControllerRepeatClick.h:22
MyGUI::FactoryManager::registerFactory
void registerFactory(std::string_view _category, std::string_view _type, Delegate::IDelegate *_delegate)
Definition MyGUI_FactoryManager.cpp:39
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::getInstance
static Gui & getInstance()
Definition MyGUI_Gui.cpp:34
MyGUI::Gui::eventFrameStart
EventHandle_FrameEventDelegate eventFrameStart
Definition MyGUI_Gui.h:215
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:40
MyGUI::WidgetManager::unregisterUnlinker
void unregisterUnlinker(IUnlinkWidget *_unlink)
Definition MyGUI_WidgetManager.cpp:144
MyGUI::WidgetManager::getInstance
static WidgetManager & getInstance()
MyGUI::WidgetManager::registerUnlinker
void registerUnlinker(IUnlinkWidget *_unlink)
Definition MyGUI_WidgetManager.cpp:138
MyGUI
Definition MyGUI_ActionController.h:15
MyGUI::newDelegate
delegates::DelegateFunction< Args... > * newDelegate(void(*_func)(Args... args))
Definition MyGUI_Delegate.h:100