MyGUI
3.2.0
Main Page
Related Pages
Namespaces
Data Structures
Files
Examples
File List
Globals
MyGUIEngine
src
MyGUI_LayoutManager.cpp
Go to the documentation of this file.
1
6
/*
7
This file is part of MyGUI.
8
9
MyGUI is free software: you can redistribute it and/or modify
10
it under the terms of the GNU Lesser General Public License as published by
11
the Free Software Foundation, either version 3 of the License, or
12
(at your option) any later version.
13
14
MyGUI is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
GNU Lesser General Public License for more details.
18
19
You should have received a copy of the GNU Lesser General Public License
20
along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
21
*/
22
#include "
MyGUI_Precompiled.h
"
23
#include "
MyGUI_LayoutManager.h
"
24
#include "
MyGUI_ResourceManager.h
"
25
#include "
MyGUI_FactoryManager.h
"
26
#include "
MyGUI_WidgetManager.h
"
27
28
namespace
MyGUI
29
{
30
31
const
std::string
XML_TYPE
(
"Layout"
);
32
const
std::string
XML_TYPE_RESOURCE
(
"Resource"
);
33
34
template
<> LayoutManager* Singleton<LayoutManager>::msInstance =
nullptr
;
35
template
<>
const
char
*
Singleton<LayoutManager>::mClassTypeName
(
"LayoutManager"
);
36
37
LayoutManager::LayoutManager
() :
38
mIsInitialise(false)
39
{
40
}
41
42
void
LayoutManager::initialise
()
43
{
44
MYGUI_ASSERT
(!mIsInitialise,
getClassTypeName
() <<
" initialised twice"
);
45
MYGUI_LOG
(Info,
"* Initialise: "
<<
getClassTypeName
());
46
47
ResourceManager::getInstance
().
registerLoadXmlDelegate
(
XML_TYPE
) =
newDelegate
(
this
, &LayoutManager::_load);
48
FactoryManager::getInstance
().
registerFactory
<
ResourceLayout
>(
XML_TYPE_RESOURCE
);
49
50
MYGUI_LOG
(Info,
getClassTypeName
() <<
" successfully initialized"
);
51
mIsInitialise =
true
;
52
}
53
54
void
LayoutManager::shutdown
()
55
{
56
MYGUI_ASSERT
(mIsInitialise,
getClassTypeName
() <<
" is not initialised"
);
57
MYGUI_LOG
(Info,
"* Shutdown: "
<<
getClassTypeName
());
58
59
ResourceManager::getInstance
().
unregisterLoadXmlDelegate
(
XML_TYPE
);
60
FactoryManager::getInstance
().
unregisterFactory
<
ResourceLayout
>(
XML_TYPE_RESOURCE
);
61
62
MYGUI_LOG
(Info,
getClassTypeName
() <<
" successfully shutdown"
);
63
mIsInitialise =
false
;
64
}
65
66
void
LayoutManager::_load(
xml::ElementPtr
_node,
const
std::string& _file,
Version
_version)
67
{
68
ResourceLayout
* resource =
new
ResourceLayout
(_node, _file);
69
ResourceManager::getInstance
().
addResource
(resource);
70
}
71
72
VectorWidgetPtr
LayoutManager::loadLayout
(
const
std::string& _file,
const
std::string& _prefix,
Widget
* _parent)
73
{
74
mCurrentLayoutName = _file;
75
76
ResourceLayout
* resource =
getByName
(_file,
false
);
77
if
(!resource)
78
{
79
ResourceManager::getInstance
().
load
(_file);
80
resource =
getByName
(_file,
false
);
81
}
82
83
VectorWidgetPtr
result;
84
if
(resource)
85
result = resource->
createLayout
(_prefix, _parent);
86
else
87
MYGUI_LOG
(Warning,
"Layout '"
<< _file <<
"' couldn't be loaded"
);
88
89
mCurrentLayoutName =
""
;
90
91
return
result;
92
}
93
94
void
LayoutManager::unloadLayout
(
VectorWidgetPtr
& _widgets)
95
{
96
WidgetManager::getInstance
().
destroyWidgets
(_widgets);
97
}
98
99
ResourceLayout
*
LayoutManager::getByName
(
const
std::string& _name,
bool
_throw)
const
100
{
101
std::string skinName =
BackwardCompatibility::getSkinRename
(_name);
102
IResource
* result =
ResourceManager::getInstance
().
getByName
(skinName,
false
);
103
104
if
(result !=
nullptr
)
105
{
106
ResourceLayout
* resource = result->
castType
<
ResourceLayout
>(
false
);
107
if
(resource ==
nullptr
)
108
{
109
MYGUI_ASSERT
(!_throw,
"Resource '"
<< skinName <<
"' is not ResourceLayout type"
);
110
}
111
return
resource;
112
}
113
114
MYGUI_ASSERT
(!_throw,
"ResourceLayout '"
<< skinName <<
"' not found"
);
115
return
nullptr
;
116
}
117
118
const
std::string&
LayoutManager::getCurrentLayout
()
const
119
{
120
return
mCurrentLayoutName;
121
}
122
123
bool
LayoutManager::isExist
(
const
std::string& _name)
const
124
{
125
return
getByName
(_name,
false
) !=
nullptr
;
126
}
127
128
}
// namespace MyGUI
Generated by
1.8.4