MyGUI: MyGUI_LayoutManager.cpp Source File

MyGUI 3.4.2

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

- File List
- Globals

MyGUI_LayoutManager.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_LayoutManager.h"
9#include "MyGUI_ResourceManager.h"
10#include "MyGUI_FactoryManager.h"
11#include "MyGUI_WidgetManager.h"
12
13namespace MyGUI
14{
15
16 MYGUI_SINGLETON_DEFINITION(LayoutManager);
17
18 LayoutManager::LayoutManager() :
19 mIsInitialise(false),
20 mXmlLayoutTagName("Layout"),
21 mSingletonHolder(this)
22 {
23 }
24
25 void LayoutManager::initialise()
26 {
27 MYGUI_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice");
28 MYGUI_LOG(Info, "* Initialise: " << getClassTypeName());
29
30 ResourceManager::getInstance().registerLoadXmlDelegate(mXmlLayoutTagName) = newDelegate(this, &LayoutManager::_load);
31
32 std::string resourceCategory = ResourceManager::getInstance().getCategoryName();
33 FactoryManager::getInstance().registerFactory<ResourceLayout>(resourceCategory);
34
35 MYGUI_LOG(Info, getClassTypeName() << " successfully initialized");
36 mIsInitialise = true;
37 }
38
39 void LayoutManager::shutdown()
40 {
41 MYGUI_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised");
42 MYGUI_LOG(Info, "* Shutdown: " << getClassTypeName());
43
44 ResourceManager::getInstance().unregisterLoadXmlDelegate(mXmlLayoutTagName);
45
46 std::string resourceCategory = ResourceManager::getInstance().getCategoryName();
47 FactoryManager::getInstance().unregisterFactory<ResourceLayout>(resourceCategory);
48
49 MYGUI_LOG(Info, getClassTypeName() << " successfully shutdown");
50 mIsInitialise = false;
51 }
52
53 void LayoutManager::_load(xml::ElementPtr _node, const std::string& _file, Version _version)
54 {
55 ResourceLayout* resource = new ResourceLayout(_node, _file);
56 ResourceManager::getInstance().addResource(resource);
57 }
58
59 VectorWidgetPtr LayoutManager::loadLayout(const std::string& _file, const std::string& _prefix, Widget* _parent)
60 {
61 mCurrentLayoutName = _file;
62
63 ResourceLayout* resource = getByName(_file, false);
64 if (!resource)
65 {
66 ResourceManager::getInstance().load(_file);
67 resource = getByName(_file, false);
68 }
69
70 VectorWidgetPtr result;
71 if (resource)
72 result = resource->createLayout(_prefix, _parent);
73 else
74 MYGUI_LOG(Warning, "Layout '" << _file << "' couldn't be loaded");
75
76 mCurrentLayoutName = "";
77
78 return result;
79 }
80
81 void LayoutManager::unloadLayout(VectorWidgetPtr& _widgets)
82 {
83 WidgetManager::getInstance().destroyWidgets(_widgets);
84 }
85
86 ResourceLayout* LayoutManager::getByName(const std::string& _name, bool _throw) const
87 {
88 std::string skinName = BackwardCompatibility::getSkinRename(_name);
89 IResource* result = ResourceManager::getInstance().getByName(skinName, false);
90
91 if (result != nullptr)
92 {
93 ResourceLayout* resource = result->castType<ResourceLayout>(false);
94 if (resource == nullptr)
95 {
96 MYGUI_ASSERT(!_throw, "Resource '" << skinName << "' is not ResourceLayout type");
97 }
98 return resource;
99 }
100
101 MYGUI_ASSERT(!_throw, "ResourceLayout '" << skinName << "' not found");
102 return nullptr;
103 }
104
105 const std::string& LayoutManager::getCurrentLayout() const
106 {
107 return mCurrentLayoutName;
108 }
109
110 bool LayoutManager::isExist(const std::string& _name) const
111 {
112 return getByName(_name, false) != nullptr;
113 }
114
115} // namespace MyGUI
MYGUI_ASSERT
#define MYGUI_ASSERT(exp, dest)
Definition MyGUI_Diagnostic.h:29
MYGUI_LOG
#define MYGUI_LOG(level, text)
Definition MyGUI_Diagnostic.h:17
MyGUI_FactoryManager.h
MyGUI_LayoutManager.h
MyGUI_Precompiled.h
MyGUI_ResourceManager.h
MYGUI_SINGLETON_DEFINITION
#define MYGUI_SINGLETON_DEFINITION(ClassName)
Definition MyGUI_Singleton.h:123
MyGUI_WidgetManager.h
MyGUI::BackwardCompatibility::getSkinRename
static std::string getSkinRename(const std::string &_skinName)
Definition MyGUI_BackwardCompatibility.cpp:1342
MyGUI::FactoryManager::unregisterFactory
void unregisterFactory(const std::string &_category, const std::string &_type)
Definition MyGUI_FactoryManager.cpp:46
MyGUI::FactoryManager::getInstance
static FactoryManager & getInstance()
MyGUI::FactoryManager::registerFactory
void registerFactory(const std::string &_category, const std::string &_type, Delegate::IDelegate *_delegate)
Definition MyGUI_FactoryManager.cpp:40
MyGUI::IObject::castType
Type * castType(bool _throw=true)
Definition MyGUI_IObject.h:18
MyGUI::IResource
Definition MyGUI_IResource.h:25
MyGUI::LayoutManager
Definition MyGUI_LayoutManager.h:25
MyGUI::LayoutManager::unloadLayout
void unloadLayout(VectorWidgetPtr &_widgets)
Definition MyGUI_LayoutManager.cpp:81
MyGUI::LayoutManager::loadLayout
VectorWidgetPtr loadLayout(const std::string &_file, const std::string &_prefix="", Widget *_parent=nullptr)
Definition MyGUI_LayoutManager.cpp:59
MyGUI::LayoutManager::getCurrentLayout
const std::string & getCurrentLayout() const
Definition MyGUI_LayoutManager.cpp:105
MyGUI::LayoutManager::isExist
bool isExist(const std::string &_name) const
Definition MyGUI_LayoutManager.cpp:110
MyGUI::LayoutManager::initialise
void initialise()
Definition MyGUI_LayoutManager.cpp:25
MyGUI::LayoutManager::getClassTypeName
static const char * getClassTypeName()
MyGUI::LayoutManager::getByName
ResourceLayout * getByName(const std::string &_name, bool _throw=true) const
Definition MyGUI_LayoutManager.cpp:86
MyGUI::LayoutManager::LayoutManager
LayoutManager()
Definition MyGUI_LayoutManager.cpp:18
MyGUI::LayoutManager::shutdown
void shutdown()
Definition MyGUI_LayoutManager.cpp:39
MyGUI::ResourceLayout
Definition MyGUI_ResourceLayout.h:20
MyGUI::ResourceLayout::createLayout
VectorWidgetPtr createLayout(const std::string &_prefix="", Widget *_parent=nullptr)
Definition MyGUI_ResourceLayout.cpp:101
MyGUI::ResourceManager::getCategoryName
const std::string & getCategoryName() const
Definition MyGUI_ResourceManager.cpp:275
MyGUI::ResourceManager::getByName
IResource * getByName(const std::string &_name, bool _throw=true) const
Definition MyGUI_ResourceManager.cpp:235
MyGUI::ResourceManager::load
bool load(const std::string &_file)
Definition MyGUI_ResourceManager.cpp:61
MyGUI::ResourceManager::unregisterLoadXmlDelegate
void unregisterLoadXmlDelegate(const std::string &_key)
Definition MyGUI_ResourceManager.cpp:126
MyGUI::ResourceManager::getInstance
static ResourceManager & getInstance()
MyGUI::ResourceManager::registerLoadXmlDelegate
LoadXmlDelegate & registerLoadXmlDelegate(const std::string &_key)
Definition MyGUI_ResourceManager.cpp:119
MyGUI::ResourceManager::addResource
void addResource(IResourcePtr _item)
Definition MyGUI_ResourceManager.cpp:205
MyGUI::Version
Definition MyGUI_Version.h:18
MyGUI::Widget
widget description should be here.
Definition MyGUI_Widget.h:37
MyGUI::WidgetManager::destroyWidgets
void destroyWidgets(const VectorWidgetPtr &_widgets)
Definition MyGUI_WidgetManager.cpp:123
MyGUI::WidgetManager::getInstance
static WidgetManager & getInstance()
MyGUI::xml::Element
Definition MyGUI_XmlDocument.h:159
MyGUI
Definition MyGUI_ActionController.h:15
MyGUI::newDelegate
delegates::DelegateFunction< Args... > * newDelegate(void(*_func)(Args... args))
Definition MyGUI_Delegate.h:99
MyGUI::VectorWidgetPtr
std::vector< Widget * > VectorWidgetPtr
Definition MyGUI_WidgetDefines.h:20