MyGUI 3.2.0

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

- File List
- Globals

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
37 LayoutManager::LayoutManager() :
38 mIsInitialise(false)
39 {
40 }
41
42 void LayoutManager::initialise()
43 {
44 MYGUI_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice");
45 MYGUI_LOG(Info, "* Initialise: " << getClassTypeName());
46
47 ResourceManager::getInstance().registerLoadXmlDelegate(XML_TYPE) = newDelegate(this, &LayoutManager::_load);
48 FactoryManager::getInstance().registerFactory<ResourceLayout>(XML_TYPE_RESOURCE);
49
50 MYGUI_LOG(Info, getClassTypeName() << " successfully initialized");
51 mIsInitialise = true;
52 }
53
54 void LayoutManager::shutdown()
55 {
56 MYGUI_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised");
57 MYGUI_LOG(Info, "* Shutdown: " << getClassTypeName());
58
59 ResourceManager::getInstance().unregisterLoadXmlDelegate(XML_TYPE);
60 FactoryManager::getInstance().unregisterFactory<ResourceLayout>(XML_TYPE_RESOURCE);
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);
69 ResourceManager::getInstance().addResource(resource);
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 {
79 ResourceManager::getInstance().load(_file);
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
94 void LayoutManager::unloadLayout(VectorWidgetPtr& _widgets)
95 {
96 WidgetManager::getInstance().destroyWidgets(_widgets);
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
MyGUI::Widget
Definition: MyGUI_Widget.h:41
MyGUI_FactoryManager.h
MyGUI::ResourceManager::unregisterLoadXmlDelegate
void unregisterLoadXmlDelegate(const std::string &_key)
Definition: MyGUI_ResourceManager.cpp:142
MyGUI::LayoutManager::isExist
bool isExist(const std::string &_name) const
Definition: MyGUI_LayoutManager.cpp:123
MyGUI_Precompiled.h
MyGUI::LayoutManager::loadLayout
VectorWidgetPtr loadLayout(const std::string &_file, const std::string &_prefix="", Widget *_parent=0)
Definition: MyGUI_LayoutManager.cpp:72
MyGUI::ResourceManager::registerLoadXmlDelegate
LoadXmlDelegate & registerLoadXmlDelegate(const std::string &_key)
Definition: MyGUI_ResourceManager.cpp:135
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_WidgetManager.h
MyGUI::Singleton< LayoutManager >::getClassTypeName
static const char * getClassTypeName()
Definition: MyGUI_Singleton.h:64
MyGUI::LayoutManager::getByName
ResourceLayout * getByName(const std::string &_name, bool _throw=true) const
Definition: MyGUI_LayoutManager.cpp:99
MyGUI::XML_TYPE
const std::string XML_TYPE("Font")
MyGUI::WidgetManager::destroyWidgets
void destroyWidgets(const VectorWidgetPtr &_widgets)
Definition: MyGUI_WidgetManager.cpp:137
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_LOG
#define MYGUI_LOG(level, text)
Definition: MyGUI_Diagnostic.h:38
MyGUI_LayoutManager.h
MyGUI::ResourceLayout
Definition: MyGUI_ResourceLayout.h:33
MyGUI::ResourceLayout::createLayout
VectorWidgetPtr createLayout(const std::string &_prefix="", Widget *_parent=0)
Definition: MyGUI_ResourceLayout.cpp:116
MyGUI::ResourceManager::load
bool load(const std::string &_file)
Definition: MyGUI_ResourceManager.cpp:77
MyGUI::VectorWidgetPtr
std::vector< Widget * > VectorWidgetPtr
Definition: MyGUI_WidgetDefines.h:33
MYGUI_ASSERT
#define MYGUI_ASSERT(exp, dest)
Definition: MyGUI_Diagnostic.h:58
MyGUI::LayoutManager::unloadLayout
void unloadLayout(VectorWidgetPtr &_widgets)
Definition: MyGUI_LayoutManager.cpp:94
MyGUI::xml::Element
Definition: MyGUI_XmlDocument.h:168
MyGUI::LayoutManager::shutdown
void shutdown()
Definition: MyGUI_LayoutManager.cpp:54
MyGUI::IObject::castType
Type * castType(bool _throw=true)
Definition: MyGUI_IObject.h:33
MyGUI::Version
Definition: MyGUI_Version.h:32
MyGUI_ResourceManager.h
MyGUI::FactoryManager::unregisterFactory
void unregisterFactory(const std::string &_category, const std::string &_type)
Definition: MyGUI_FactoryManager.cpp:61
MyGUI::FactoryManager::registerFactory
void registerFactory(const std::string &_category, const std::string &_type, Delegate::IDelegate *_delegate)
Definition: MyGUI_FactoryManager.cpp:55
MyGUI::ResourceManager::addResource
void addResource(IResourcePtr _item)
Definition: MyGUI_ResourceManager.cpp:221
MyGUI::LayoutManager::getCurrentLayout
const std::string & getCurrentLayout() const
Definition: MyGUI_LayoutManager.cpp:118
MyGUI::IResource
Definition: MyGUI_IResource.h:38
MyGUI::Singleton::mClassTypeName
static const char * mClassTypeName
Definition: MyGUI_Singleton.h:73
MyGUI::LayoutManager::LayoutManager
LayoutManager()
Definition: MyGUI_LayoutManager.cpp:37
MyGUI::XML_TYPE_RESOURCE
const std::string XML_TYPE_RESOURCE("Resource")
MyGUI::LayoutManager::initialise
void initialise()
Definition: MyGUI_LayoutManager.cpp:42