MyGUI_WidgetManager.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_WidgetManager.h"
#include "MyGUI_Gui.h"
#include "MyGUI_Widget.h"
#include "MyGUI_FactoryManager.h"
#include "MyGUI_Button.h"
#include "MyGUI_Canvas.h"
#include "MyGUI_ComboBox.h"
#include "MyGUI_DDContainer.h"
#include "MyGUI_EditBox.h"
#include "MyGUI_ItemBox.h"
#include "MyGUI_ListBox.h"
#include "MyGUI_MenuBar.h"
#include "MyGUI_MenuControl.h"
#include "MyGUI_MenuItem.h"
#include "MyGUI_MultiListBox.h"
#include "MyGUI_MultiListItem.h"
#include "MyGUI_PopupMenu.h"
#include "MyGUI_ProgressBar.h"
#include "MyGUI_ScrollBar.h"
#include "MyGUI_ScrollView.h"
#include "MyGUI_ImageBox.h"
#include "MyGUI_TextBox.h"
#include "MyGUI_TabControl.h"
#include "MyGUI_TabItem.h"
#include "MyGUI_Window.h"
#include "MyGUI_BackwardCompatibility.h"
namespace MyGUI
{
MYGUI_SINGLETON_DEFINITION(WidgetManager);
WidgetManager::WidgetManager() :
mCategoryName("Widget"),
mSingletonHolder(this)
{
}
void WidgetManager::initialise()
{
MYGUI_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice");
MYGUI_LOG(Info, "* Initialise: " << getClassTypeName());
FactoryManager& factory = FactoryManager::getInstance();
factory.registerFactory<Button>(mCategoryName);
factory.registerFactory<Canvas>(mCategoryName);
factory.registerFactory<ComboBox>(mCategoryName);
factory.registerFactory<DDContainer>(mCategoryName);
factory.registerFactory<EditBox>(mCategoryName);
factory.registerFactory<ItemBox>(mCategoryName);
factory.registerFactory<ListBox>(mCategoryName);
factory.registerFactory<MenuBar>(mCategoryName);
factory.registerFactory<MenuControl>(mCategoryName);
factory.registerFactory<MenuItem>(mCategoryName);
factory.registerFactory<MultiListBox>(mCategoryName);
factory.registerFactory<MultiListItem>(mCategoryName);
factory.registerFactory<PopupMenu>(mCategoryName);
factory.registerFactory<ProgressBar>(mCategoryName);
factory.registerFactory<ScrollBar>(mCategoryName);
factory.registerFactory<ScrollView>(mCategoryName);
factory.registerFactory<ImageBox>(mCategoryName);
factory.registerFactory<TextBox>(mCategoryName);
factory.registerFactory<TabControl>(mCategoryName);
factory.registerFactory<TabItem>(mCategoryName);
factory.registerFactory<Widget>(mCategoryName);
factory.registerFactory<Window>(mCategoryName);
BackwardCompatibility::registerWidgetTypes();
Gui::getInstance().eventFrameStart += newDelegate(this, &WidgetManager::notifyEventFrameStart);
MYGUI_LOG(Info, getClassTypeName() << " successfully initialized");
mIsInitialise = true;
}
void WidgetManager::shutdown()
{
MYGUI_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised");
MYGUI_LOG(Info, "* Shutdown: " << getClassTypeName());
Gui::getInstance().eventFrameStart -= newDelegate(this, &WidgetManager::notifyEventFrameStart);
_deleteDelayWidgets();
mVectorIUnlinkWidget.clear();
FactoryManager::getInstance().unregisterFactory(mCategoryName);
MYGUI_LOG(Info, getClassTypeName() << " successfully shutdown");
mIsInitialise = false;
}
Widget* WidgetManager::createWidget(
WidgetStyle _style,
std::string_view _type,
std::string_view _skin,
const IntCoord& _coord,
Widget* _parent,
ICroppedRectangle* _cropeedParent,
std::string_view _name)
{
IObject* object = FactoryManager::getInstance().createObject(mCategoryName, _type);
if (object != nullptr)
{
Widget* widget = object->castType<Widget>();
widget->_initialise(_style, _coord, _skin, _parent, _cropeedParent, _name);
return widget;
}
MYGUI_EXCEPT("factory '" << _type << "' not found");
}
void WidgetManager::destroyWidget(Widget* _widget)
{
Gui::getInstance().destroyWidget(_widget);
}
void WidgetManager::destroyWidgets(const VectorWidgetPtr& _widgets)
{
Gui::getInstance().destroyWidgets(_widgets);
}
void WidgetManager::destroyWidgets(EnumeratorWidgetPtr _widgets)
{
Gui::getInstance().destroyWidgets(_widgets);
}
void WidgetManager::registerUnlinker(IUnlinkWidget* _unlink)
{
unregisterUnlinker(_unlink);
mVectorIUnlinkWidget.push_back(_unlink);
}
void WidgetManager::unregisterUnlinker(IUnlinkWidget* _unlink)
{
VectorIUnlinkWidget::iterator iter =
std::remove(mVectorIUnlinkWidget.begin(), mVectorIUnlinkWidget.end(), _unlink);
if (iter != mVectorIUnlinkWidget.end())
mVectorIUnlinkWidget.erase(iter);
}
void WidgetManager::unlinkFromUnlinkers(Widget* _widget)
{
for (auto& iter : mVectorIUnlinkWidget)
{
iter->_unlinkWidget(_widget);
}
}
bool WidgetManager::isFactoryExist(std::string_view _type)
{
return FactoryManager::getInstance().isFactoryExist(mCategoryName, _type);
}
void WidgetManager::notifyEventFrameStart(float _time)
{
_deleteDelayWidgets();
}
void WidgetManager::_deleteWidget(Widget* _widget)
{
_widget->_shutdown();
for (auto& widget : mDestroyWidgets)
{
/*if ((*entry) == _widget)
return;*/
MYGUI_ASSERT(widget != _widget, "double delete widget");
}
mDestroyWidgets.push_back(_widget);
}
void WidgetManager::_deleteDelayWidgets()
{
if (!mDestroyWidgets.empty())
{
for (auto& widget : mDestroyWidgets)
delete widget;
mDestroyWidgets.clear();
}
}
const std::string& WidgetManager::getCategoryName() const
{
return mCategoryName;
}
} // 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