MyGUI_SkinManager.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_SkinManager.h"
#include "MyGUI_LanguageManager.h"
#include "MyGUI_ResourceSkin.h"
#include "MyGUI_XmlDocument.h"
#include "MyGUI_SubWidgetManager.h"
#include "MyGUI_Gui.h"
#include "MyGUI_DataManager.h"
#include "MyGUI_FactoryManager.h"
#include "MyGUI_IStateInfo.h"
#include "MyGUI_LayoutManager.h"
#include "MyGUI_BackwardCompatibility.h"
namespace MyGUI
{
MYGUI_SINGLETON_DEFINITION(SkinManager);
SkinManager::SkinManager() :
mXmlSkinTagName("Skin"),
mXmlDefaultSkinValue("Default"),
mSingletonHolder(this)
{
}
void SkinManager::initialise()
{
MYGUI_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice");
MYGUI_LOG(Info, "* Initialise: " << getClassTypeName());
ResourceManager::getInstance().registerLoadXmlDelegate(mXmlSkinTagName) =
newDelegate(this, &SkinManager::_load);
const std::string& resourceCategory = ResourceManager::getInstance().getCategoryName();
FactoryManager::getInstance().registerFactory<ResourceSkin>(resourceCategory);
mDefaultName = "skin_Default";
createDefault(mDefaultName);
MYGUI_LOG(Info, getClassTypeName() << " successfully initialized");
mIsInitialise = true;
}
void SkinManager::shutdown()
{
MYGUI_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised");
MYGUI_LOG(Info, "* Shutdown: " << getClassTypeName());
ResourceManager::getInstance().unregisterLoadXmlDelegate(mXmlSkinTagName);
const std::string& resourceCategory = ResourceManager::getInstance().getCategoryName();
FactoryManager::getInstance().unregisterFactory<ResourceSkin>(resourceCategory);
MYGUI_LOG(Info, getClassTypeName() << " successfully shutdown");
mIsInitialise = false;
}
void SkinManager::_load(xml::ElementPtr _node, std::string_view _file, Version _version)
{
#ifndef MYGUI_DONT_USE_OBSOLETE
loadOldSkinFormat(_node, _file, _version, mXmlSkinTagName);
#endif // MYGUI_DONT_USE_OBSOLETE
}
void SkinManager::createDefault(std::string_view _value)
{
const std::string& resourceCategory = ResourceManager::getInstance().getCategoryName();
ResourceSkin* skin = FactoryManager::getInstance().createObject<ResourceSkin>(resourceCategory);
skin->setResourceName(_value);
ResourceManager::getInstance().addResource(skin);
}
ResourceSkin* SkinManager::getByName(std::string_view _name) const
{
std::string_view skinName = BackwardCompatibility::getSkinRename(_name);
IResource* result = nullptr;
if (!skinName.empty() && skinName != mXmlDefaultSkinValue)
result = ResourceManager::getInstance().getByName(skinName, false);
if (result == nullptr)
{
result = ResourceManager::getInstance().getByName(mDefaultName, false);
if (!skinName.empty() && skinName != mXmlDefaultSkinValue)
{
MYGUI_LOG(
Error,
"Skin '" << skinName << "' not found. Replaced with default skin."
<< " [" << LayoutManager::getInstance().getCurrentLayout() << "]");
}
}
return result ? result->castType<ResourceSkin>(false) : nullptr;
}
bool SkinManager::isExist(std::string_view _name) const
{
std::string_view skinName = BackwardCompatibility::getSkinRename(_name);
IResource* result = ResourceManager::getInstance().getByName(skinName, false);
return (result != nullptr) && (result->isType<ResourceSkin>());
}
void SkinManager::setDefaultSkin(std::string_view _value)
{
mDefaultName = _value;
}
const std::string& SkinManager::getDefaultSkin() const
{
return mDefaultName;
}
} // namespace MyGUI
MyGUI_BackwardCompatibility.h
MyGUI_DataManager.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_IStateInfo.h
MyGUI_LanguageManager.h
MyGUI_LayoutManager.h
MyGUI_Precompiled.h
MyGUI_ResourceSkin.h
MYGUI_SINGLETON_DEFINITION
#define MYGUI_SINGLETON_DEFINITION(ClassName)
Definition MyGUI_Singleton.h:126
MyGUI_SkinManager.h
MyGUI_SubWidgetManager.h
MyGUI_XmlDocument.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::FactoryManager::createObject
IObject * createObject(std::string_view _category, std::string_view _type)
Definition MyGUI_FactoryManager.cpp:80
MyGUI::IObject::castType
Type * castType(bool _throw=true)
Definition MyGUI_IObject.h:18
MyGUI::IResource
Definition MyGUI_IResource.h:24
MyGUI::IResource::isType
virtual bool isType(const std::type_info &_type) const override
Definition MyGUI_IResource.h:28
MyGUI::LayoutManager::getInstance
static LayoutManager & getInstance()
MyGUI::MemberObsolete< SkinManager >::loadOldSkinFormat
void loadOldSkinFormat(xml::ElementPtr _node, std::string_view _file, Version _version, std::string_view _tag)
Definition MyGUI_BackwardCompatibility.cpp:1010
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::getInstance
static ResourceManager & getInstance()
MyGUI::ResourceManager::addResource
void addResource(IResourcePtr _item)
Definition MyGUI_ResourceManager.cpp:213
MyGUI::ResourceSkin
Definition MyGUI_ResourceSkin.h:22
MyGUI::SkinManager
Definition MyGUI_SkinManager.h:22
MyGUI::SkinManager::shutdown
void shutdown()
Definition MyGUI_SkinManager.cpp:50
MyGUI::SkinManager::getDefaultSkin
const std::string & getDefaultSkin() const
Definition MyGUI_SkinManager.cpp:114
MyGUI::SkinManager::isExist
bool isExist(std::string_view _name) const
Definition MyGUI_SkinManager.cpp:102
MyGUI::SkinManager::getByName
ResourceSkin * getByName(std::string_view _name) const
Definition MyGUI_SkinManager.cpp:80
MyGUI::SkinManager::getClassTypeName
static std::string_view getClassTypeName()
MyGUI::SkinManager::initialise
void initialise()
Definition MyGUI_SkinManager.cpp:32
MyGUI::SkinManager::setDefaultSkin
void setDefaultSkin(std::string_view _value)
Definition MyGUI_SkinManager.cpp:109
MyGUI::SkinManager::SkinManager
SkinManager()
Definition MyGUI_SkinManager.cpp:25
MyGUI::Version
Definition MyGUI_Version.h:18
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