MyGUI  3.4.1
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"
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"
19 
20 namespace MyGUI
21 {
22 
24 
26  mIsInitialise(false),
27  mXmlSkinTagName("Skin"),
28  mXmlDefaultSkinValue("Default"),
29  mSingletonHolder(this)
30  {
31  }
32 
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();
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  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, 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);
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
#define MYGUI_ASSERT(exp, dest)
#define MYGUI_LOG(level, text)
static std::string getSkinRename(const std::string &_skinName)
void unregisterFactory(const std::string &_category, const std::string &_type)
void registerFactory(const std::string &_category, const std::string &_type, Delegate::IDelegate *_delegate)
IObject * createObject(const std::string &_category, const std::string &_type)
static FactoryManager & getInstance()
Type * castType(bool _throw=true)
Definition: MyGUI_IObject.h:18
virtual bool isType(const std::type_info &_type) const override
static LayoutManager & getInstance()
void loadOldSkinFormat(xml::ElementPtr _node, const std::string &_file, Version _version, const std::string &_tag)
const std::string & getCategoryName() const
IResource * getByName(const std::string &_name, bool _throw=true) const
void unregisterLoadXmlDelegate(const std::string &_key)
static ResourceManager & getInstance()
LoadXmlDelegate & registerLoadXmlDelegate(const std::string &_key)
void addResource(IResourcePtr _item)
const std::string getDefaultSkin() const
void setDefaultSkin(const std::string &_value)
ResourceSkin * getByName(const std::string &_name) const
static const char * getClassTypeName()
bool isExist(const std::string &_name) const
delegates::DelegateFunction< Args... > * newDelegate(void(*_func)(Args... args))
MYGUI_SINGLETON_DEFINITION(ClipboardManager)