MyGUI: MyGUI_SkinManager.cpp Source File

MyGUI 3.2.2

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
20 namespace MyGUI
21 {
22
23 template <> SkinManager* Singleton<SkinManager>::msInstance = nullptr;
24 template <> const char* Singleton<SkinManager>::mClassTypeName = "SkinManager";
25
26 SkinManager::SkinManager() :
27 mIsInitialise(false),
28 mXmlSkinTagName("Skin"),
29 mXmlDefaultSkinValue("Default")
30 {
31 }
32
33 void SkinManager::initialise()
34 {
35 MYGUI_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice");
36 MYGUI_LOG(Info, "* Initialise: " << getClassTypeName());
37
38 ResourceManager::getInstance().registerLoadXmlDelegate(mXmlSkinTagName) = newDelegate(this, &SkinManager::_load);
39
40 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 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, const std::string& _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(const std::string& _value)
72 {
73 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(const std::string& _name) const
81 {
82 std::string 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(Error, "Skin '" << skinName << "' not found. Replaced with default skin." << " [" << LayoutManager::getInstance().getCurrentLayout() << "]");
93 }
94 }
95
96 return result ? result->castType<ResourceSkin>(false) : nullptr;
97 }
98
99 bool SkinManager::isExist(const std::string& _name) const
100 {
101 std::string skinName = BackwardCompatibility::getSkinRename(_name);
102 IResource* result = ResourceManager::getInstance().getByName(skinName, false);
103 return (result != nullptr) && (result->isType<ResourceSkin>());
104 }
105
106 void SkinManager::setDefaultSkin(const std::string& _value)
107 {
108 mDefaultName = _value;
109 }
110
111 const std::string SkinManager::getDefaultSkin() const
112 {
113 return mDefaultName;
114 }
115
116 } // namespace MyGUI
MyGUI::Singleton< ResourceManager >::getInstance
static ResourceManager & getInstance()
Definition: MyGUI_Singleton.h:38
MyGUI::ResourceManager::getCategoryName
const std::string & getCategoryName() const
Definition: MyGUI_ResourceManager.cpp:275
MyGUI_DataManager.h
MyGUI::FactoryManager::unregisterFactory
void unregisterFactory(const std::string &_category, const std::string &_type)
Definition: MyGUI_FactoryManager.cpp:46
MyGUI_Gui.h
MyGUI::BackwardCompatibility::getSkinRename
static std::string getSkinRename(const std::string &_skinName)
Definition: MyGUI_BackwardCompatibility.cpp:1338
MyGUI_XmlDocument.h
MyGUI::ResourceManager::addResource
void addResource(IResourcePtr _item)
Definition: MyGUI_ResourceManager.cpp:205
MyGUI::ResourceManager::registerLoadXmlDelegate
LoadXmlDelegate & registerLoadXmlDelegate(const std::string &_key)
Definition: MyGUI_ResourceManager.cpp:119
MyGUI::ResourceManager::unregisterLoadXmlDelegate
void unregisterLoadXmlDelegate(const std::string &_key)
Definition: MyGUI_ResourceManager.cpp:126
MyGUI::MemberObsolete< SkinManager >::loadOldSkinFormat
void loadOldSkinFormat(xml::ElementPtr _node, const std::string &_file, Version _version, const std::string &_tag)
Definition: MyGUI_BackwardCompatibility.cpp:1001
MyGUI::ResourceSkin
Definition: MyGUI_ResourceSkin.h:21
MyGUI::Singleton< SkinManager >::getClassTypeName
static const char * getClassTypeName()
Definition: MyGUI_Singleton.h:49
MyGUI::IResource::isType
virtual bool isType(const std::type_info &_type) const
Definition: MyGUI_IResource.h:29
MyGUI::FactoryManager::registerFactory
void registerFactory(const std::string &_category, const std::string &_type, Delegate::IDelegate *_delegate)
Definition: MyGUI_FactoryManager.cpp:40
MyGUI::xml::Element
Definition: MyGUI_XmlDocument.h:158
MyGUI::SkinManager::SkinManager
SkinManager()
Definition: MyGUI_SkinManager.cpp:26
MyGUI_Precompiled.h
MyGUI::Version
Definition: MyGUI_Version.h:17
MYGUI_ASSERT
#define MYGUI_ASSERT(exp, dest)
Definition: MyGUI_Diagnostic.h:42
MyGUI::IObject::castType
Type * castType(bool _throw=true)
Definition: MyGUI_IObject.h:18
MyGUI::SkinManager::getDefaultSkin
const std::string getDefaultSkin() const
Definition: MyGUI_SkinManager.cpp:111
MyGUI::SkinManager::initialise
void initialise()
Definition: MyGUI_SkinManager.cpp:33
MyGUI_LanguageManager.h
MyGUI::ResourceManager::getByName
IResource * getByName(const std::string &_name, bool _throw=true) const
Definition: MyGUI_ResourceManager.cpp:235
MYGUI_LOG
#define MYGUI_LOG(level, text)
Definition: MyGUI_Diagnostic.h:22
MyGUI::FactoryManager::createObject
IObject * createObject(const std::string &_category, const std::string &_type)
Definition: MyGUI_FactoryManager.cpp:72
MyGUI_SkinManager.h
MyGUI::SkinManager::isExist
bool isExist(const std::string &_name) const
Definition: MyGUI_SkinManager.cpp:99
MyGUI_IStateInfo.h
MyGUI::IResource
Definition: MyGUI_IResource.h:23
MyGUI_LayoutManager.h
MyGUI_BackwardCompatibility.h
MyGUI::SkinManager::setDefaultSkin
void setDefaultSkin(const std::string &_value)
Definition: MyGUI_SkinManager.cpp:106
MyGUI
Definition: MyGUI_ActionController.h:14
MyGUI::SkinManager::getByName
ResourceSkin * getByName(const std::string &_name) const
Definition: MyGUI_SkinManager.cpp:80
newDelegate
MYGUI_TEMPLATE MYGUI_TEMPLATE_PARAMS delegates::IDelegateMYGUI_SUFFIX MYGUI_TEMPLATE_ARGS * newDelegate(void(*_func)(MYGUI_PARAMS))
Definition: MyGUI_DelegateImplement.h:117
MyGUI_SubWidgetManager.h
MyGUI::SkinManager::shutdown
void shutdown()
Definition: MyGUI_SkinManager.cpp:50
MyGUI_FactoryManager.h
MyGUI_ResourceSkin.h