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"
10#include "MyGUI_ResourceSkin.h"
11#include "MyGUI_XmlDocument.h"
13#include "MyGUI_Gui.h"
14#include "MyGUI_DataManager.h"
16#include "MyGUI_IStateInfo.h"
17#include "MyGUI_LayoutManager.h"
19
20namespace MyGUI
21{
22
24
26 mXmlSkinTagName("Skin"),
27 mXmlDefaultSkinValue("Default"),
28 mSingletonHolder(this)
29 {
30 }
31
33 {
34 MYGUI_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice");
35 MYGUI_LOG(Info, "* Initialise: " << getClassTypeName());
36
38 newDelegate(this, &SkinManager::_load);
39
40 const std::string& resourceCategory = ResourceManager::getInstance().getCategoryName();
42
43 mDefaultName = "skin_Default";
44 createDefault(mDefaultName);
45
46 MYGUI_LOG(Info, getClassTypeName() << " successfully initialized");
47 mIsInitialise = true;
48 }
49
51 {
52 MYGUI_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised");
53 MYGUI_LOG(Info, "* Shutdown: " << getClassTypeName());
54
56
57 const std::string& resourceCategory = ResourceManager::getInstance().getCategoryName();
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);
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 {
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
#define MYGUI_ASSERT(exp, dest)
#define MYGUI_LOG(level, text)
#define MYGUI_SINGLETON_DEFINITION(ClassName)
static std::string_view getSkinRename(std::string_view _skinName)
void registerFactory(std::string_view _category, std::string_view _type, Delegate::IDelegate *_delegate)
static FactoryManager & getInstance()
void unregisterFactory(std::string_view _category, std::string_view _type)
IObject * createObject(std::string_view _category, std::string_view _type)
Type * castType(bool _throw=true)
virtual bool isType(const std::type_info &_type) const override
static LayoutManager & getInstance()
void loadOldSkinFormat(xml::ElementPtr _node, std::string_view _file, Version _version, std::string_view _tag)
void unregisterLoadXmlDelegate(std::string_view _key)
const std::string & getCategoryName() const
LoadXmlDelegate & registerLoadXmlDelegate(std::string_view _key)
IResource * getByName(std::string_view _name, bool _throw=true) const
static ResourceManager & getInstance()
void addResource(IResourcePtr _item)
const std::string & getDefaultSkin() const
bool isExist(std::string_view _name) const
ResourceSkin * getByName(std::string_view _name) const
static std::string_view getClassTypeName()
void setDefaultSkin(std::string_view _value)
Element * ElementPtr
delegates::DelegateFunction< Args... > * newDelegate(void(*_func)(Args... args))