MyGUI: MyGUI_SkinManager.cpp Source File

MyGUI 3.4.3

MyGUI_SkinManager.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_SkinManager.h"
9#include "MyGUI_LanguageManager.h"
10#include "MyGUI_ResourceSkin.h"
11#include "MyGUI_XmlDocument.h"
12#include "MyGUI_SubWidgetManager.h"
13#include "MyGUI_Gui.h"
14#include "MyGUI_DataManager.h"
15#include "MyGUI_FactoryManager.h"
16#include "MyGUI_IStateInfo.h"
17#include "MyGUI_LayoutManager.h"
18#include "MyGUI_BackwardCompatibility.h"
19
20namespace MyGUI
21{
22
23 MYGUI_SINGLETON_DEFINITION(SkinManager);
24
25 SkinManager::SkinManager() :
26 mXmlSkinTagName("Skin"),
27 mXmlDefaultSkinValue("Default"),
28 mSingletonHolder(this)
29 {
30 }
31
32 void SkinManager::initialise()
33 {
34 MYGUI_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice");
35 MYGUI_LOG(Info, "* Initialise: " << getClassTypeName());
36
37 ResourceManager::getInstance().registerLoadXmlDelegate(mXmlSkinTagName) =
38 newDelegate(this, &SkinManager::_load);
39
40 const std::string& resourceCategory = ResourceManager::getInstance().getCategoryName();
41 FactoryManager::getInstance().registerFactory<ResourceSkin>(resourceCategory);
42
43 mDefaultName = "skin_Default";
44 createDefault(mDefaultName);
45
46 MYGUI_LOG(Info, getClassTypeName() << " successfully initialized");
47 mIsInitialise = true;
48 }
49
50 void SkinManager::shutdown()
51 {
52 MYGUI_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised");
53 MYGUI_LOG(Info, "* Shutdown: " << getClassTypeName());
54
55 ResourceManager::getInstance().unregisterLoadXmlDelegate(mXmlSkinTagName);
56
57 const std::string& resourceCategory = ResourceManager::getInstance().getCategoryName();
58 FactoryManager::getInstance().unregisterFactory<ResourceSkin>(resourceCategory);
59
60 MYGUI_LOG(Info, getClassTypeName() << " successfully shutdown");
61 mIsInitialise = false;
62 }
63
64 void SkinManager::_load(xml::ElementPtr _node, std::string_view _file, Version _version)
65 {
66#ifndef MYGUI_DONT_USE_OBSOLETE
67 loadOldSkinFormat(_node, _file, _version, mXmlSkinTagName);
68#endif // MYGUI_DONT_USE_OBSOLETE
69 }
70
71 void SkinManager::createDefault(std::string_view _value)
72 {
73 const std::string& resourceCategory = ResourceManager::getInstance().getCategoryName();
74 ResourceSkin* skin = FactoryManager::getInstance().createObject<ResourceSkin>(resourceCategory);
75
76 skin->setResourceName(_value);
77 ResourceManager::getInstance().addResource(skin);
78 }
79
80 ResourceSkin* SkinManager::getByName(std::string_view _name) const
81 {
82 std::string_view skinName = BackwardCompatibility::getSkinRename(_name);
83 IResource* result = nullptr;
84 if (!skinName.empty() && skinName != mXmlDefaultSkinValue)
85 result = ResourceManager::getInstance().getByName(skinName, false);
86
87 if (result == nullptr)
88 {
89 result = ResourceManager::getInstance().getByName(mDefaultName, false);
90 if (!skinName.empty() && skinName != mXmlDefaultSkinValue)
91 {
92 MYGUI_LOG(
93 Error,
94 "Skin '" << skinName << "' not found. Replaced with default skin."
95 << " [" << LayoutManager::getInstance().getCurrentLayout() << "]");
96 }
97 }
98
99 return result ? result->castType<ResourceSkin>(false) : nullptr;
100 }
101
102 bool SkinManager::isExist(std::string_view _name) const
103 {
104 std::string_view skinName = BackwardCompatibility::getSkinRename(_name);
105 IResource* result = ResourceManager::getInstance().getByName(skinName, false);
106 return (result != nullptr) && (result->isType<ResourceSkin>());
107 }
108
109 void SkinManager::setDefaultSkin(std::string_view _value)
110 {
111 mDefaultName = _value;
112 }
113
114 const std::string& SkinManager::getDefaultSkin() const
115 {
116 return mDefaultName;
117 }
118
119} // 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