MyGUI_LayoutManager.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_LayoutManager.h"
#include "MyGUI_ResourceManager.h"
#include "MyGUI_FactoryManager.h"
#include "MyGUI_WidgetManager.h"
namespace MyGUI
{
MYGUI_SINGLETON_DEFINITION(LayoutManager);
LayoutManager::LayoutManager() :
mXmlLayoutTagName("Layout"),
mSingletonHolder(this)
{
}
void LayoutManager::initialise()
{
MYGUI_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice");
MYGUI_LOG(Info, "* Initialise: " << getClassTypeName());
ResourceManager::getInstance().registerLoadXmlDelegate(mXmlLayoutTagName) =
newDelegate(this, &LayoutManager::_load);
const std::string& resourceCategory = ResourceManager::getInstance().getCategoryName();
FactoryManager::getInstance().registerFactory<ResourceLayout>(resourceCategory);
MYGUI_LOG(Info, getClassTypeName() << " successfully initialized");
mIsInitialise = true;
}
void LayoutManager::shutdown()
{
MYGUI_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised");
MYGUI_LOG(Info, "* Shutdown: " << getClassTypeName());
ResourceManager::getInstance().unregisterLoadXmlDelegate(mXmlLayoutTagName);
const std::string& resourceCategory = ResourceManager::getInstance().getCategoryName();
FactoryManager::getInstance().unregisterFactory<ResourceLayout>(resourceCategory);
MYGUI_LOG(Info, getClassTypeName() << " successfully shutdown");
mIsInitialise = false;
}
void LayoutManager::_load(xml::ElementPtr _node, std::string_view _file, Version _version)
{
ResourceLayout* resource = new ResourceLayout(_node, _file);
ResourceManager::getInstance().addResource(resource);
}
VectorWidgetPtr LayoutManager::loadLayout(std::string_view _file, std::string_view _prefix, Widget* _parent)
{
mCurrentLayoutName = _file;
ResourceLayout* resource = getByName(_file, false);
if (!resource)
{
ResourceManager::getInstance().load(mCurrentLayoutName);
resource = getByName(_file, false);
}
VectorWidgetPtr result;
if (resource)
result = resource->createLayout(_prefix, _parent);
else
MYGUI_LOG(Warning, "Layout '" << _file << "' couldn't be loaded");
mCurrentLayoutName.clear();
return result;
}
void LayoutManager::unloadLayout(VectorWidgetPtr& _widgets)
{
WidgetManager::getInstance().destroyWidgets(_widgets);
}
ResourceLayout* LayoutManager::getByName(std::string_view _name, bool _throw) const
{
std::string_view skinName = BackwardCompatibility::getSkinRename(_name);
IResource* result = ResourceManager::getInstance().getByName(skinName, false);
if (result != nullptr)
{
ResourceLayout* resource = result->castType<ResourceLayout>(false);
if (resource == nullptr)
{
MYGUI_ASSERT(!_throw, "Resource '" << skinName << "' is not ResourceLayout type");
}
return resource;
}
MYGUI_ASSERT(!_throw, "ResourceLayout '" << skinName << "' not found");
return nullptr;
}
const std::string& LayoutManager::getCurrentLayout() const
{
return mCurrentLayoutName;
}
bool LayoutManager::isExist(std::string_view _name) const
{
return getByName(_name, false) != nullptr;
}
} // namespace MyGUI
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_LayoutManager.h
MyGUI_Precompiled.h
MyGUI_ResourceManager.h
MYGUI_SINGLETON_DEFINITION
#define MYGUI_SINGLETON_DEFINITION(ClassName)
Definition MyGUI_Singleton.h:126
MyGUI_WidgetManager.h
MyGUI::BackwardCompatibility::getSkinRename
static std::string_view getSkinRename(std::string_view _skinName)
Definition MyGUI_BackwardCompatibility.cpp:1417
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::IObject::castType
Type * castType(bool _throw=true)
Definition MyGUI_IObject.h:18
MyGUI::IResource
Definition MyGUI_IResource.h:24
MyGUI::LayoutManager
Definition MyGUI_LayoutManager.h:27
MyGUI::LayoutManager::unloadLayout
void unloadLayout(VectorWidgetPtr &_widgets)
Definition MyGUI_LayoutManager.cpp:81
MyGUI::LayoutManager::getCurrentLayout
const std::string & getCurrentLayout() const
Definition MyGUI_LayoutManager.cpp:105
MyGUI::LayoutManager::getByName
ResourceLayout * getByName(std::string_view _name, bool _throw=true) const
Definition MyGUI_LayoutManager.cpp:86
MyGUI::LayoutManager::isExist
bool isExist(std::string_view _name) const
Definition MyGUI_LayoutManager.cpp:110
MyGUI::LayoutManager::loadLayout
VectorWidgetPtr loadLayout(std::string_view _file, std::string_view _prefix={}, Widget *_parent=nullptr)
Definition MyGUI_LayoutManager.cpp:59
MyGUI::LayoutManager::initialise
void initialise()
Definition MyGUI_LayoutManager.cpp:24
MyGUI::LayoutManager::getClassTypeName
static std::string_view getClassTypeName()
MyGUI::LayoutManager::LayoutManager
LayoutManager()
Definition MyGUI_LayoutManager.cpp:18
MyGUI::LayoutManager::shutdown
void shutdown()
Definition MyGUI_LayoutManager.cpp:39
MyGUI::ResourceLayout
Definition MyGUI_ResourceLayout.h:19
MyGUI::ResourceLayout::createLayout
VectorWidgetPtr createLayout(std::string_view _prefix={}, Widget *_parent=nullptr)
Definition MyGUI_ResourceLayout.cpp:104
MyGUI::ResourceManager::unregisterLoadXmlDelegate
void unregisterLoadXmlDelegate(std::string_view _key)
Definition MyGUI_ResourceManager.cpp:127
MyGUI::ResourceManager::getCategoryName
const std::string & getCategoryName() const
Definition MyGUI_ResourceManager.cpp:283
MyGUI::ResourceManager::registerLoadXmlDelegate
LoadXmlDelegate & registerLoadXmlDelegate(std::string_view _key)
Definition MyGUI_ResourceManager.cpp:120
MyGUI::ResourceManager::getByName
IResource * getByName(std::string_view _name, bool _throw=true) const
Definition MyGUI_ResourceManager.cpp:243
MyGUI::ResourceManager::load
bool load(const std::string &_file)
Definition MyGUI_ResourceManager.cpp:60
MyGUI::ResourceManager::getInstance
static ResourceManager & getInstance()
MyGUI::ResourceManager::addResource
void addResource(IResourcePtr _item)
Definition MyGUI_ResourceManager.cpp:213
MyGUI::Version
Definition MyGUI_Version.h:18
MyGUI::Widget
widget description should be here.
Definition MyGUI_Widget.h:40
MyGUI::WidgetManager::destroyWidgets
void destroyWidgets(const VectorWidgetPtr &_widgets)
Definition MyGUI_WidgetManager.cpp:128
MyGUI::WidgetManager::getInstance
static WidgetManager & getInstance()
MyGUI::xml::ElementPtr
Element * ElementPtr
Definition MyGUI_XmlDocument.h:112
MyGUI
Definition MyGUI_ActionController.h:15
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