MyGUI
3.2.1
Main Page
Related Pages
Namespaces
Data Structures
Files
Examples
File List
Globals
mygui
MyGUIEngine
src
MyGUI_SharedLayer.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
"
8
#include "
MyGUI_LayerItem.h
"
9
#include "
MyGUI_SharedLayer.h
"
10
#include "
MyGUI_LayerNode.h
"
11
#include "
MyGUI_RenderManager.h
"
12
13
namespace
MyGUI
14
{
15
16
SharedLayer::SharedLayer
() :
17
mIsPick(false),
18
mChildItem(
nullptr
),
19
mOutOfDate(false)
20
{
21
mViewSize
=
RenderManager::getInstance
().
getViewSize
();
22
}
23
24
SharedLayer::~SharedLayer
()
25
{
26
MYGUI_ASSERT
(
mChildItem
==
nullptr
,
"Layer '"
<<
getName
() <<
"' must be empty before destroy"
);
27
}
28
29
void
SharedLayer::deserialization
(
xml::ElementPtr
_node,
Version
_version)
30
{
31
mName
= _node->
findAttribute
(
"name"
);
32
if
(_version >=
Version
(1, 2))
33
{
34
MyGUI::xml::ElementEnumerator
propert = _node->
getElementEnumerator
();
35
while
(propert.
next
(
"Property"
))
36
{
37
const
std::string& key = propert->
findAttribute
(
"key"
);
38
const
std::string& value = propert->
findAttribute
(
"value"
);
39
if
(key ==
"Pick"
)
40
mIsPick
= utility::parseValue<bool>(value);
41
}
42
}
43
else
if
(_version >=
Version
(1, 0))
44
{
45
mIsPick
=
utility::parseBool
(_node->
findAttribute
(
"pick"
));
46
}
47
else
48
{
49
mIsPick
=
utility::parseBool
(_node->
findAttribute
(
"peek"
));
50
}
51
}
52
53
ILayerNode
*
SharedLayer::createChildItemNode
()
54
{
55
if
(
mChildItem
==
nullptr
)
56
mChildItem
=
new
SharedLayerNode
(
this
);
57
58
mChildItem
->
addUsing
();
59
60
mOutOfDate
=
true
;
61
62
return
mChildItem
;
63
}
64
65
void
SharedLayer::destroyChildItemNode
(
ILayerNode
* _item)
66
{
67
// айтем рутовый, мы удаляем
68
if
(
mChildItem
== _item)
69
{
70
mChildItem
->
removeUsing
();
71
if
(0 ==
mChildItem
->
countUsing
())
72
{
73
delete
mChildItem
;
74
mChildItem
=
nullptr
;
75
}
76
77
mOutOfDate
=
true
;
78
79
return
;
80
}
81
//MYGUI_EXCEPT("item node not found");
82
}
83
84
void
SharedLayer::upChildItemNode
(
ILayerNode
* _item)
85
{
86
// если есть отец, то пусть сам рулит
87
ILayerNode
* parent = _item->
getParent
();
88
if
(parent !=
nullptr
)
89
parent->
upChildItemNode
(_item);
90
91
mOutOfDate
=
true
;
92
}
93
94
ILayerItem
*
SharedLayer::getLayerItemByPoint
(
int
_left,
int
_top)
const
95
{
96
if
(!
mIsPick
)
97
return
nullptr
;
98
99
if
(
mChildItem
!=
nullptr
)
100
{
101
ILayerItem
* item =
mChildItem
->
getLayerItemByPoint
(_left, _top);
102
if
(item !=
nullptr
)
103
return
item;
104
}
105
return
nullptr
;
106
}
107
108
IntPoint
SharedLayer::getPosition
(
int
_left,
int
_top)
const
109
{
110
return
IntPoint
(_left, _top);
111
}
112
113
void
SharedLayer::renderToTarget
(
IRenderTarget
* _target,
bool
_update)
114
{
115
if
(
mChildItem
!=
nullptr
)
116
mChildItem
->
renderToTarget
(_target, _update);
117
118
mOutOfDate
=
false
;
119
}
120
121
void
SharedLayer::resizeView
(
const
IntSize
& _viewSize)
122
{
123
if
(
mChildItem
!=
nullptr
)
124
mChildItem
->
resizeView
(_viewSize);
125
126
mViewSize
= _viewSize;
127
}
128
129
EnumeratorILayerNode
SharedLayer::getEnumerator
()
const
130
{
131
static
VectorILayerNode
nodes;
132
if
(
mChildItem
==
nullptr
)
133
{
134
nodes.clear();
135
}
136
else
137
{
138
if
(nodes.empty())
139
nodes.push_back(
mChildItem
);
140
else
141
nodes[0] =
mChildItem
;
142
}
143
144
return
EnumeratorILayerNode
(nodes);
145
}
146
147
size_t
SharedLayer::getLayerNodeCount
()
const
148
{
149
return
mChildItem
==
nullptr
? 0 : 1;
150
}
151
152
ILayerNode
*
SharedLayer::getLayerNodeAt
(
size_t
_index)
const
153
{
154
size_t
count =
getLayerNodeCount
();
155
MYGUI_ASSERT_RANGE
(_index, count,
"SharedLayer::getLayerNodeAt"
);
156
157
return
mChildItem
;
158
}
159
160
const
IntSize
&
SharedLayer::getSize
()
const
161
{
162
return
mViewSize
;
163
}
164
165
bool
SharedLayer::isOutOfDate
()
const
166
{
167
if
(
mChildItem
->
isOutOfDate
())
168
return
true
;
169
170
return
mOutOfDate
;
171
}
172
173
}
// namespace MyGUI
Generated on Wed Aug 20 2014 00:03:33 for MyGUI by
1.8.3.1