MyGUI 3.5.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
13#include <pugixml.hpp>
14
15namespace MyGUI
16{
17
19
20 LayoutManager::LayoutManager() :
21 mSingletonHolder(this),
22 mXmlLayoutTagName("Layout")
23 {
24 }
25
26 void LayoutManager::initialise()
27 {
28 MYGUI_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice");
29 MYGUI_LOG(Info, "* Initialise: " << getClassTypeName());
30
31 ResourceManager::getInstance().registerLoadXmlDelegate(mXmlLayoutTagName) =
32 newDelegate(this, &LayoutManager::_load);
33
34 const std::string& resourceCategory = ResourceManager::getInstance().getCategoryName();
35 FactoryManager::getInstance().registerFactory<ResourceLayout>(resourceCategory);
36
37 MYGUI_LOG(Info, getClassTypeName() << " successfully initialized");
38 mIsInitialise = true;
39 }
40
41 void LayoutManager::shutdown()
42 {
43 MYGUI_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised");
44 MYGUI_LOG(Info, "* Shutdown: " << getClassTypeName());
45
46 ResourceManager::getInstance().unregisterLoadXmlDelegate(mXmlLayoutTagName);
47
48 const std::string& resourceCategory = ResourceManager::getInstance().getCategoryName();
49 FactoryManager::getInstance().unregisterFactory<ResourceLayout>(resourceCategory);
50
51 MYGUI_LOG(Info, getClassTypeName() << " successfully shutdown");
52 mIsInitialise = false;
53 }
54
55 void LayoutManager::_load(xml::ElementPtr _node, std::string_view _file, Version _version)
56 {
57 ResourceLayout* resource = new ResourceLayout(_node.node(), _file);
58 ResourceManager::getInstance().addResource(resource);
59 }
60
61 VectorWidgetPtr LayoutManager::loadLayout(std::string_view _file, std::string_view _prefix, Widget* _parent)
62 {
63 mCurrentLayoutName = _file;
64
65 ResourceLayout* resource = getByName(_file, false);
66 if (!resource)
67 {
68 ResourceManager::getInstance().load(mCurrentLayoutName);
69 resource = getByName(_file, false);
70 }
71
72 VectorWidgetPtr result;
73 if (resource)
74 result = resource->createLayout(_prefix, _parent);
75 else
76 MYGUI_LOG(Warning, "Layout '" << _file << "' couldn't be loaded");
77
78 mCurrentLayoutName.clear();
79
80 return result;
81 }
82
83 void LayoutManager::unloadLayout(VectorWidgetPtr& _widgets)
84 {
85 WidgetManager::getInstance().destroyWidgets(_widgets);
86 }
87
88 ResourceLayout* LayoutManager::getByName(std::string_view _name, bool _throw) const
89 {
90 std::string_view skinName = BackwardCompatibility::getSkinRename(_name);
91 IResource* result = ResourceManager::getInstance().getByName(skinName, false);
92
93 if (result != nullptr)
94 {
95 ResourceLayout* resource = result->castType<ResourceLayout>(false);
96 if (resource == nullptr)
97 {
98 MYGUI_ASSERT(!_throw, "Resource '" << skinName << "' is not ResourceLayout type");
99 }
100 return resource;
101 }
102
103 MYGUI_ASSERT(!_throw, "ResourceLayout '" << skinName << "' not found");
104 return nullptr;
105 }
106
107 const std::string& LayoutManager::getCurrentLayout() const
108 {
109 return mCurrentLayoutName;
110 }
111
112 bool LayoutManager::isExist(std::string_view _name) const
113 {
114 return getByName(_name, false) != nullptr;
115 }
116
117} // namespace MyGUI
#define MYGUI_ASSERT(exp, dest)
#define MYGUI_LOG(level, text)
std::vector< Widget * > VectorWidgetPtr
MYGUI_SINGLETON_DEFINITION(ClipboardManager)