MyGUI
3.2.1
|
00001 /* 00002 * This source file is part of MyGUI. For the latest info, see http://mygui.info/ 00003 * Distributed under the MIT License 00004 * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT) 00005 */ 00006 00007 #include "MyGUI_Precompiled.h" 00008 #include "MyGUI_LayoutManager.h" 00009 #include "MyGUI_ResourceManager.h" 00010 #include "MyGUI_FactoryManager.h" 00011 #include "MyGUI_WidgetManager.h" 00012 00013 namespace MyGUI 00014 { 00015 00016 template <> LayoutManager* Singleton<LayoutManager>::msInstance = nullptr; 00017 template <> const char* Singleton<LayoutManager>::mClassTypeName = "LayoutManager"; 00018 00019 LayoutManager::LayoutManager() : 00020 mIsInitialise(false), 00021 mXmlLayoutTagName("Layout") 00022 { 00023 } 00024 00025 void LayoutManager::initialise() 00026 { 00027 MYGUI_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice"); 00028 MYGUI_LOG(Info, "* Initialise: " << getClassTypeName()); 00029 00030 ResourceManager::getInstance().registerLoadXmlDelegate(mXmlLayoutTagName) = newDelegate(this, &LayoutManager::_load); 00031 00032 std::string resourceCategory = ResourceManager::getInstance().getCategoryName(); 00033 FactoryManager::getInstance().registerFactory<ResourceLayout>(resourceCategory); 00034 00035 MYGUI_LOG(Info, getClassTypeName() << " successfully initialized"); 00036 mIsInitialise = true; 00037 } 00038 00039 void LayoutManager::shutdown() 00040 { 00041 MYGUI_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised"); 00042 MYGUI_LOG(Info, "* Shutdown: " << getClassTypeName()); 00043 00044 ResourceManager::getInstance().unregisterLoadXmlDelegate(mXmlLayoutTagName); 00045 00046 std::string resourceCategory = ResourceManager::getInstance().getCategoryName(); 00047 FactoryManager::getInstance().unregisterFactory<ResourceLayout>(resourceCategory); 00048 00049 MYGUI_LOG(Info, getClassTypeName() << " successfully shutdown"); 00050 mIsInitialise = false; 00051 } 00052 00053 void LayoutManager::_load(xml::ElementPtr _node, const std::string& _file, Version _version) 00054 { 00055 ResourceLayout* resource = new ResourceLayout(_node, _file); 00056 ResourceManager::getInstance().addResource(resource); 00057 } 00058 00059 VectorWidgetPtr LayoutManager::loadLayout(const std::string& _file, const std::string& _prefix, Widget* _parent) 00060 { 00061 mCurrentLayoutName = _file; 00062 00063 ResourceLayout* resource = getByName(_file, false); 00064 if (!resource) 00065 { 00066 ResourceManager::getInstance().load(_file); 00067 resource = getByName(_file, false); 00068 } 00069 00070 VectorWidgetPtr result; 00071 if (resource) 00072 result = resource->createLayout(_prefix, _parent); 00073 else 00074 MYGUI_LOG(Warning, "Layout '" << _file << "' couldn't be loaded"); 00075 00076 mCurrentLayoutName = ""; 00077 00078 return result; 00079 } 00080 00081 void LayoutManager::unloadLayout(VectorWidgetPtr& _widgets) 00082 { 00083 WidgetManager::getInstance().destroyWidgets(_widgets); 00084 } 00085 00086 ResourceLayout* LayoutManager::getByName(const std::string& _name, bool _throw) const 00087 { 00088 std::string skinName = BackwardCompatibility::getSkinRename(_name); 00089 IResource* result = ResourceManager::getInstance().getByName(skinName, false); 00090 00091 if (result != nullptr) 00092 { 00093 ResourceLayout* resource = result->castType<ResourceLayout>(false); 00094 if (resource == nullptr) 00095 { 00096 MYGUI_ASSERT(!_throw, "Resource '" << skinName << "' is not ResourceLayout type"); 00097 } 00098 return resource; 00099 } 00100 00101 MYGUI_ASSERT(!_throw, "ResourceLayout '" << skinName << "' not found"); 00102 return nullptr; 00103 } 00104 00105 const std::string& LayoutManager::getCurrentLayout() const 00106 { 00107 return mCurrentLayoutName; 00108 } 00109 00110 bool LayoutManager::isExist(const std::string& _name) const 00111 { 00112 return getByName(_name, false) != nullptr; 00113 } 00114 00115 } // namespace MyGUI