MyGUI  3.2.0
MyGUI_LayoutManager.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_LayoutManager.h"
24 #include "MyGUI_ResourceManager.h"
25 #include "MyGUI_FactoryManager.h"
26 #include "MyGUI_WidgetManager.h"
27 
28 namespace MyGUI
29 {
30 
31  const std::string XML_TYPE("Layout");
32  const std::string XML_TYPE_RESOURCE("Resource");
33 
34  template <> LayoutManager* Singleton<LayoutManager>::msInstance = nullptr;
35  template <> const char* Singleton<LayoutManager>::mClassTypeName("LayoutManager");
36 
38  mIsInitialise(false)
39  {
40  }
41 
43  {
44  MYGUI_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice");
45  MYGUI_LOG(Info, "* Initialise: " << getClassTypeName());
46 
49 
50  MYGUI_LOG(Info, getClassTypeName() << " successfully initialized");
51  mIsInitialise = true;
52  }
53 
55  {
56  MYGUI_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised");
57  MYGUI_LOG(Info, "* Shutdown: " << getClassTypeName());
58 
61 
62  MYGUI_LOG(Info, getClassTypeName() << " successfully shutdown");
63  mIsInitialise = false;
64  }
65 
66  void LayoutManager::_load(xml::ElementPtr _node, const std::string& _file, Version _version)
67  {
68  ResourceLayout* resource = new ResourceLayout(_node, _file);
70  }
71 
72  VectorWidgetPtr LayoutManager::loadLayout(const std::string& _file, const std::string& _prefix, Widget* _parent)
73  {
74  mCurrentLayoutName = _file;
75 
76  ResourceLayout* resource = getByName(_file, false);
77  if (!resource)
78  {
80  resource = getByName(_file, false);
81  }
82 
83  VectorWidgetPtr result;
84  if (resource)
85  result = resource->createLayout(_prefix, _parent);
86  else
87  MYGUI_LOG(Warning, "Layout '" << _file << "' couldn't be loaded");
88 
89  mCurrentLayoutName = "";
90 
91  return result;
92  }
93 
95  {
97  }
98 
99  ResourceLayout* LayoutManager::getByName(const std::string& _name, bool _throw) const
100  {
101  std::string skinName = BackwardCompatibility::getSkinRename(_name);
102  IResource* result = ResourceManager::getInstance().getByName(skinName, false);
103 
104  if (result != nullptr)
105  {
106  ResourceLayout* resource = result->castType<ResourceLayout>(false);
107  if (resource == nullptr)
108  {
109  MYGUI_ASSERT(!_throw, "Resource '" << skinName << "' is not ResourceLayout type");
110  }
111  return resource;
112  }
113 
114  MYGUI_ASSERT(!_throw, "ResourceLayout '" << skinName << "' not found");
115  return nullptr;
116  }
117 
118  const std::string& LayoutManager::getCurrentLayout() const
119  {
120  return mCurrentLayoutName;
121  }
122 
123  bool LayoutManager::isExist(const std::string& _name) const
124  {
125  return getByName(_name, false) != nullptr;
126  }
127 
128 } // namespace MyGUI
void unregisterLoadXmlDelegate(const std::string &_key)
bool isExist(const std::string &_name) const
VectorWidgetPtr loadLayout(const std::string &_file, const std::string &_prefix="", Widget *_parent=0)
LoadXmlDelegate & registerLoadXmlDelegate(const std::string &_key)
delegates::IDelegate0 * newDelegate(void(*_func)())
static ResourceManager & getInstance()
static const char * getClassTypeName()
ResourceLayout * getByName(const std::string &_name, bool _throw=true) const
const std::string XML_TYPE("Font")
void destroyWidgets(const VectorWidgetPtr &_widgets)
static std::string getSkinRename(const std::string &_skinName)
IResource * getByName(const std::string &_name, bool _throw=true) const
#define MYGUI_LOG(level, text)
VectorWidgetPtr createLayout(const std::string &_prefix="", Widget *_parent=0)
bool load(const std::string &_file)
std::vector< Widget * > VectorWidgetPtr
#define MYGUI_ASSERT(exp, dest)
void unloadLayout(VectorWidgetPtr &_widgets)
Type * castType(bool _throw=true)
Definition: MyGUI_IObject.h:33
void unregisterFactory(const std::string &_category, const std::string &_type)
void registerFactory(const std::string &_category, const std::string &_type, Delegate::IDelegate *_delegate)
void addResource(IResourcePtr _item)
const std::string & getCurrentLayout() const
const std::string XML_TYPE_RESOURCE("Resource")