MyGUI  3.2.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 
23  template <> SkinManager* Singleton<SkinManager>::msInstance = nullptr;
24  template <> const char* Singleton<SkinManager>::mClassTypeName = "SkinManager";
25 
27  mIsInitialise(false),
28  mXmlSkinTagName("Skin"),
29  mXmlDefaultSkinValue("Default")
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