MyGUI 3.2.0

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

- File List
- Globals

MyGUI_SkinManager.cpp
Go to the documentation of this file.
1
6 /*
7 This file is part of MyGUI.
8
9 MyGUI is free software: you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 MyGUI is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public License
20 along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
21 */
22 #include "MyGUI_Precompiled.h"
23 #include "MyGUI_SkinManager.h"
24 #include "MyGUI_LanguageManager.h"
25 #include "MyGUI_ResourceSkin.h"
26 #include "MyGUI_XmlDocument.h"
27 #include "MyGUI_SubWidgetManager.h"
28 #include "MyGUI_Gui.h"
29 #include "MyGUI_DataManager.h"
30 #include "MyGUI_FactoryManager.h"
31 #include "MyGUI_IStateInfo.h"
32 #include "MyGUI_LayoutManager.h"
33 #include "MyGUI_BackwardCompatibility.h"
34
35 namespace MyGUI
36 {
37
38 const std::string XML_TYPE("Skin");
39 const std::string XML_TYPE_RESOURCE("Resource");
40 const std::string RESOURCE_DEFAULT_NAME("Default");
41
42 template <> SkinManager* Singleton<SkinManager>::msInstance = nullptr;
43 template <> const char* Singleton<SkinManager>::mClassTypeName("SkinManager");
44
45 SkinManager::SkinManager() :
46 mIsInitialise(false)
47 {
48 }
49
50 void SkinManager::initialise()
51 {
52 MYGUI_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice");
53 MYGUI_LOG(Info, "* Initialise: " << getClassTypeName());
54
55 ResourceManager::getInstance().registerLoadXmlDelegate(XML_TYPE) = newDelegate(this, &SkinManager::_load);
56 FactoryManager::getInstance().registerFactory<ResourceSkin>(XML_TYPE_RESOURCE);
57
58 mDefaultName = "skin_Default";
59 createDefault(mDefaultName);
60
61 MYGUI_LOG(Info, getClassTypeName() << " successfully initialized");
62 mIsInitialise = true;
63 }
64
65 void SkinManager::shutdown()
66 {
67 MYGUI_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised");
68 MYGUI_LOG(Info, "* Shutdown: " << getClassTypeName());
69
70 ResourceManager::getInstance().unregisterLoadXmlDelegate(XML_TYPE);
71 FactoryManager::getInstance().unregisterFactory<ResourceSkin>(XML_TYPE_RESOURCE);
72
73 MYGUI_LOG(Info, getClassTypeName() << " successfully shutdown");
74 mIsInitialise = false;
75 }
76
77 void SkinManager::_load(xml::ElementPtr _node, const std::string& _file, Version _version)
78 {
79 // берем детей и крутимся, основной цикл со скинами
80 xml::ElementEnumerator skin = _node->getElementEnumerator();
81 while (skin.next(XML_TYPE))
82 {
83 /*std::string name = */skin->findAttribute("name");
84 std::string type = skin->findAttribute("type");
85 if (type.empty())
86 type = "ResourceSkin";
87
88 IObject* object = FactoryManager::getInstance().createObject(XML_TYPE_RESOURCE, type);
89 if (object != nullptr)
90 {
91 ResourceSkin* data = object->castType<ResourceSkin>();
92 data->deserialization(skin.current(), _version);
93
94 ResourceManager::getInstance().addResource(data);
95 }
96 }
97 }
98
99 void SkinManager::createDefault(const std::string& _value)
100 {
101 xml::Document doc;
102 xml::ElementPtr root = doc.createRoot("MyGUI");
103 xml::ElementPtr newnode = root->createChild("Resource");
104 newnode->addAttribute("type", ResourceSkin::getClassTypeName());
105 newnode->addAttribute("name", _value);
106
107 ResourceManager::getInstance().loadFromXmlNode(root, "", Version());
108 }
109
110 ResourceSkin* SkinManager::getByName(const std::string& _name) const
111 {
112 std::string skinName = BackwardCompatibility::getSkinRename(_name);
113 IResource* result = nullptr;
114 if (!skinName.empty() && skinName != RESOURCE_DEFAULT_NAME)
115 result = ResourceManager::getInstance().getByName(skinName, false);
116
117 if (result == nullptr)
118 {
119 result = ResourceManager::getInstance().getByName(mDefaultName, false);
120 if (!skinName.empty() && skinName != RESOURCE_DEFAULT_NAME)
121 {
122 MYGUI_LOG(Error, "Skin '" << skinName << "' not found. Replaced with default skin." << " [" << LayoutManager::getInstance().getCurrentLayout() << "]");
123 }
124 }
125
126 return result ? result->castType<ResourceSkin>(false) : nullptr;
127 }
128
129 bool SkinManager::isExist(const std::string& _name) const
130 {
131 std::string skinName = BackwardCompatibility::getSkinRename(_name);
132 IResource* result = ResourceManager::getInstance().getByName(skinName, false);
133 return (result != nullptr) && (result->isType<ResourceSkin>());
134 }
135
136 void SkinManager::setDefaultSkin(const std::string& _value)
137 {
138 mDefaultName = _value;
139 }
140
141 const std::string SkinManager::getDefaultSkin() const
142 {
143 return mDefaultName;
144 }
145
146 } // namespace MyGUI
MyGUI::SkinManager::shutdown
void shutdown()
Definition: MyGUI_SkinManager.cpp:65
MyGUI::RESOURCE_DEFAULT_NAME
const std::string RESOURCE_DEFAULT_NAME("Default")
MyGUI_FactoryManager.h
MyGUI::ResourceSkin
Definition: MyGUI_ResourceSkin.h:36
MyGUI::ResourceManager::unregisterLoadXmlDelegate
void unregisterLoadXmlDelegate(const std::string &_key)
Definition: MyGUI_ResourceManager.cpp:142
MyGUI_Precompiled.h
MyGUI_DataManager.h
MyGUI::ResourceManager::registerLoadXmlDelegate
LoadXmlDelegate & registerLoadXmlDelegate(const std::string &_key)
Definition: MyGUI_ResourceManager.cpp:135
MyGUI::xml::ElementPtr
Element * ElementPtr
Definition: MyGUI_XmlDocument.h:114
MyGUI::newDelegate
delegates::IDelegate0 * newDelegate(void(*_func)())
Definition: MyGUI_Delegate.h:150
MyGUI::Singleton< ResourceManager >::getInstance
static ResourceManager & getInstance()
Definition: MyGUI_Singleton.h:53
MyGUI::ResourceManager::loadFromXmlNode
void loadFromXmlNode(xml::ElementPtr _node, const std::string &_file, Version _version)
Definition: MyGUI_ResourceManager.cpp:82
MyGUI::SkinManager::initialise
void initialise()
Definition: MyGUI_SkinManager.cpp:50
MyGUI::xml::Element::findAttribute
bool findAttribute(const std::string &_name, std::string &_value)
Definition: MyGUI_XmlDocument.cpp:261
MyGUI::Singleton< SkinManager >::getClassTypeName
static const char * getClassTypeName()
Definition: MyGUI_Singleton.h:64
MyGUI::XML_TYPE
const std::string XML_TYPE("Font")
MyGUI_SubWidgetManager.h
MyGUI::ResourceSkin::deserialization
virtual void deserialization(xml::ElementPtr _node, Version _version)
Definition: MyGUI_ResourceSkin.cpp:44
MyGUI_LanguageManager.h
MyGUI::SkinManager::getByName
ResourceSkin * getByName(const std::string &_name) const
Definition: MyGUI_SkinManager.cpp:110
MyGUI::BackwardCompatibility::getSkinRename
static std::string getSkinRename(const std::string &_skinName)
Definition: MyGUI_BackwardCompatibility.cpp:1119
MyGUI::ResourceManager::getByName
IResource * getByName(const std::string &_name, bool _throw=true) const
Definition: MyGUI_ResourceManager.cpp:251
MyGUI::xml::ElementEnumerator
Definition: MyGUI_XmlDocument.h:124
MyGUI_IStateInfo.h
MYGUI_LOG
#define MYGUI_LOG(level, text)
Definition: MyGUI_Diagnostic.h:38
MyGUI_XmlDocument.h
MyGUI_LayoutManager.h
MyGUI::xml::ElementEnumerator::next
bool next()
Definition: MyGUI_XmlDocument.cpp:115
MYGUI_ASSERT
#define MYGUI_ASSERT(exp, dest)
Definition: MyGUI_Diagnostic.h:58
MyGUI_BackwardCompatibility.h
MyGUI::xml::Element
Definition: MyGUI_XmlDocument.h:168
MyGUI_ResourceSkin.h
MyGUI::IObject::castType
Type * castType(bool _throw=true)
Definition: MyGUI_IObject.h:33
MyGUI::Version
Definition: MyGUI_Version.h:32
MyGUI::FactoryManager::unregisterFactory
void unregisterFactory(const std::string &_category, const std::string &_type)
Definition: MyGUI_FactoryManager.cpp:61
MyGUI::IObject
Definition: MyGUI_IObject.h:31
MyGUI::FactoryManager::registerFactory
void registerFactory(const std::string &_category, const std::string &_type, Delegate::IDelegate *_delegate)
Definition: MyGUI_FactoryManager.cpp:55
MyGUI::SkinManager::getDefaultSkin
const std::string getDefaultSkin() const
Definition: MyGUI_SkinManager.cpp:141
MyGUI::xml::Element::getElementEnumerator
ElementEnumerator getElementEnumerator()
Definition: MyGUI_XmlDocument.cpp:367
MyGUI::ResourceManager::addResource
void addResource(IResourcePtr _item)
Definition: MyGUI_ResourceManager.cpp:221
MyGUI_Gui.h
MyGUI::SkinManager::isExist
bool isExist(const std::string &_name) const
Definition: MyGUI_SkinManager.cpp:129
MyGUI::SkinManager::setDefaultSkin
void setDefaultSkin(const std::string &_value)
Definition: MyGUI_SkinManager.cpp:136
MyGUI::IResource
Definition: MyGUI_IResource.h:38
MyGUI::Singleton::mClassTypeName
static const char * mClassTypeName
Definition: MyGUI_Singleton.h:73
MyGUI::xml::Element::addAttribute
void addAttribute(const std::string &_key, const T &_value)
Definition: MyGUI_XmlDocument.h:184
MyGUI::FactoryManager::createObject
IObject * createObject(const std::string &_category, const std::string &_type)
Definition: MyGUI_FactoryManager.cpp:87
MyGUI_SkinManager.h
MyGUI::SkinManager::SkinManager
SkinManager()
Definition: MyGUI_SkinManager.cpp:45
MyGUI::XML_TYPE_RESOURCE
const std::string XML_TYPE_RESOURCE("Resource")
MyGUI::xml::Element::createChild
ElementPtr createChild(const std::string &_name, const std::string &_content="", ElementType _type=ElementType::Normal)
Definition: MyGUI_XmlDocument.cpp:236
MyGUI::IResource::isType
virtual bool isType(const std::type_info &_type) const
Definition: MyGUI_IResource.h:44
MyGUI::ResourceSkin::getClassTypeName
static const std::string & getClassTypeName()
Definition: MyGUI_ResourceSkin.h:39
MyGUI::xml::ElementEnumerator::current
ElementPtr current()
Definition: MyGUI_XmlDocument.cpp:146