MyGUI 3.2.2

- Main Page
- Related Pages
- Namespaces
- Data Structures
- Files
- Examples

- File List
- Globals

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::SkinManager::shutdown
void shutdown()
Definition: MyGUI_SkinManager.cpp:50
MyGUI_FactoryManager.h
MyGUI::ResourceSkin
Definition: MyGUI_ResourceSkin.h:21
MyGUI::ResourceManager::unregisterLoadXmlDelegate
void unregisterLoadXmlDelegate(const std::string &_key)
Definition: MyGUI_ResourceManager.cpp:126
MyGUI_Precompiled.h
MyGUI_DataManager.h
MyGUI::ResourceManager::registerLoadXmlDelegate
LoadXmlDelegate & registerLoadXmlDelegate(const std::string &_key)
Definition: MyGUI_ResourceManager.cpp:119
MyGUI::newDelegate
delegates::IDelegate0 * newDelegate(void(*_func)())
Definition: MyGUI_Delegate.h:118
MyGUI::Singleton< ResourceManager >::getInstance
static ResourceManager & getInstance()
Definition: MyGUI_Singleton.h:38
MyGUI::SkinManager::initialise
void initialise()
Definition: MyGUI_SkinManager.cpp:33
MyGUI::Singleton< SkinManager >::getClassTypeName
static const char * getClassTypeName()
Definition: MyGUI_Singleton.h:49
MyGUI_SubWidgetManager.h
MyGUI_LanguageManager.h
MyGUI::SkinManager::getByName
ResourceSkin * getByName(const std::string &_name) const
Definition: MyGUI_SkinManager.cpp:80
MyGUI::BackwardCompatibility::getSkinRename
static std::string getSkinRename(const std::string &_skinName)
Definition: MyGUI_BackwardCompatibility.cpp:1338
MyGUI::ResourceManager::getByName
IResource * getByName(const std::string &_name, bool _throw=true) const
Definition: MyGUI_ResourceManager.cpp:235
MyGUI_IStateInfo.h
MYGUI_LOG
#define MYGUI_LOG(level, text)
Definition: MyGUI_Diagnostic.h:22
MyGUI_XmlDocument.h
MyGUI_LayoutManager.h
MyGUI
Definition: MyGUI_ActionController.h:14
MYGUI_ASSERT
#define MYGUI_ASSERT(exp, dest)
Definition: MyGUI_Diagnostic.h:42
MyGUI_BackwardCompatibility.h
MyGUI::xml::Element
Definition: MyGUI_XmlDocument.h:158
MyGUI_ResourceSkin.h
MyGUI::IObject::castType
Type * castType(bool _throw=true)
Definition: MyGUI_IObject.h:18
MyGUI::Version
Definition: MyGUI_Version.h:17
MyGUI::FactoryManager::unregisterFactory
void unregisterFactory(const std::string &_category, const std::string &_type)
Definition: MyGUI_FactoryManager.cpp:46
MyGUI::ResourceManager::getCategoryName
const std::string & getCategoryName() const
Definition: MyGUI_ResourceManager.cpp:275
MyGUI::FactoryManager::registerFactory
void registerFactory(const std::string &_category, const std::string &_type, Delegate::IDelegate *_delegate)
Definition: MyGUI_FactoryManager.cpp:40
MyGUI::SkinManager::getDefaultSkin
const std::string getDefaultSkin() const
Definition: MyGUI_SkinManager.cpp:111
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::ResourceManager::addResource
void addResource(IResourcePtr _item)
Definition: MyGUI_ResourceManager.cpp:205
MyGUI_Gui.h
MyGUI::SkinManager::isExist
bool isExist(const std::string &_name) const
Definition: MyGUI_SkinManager.cpp:99
MyGUI::SkinManager::setDefaultSkin
void setDefaultSkin(const std::string &_value)
Definition: MyGUI_SkinManager.cpp:106
MyGUI::IResource
Definition: MyGUI_IResource.h:23
MyGUI::FactoryManager::createObject
IObject * createObject(const std::string &_category, const std::string &_type)
Definition: MyGUI_FactoryManager.cpp:72
MyGUI_SkinManager.h
MyGUI::SkinManager::SkinManager
SkinManager()
Definition: MyGUI_SkinManager.cpp:26
MyGUI::IResource::isType
virtual bool isType(const std::type_info &_type) const
Definition: MyGUI_IResource.h:29