20 LayoutManager::LayoutManager() :
21 mSingletonHolder(this),
22 mXmlLayoutTagName(
"Layout")
26 void LayoutManager::initialise()
28 MYGUI_ASSERT(!mIsInitialise, getClassTypeName() <<
" initialised twice");
29 MYGUI_LOG(Info,
"* Initialise: " << getClassTypeName());
31 ResourceManager::getInstance().registerLoadXmlDelegate(mXmlLayoutTagName) =
32 newDelegate(
this, &LayoutManager::_load);
34 const std::string& resourceCategory = ResourceManager::getInstance().getCategoryName();
35 FactoryManager::getInstance().registerFactory<ResourceLayout>(resourceCategory);
37 MYGUI_LOG(Info, getClassTypeName() <<
" successfully initialized");
41 void LayoutManager::shutdown()
43 MYGUI_ASSERT(mIsInitialise, getClassTypeName() <<
" is not initialised");
44 MYGUI_LOG(Info,
"* Shutdown: " << getClassTypeName());
46 ResourceManager::getInstance().unregisterLoadXmlDelegate(mXmlLayoutTagName);
48 const std::string& resourceCategory = ResourceManager::getInstance().getCategoryName();
49 FactoryManager::getInstance().unregisterFactory<ResourceLayout>(resourceCategory);
51 MYGUI_LOG(Info, getClassTypeName() <<
" successfully shutdown");
52 mIsInitialise =
false;
55 void LayoutManager::_load(xml::ElementPtr _node, std::string_view _file, Version _version)
57 ResourceLayout* resource =
new ResourceLayout(_node.node(), _file);
58 ResourceManager::getInstance().addResource(resource);
61 VectorWidgetPtr LayoutManager::loadLayout(std::string_view _file, std::string_view _prefix, Widget* _parent)
63 mCurrentLayoutName = _file;
65 ResourceLayout* resource = getByName(_file,
false);
68 ResourceManager::getInstance().load(mCurrentLayoutName);
69 resource = getByName(_file,
false);
74 result = resource->createLayout(_prefix, _parent);
76 MYGUI_LOG(Warning,
"Layout '" << _file <<
"' couldn't be loaded");
78 mCurrentLayoutName.clear();
83 void LayoutManager::unloadLayout(VectorWidgetPtr& _widgets)
85 WidgetManager::getInstance().destroyWidgets(_widgets);
88 ResourceLayout* LayoutManager::getByName(std::string_view _name,
bool _throw)
const
90 std::string_view skinName = BackwardCompatibility::getSkinRename(_name);
91 IResource* result = ResourceManager::getInstance().getByName(skinName,
false);
93 if (result !=
nullptr)
95 ResourceLayout* resource = result->castType<ResourceLayout>(
false);
96 if (resource ==
nullptr)
98 MYGUI_ASSERT(!_throw,
"Resource '" << skinName <<
"' is not ResourceLayout type");
103 MYGUI_ASSERT(!_throw,
"ResourceLayout '" << skinName <<
"' not found");
107 const std::string& LayoutManager::getCurrentLayout()
const
109 return mCurrentLayoutName;
112 bool LayoutManager::isExist(std::string_view _name)
const
114 return getByName(_name,
false) !=
nullptr;
#define MYGUI_ASSERT(exp, dest)
#define MYGUI_LOG(level, text)
std::vector< Widget * > VectorWidgetPtr
MYGUI_SINGLETON_DEFINITION(ClipboardManager)