MyGUI 3.4.3
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"
11#include "MyGUI_WidgetManager.h"
12
13namespace MyGUI
14{
15
17
19 mXmlLayoutTagName("Layout"),
20 mSingletonHolder(this)
21 {
22 }
23
25 {
26 MYGUI_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice");
27 MYGUI_LOG(Info, "* Initialise: " << getClassTypeName());
28
30 newDelegate(this, &LayoutManager::_load);
31
32 const std::string& resourceCategory = ResourceManager::getInstance().getCategoryName();
34
35 MYGUI_LOG(Info, getClassTypeName() << " successfully initialized");
36 mIsInitialise = true;
37 }
38
40 {
41 MYGUI_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised");
42 MYGUI_LOG(Info, "* Shutdown: " << getClassTypeName());
43
45
46 const std::string& resourceCategory = ResourceManager::getInstance().getCategoryName();
48
49 MYGUI_LOG(Info, getClassTypeName() << " successfully shutdown");
50 mIsInitialise = false;
51 }
52
53 void LayoutManager::_load(xml::ElementPtr _node, std::string_view _file, Version _version)
54 {
55 ResourceLayout* resource = new ResourceLayout(_node, _file);
57 }
58
59 VectorWidgetPtr LayoutManager::loadLayout(std::string_view _file, std::string_view _prefix, Widget* _parent)
60 {
61 mCurrentLayoutName = _file;
62
63 ResourceLayout* resource = getByName(_file, false);
64 if (!resource)
65 {
66 ResourceManager::getInstance().load(mCurrentLayoutName);
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.clear();
77
78 return result;
79 }
80
85
86 ResourceLayout* LayoutManager::getByName(std::string_view _name, bool _throw) const
87 {
88 std::string_view 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(std::string_view _name) const
111 {
112 return getByName(_name, false) != nullptr;
113 }
114
115} // namespace MyGUI
#define MYGUI_ASSERT(exp, dest)
#define MYGUI_LOG(level, text)
#define MYGUI_SINGLETON_DEFINITION(ClassName)
static std::string_view getSkinRename(std::string_view _skinName)
void registerFactory(std::string_view _category, std::string_view _type, Delegate::IDelegate *_delegate)
static FactoryManager & getInstance()
void unregisterFactory(std::string_view _category, std::string_view _type)
Type * castType(bool _throw=true)
void unloadLayout(VectorWidgetPtr &_widgets)
const std::string & getCurrentLayout() const
ResourceLayout * getByName(std::string_view _name, bool _throw=true) const
bool isExist(std::string_view _name) const
VectorWidgetPtr loadLayout(std::string_view _file, std::string_view _prefix={}, Widget *_parent=nullptr)
static std::string_view getClassTypeName()
VectorWidgetPtr createLayout(std::string_view _prefix={}, Widget *_parent=nullptr)
void unregisterLoadXmlDelegate(std::string_view _key)
const std::string & getCategoryName() const
LoadXmlDelegate & registerLoadXmlDelegate(std::string_view _key)
IResource * getByName(std::string_view _name, bool _throw=true) const
bool load(const std::string &_file)
static ResourceManager & getInstance()
void addResource(IResourcePtr _item)
widget description should be here.
void destroyWidgets(const VectorWidgetPtr &_widgets)
static WidgetManager & getInstance()
delegates::DelegateFunction< Args... > * newDelegate(void(*_func)(Args... args))
std::vector< Widget * > VectorWidgetPtr