MyGUI 3.4.1
MyGUI_OverlappedLayer.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"
10#include "MyGUI_LayerNode.h"
11#include "MyGUI_RenderManager.h"
12
13namespace MyGUI
14{
15
17 mIsPick(false),
18 mOutOfDate(false)
19 {
21 }
22
24 {
25 if (!mChildItems.empty())
26 MYGUI_LOG(Critical, "Layer '" << getName() << "' must be empty before destroy");
27 }
28
30 {
31 mName = _node->findAttribute("name");
32 if (_version >= Version(1, 2))
33 {
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 setPick(utility::parseValue<bool>(value));
41 }
42 }
43 else if (_version >= Version(1, 0))
44 {
46 }
47 else
48 {
50 }
51 }
52
53 void OverlappedLayer::setPick(bool _pick)
54 {
55 mIsPick = _pick;
56 }
57
59 {
60 // создаем рутовый айтем
61 ILayerNode* node = new LayerNode(this);
62 mChildItems.push_back(node);
63
64 mOutOfDate = true;
65
66 return node;
67 }
68
70 {
71 // если есть отец, то русть сам и удаляет
72 ILayerNode* parent = _item->getParent();
73 if (parent)
74 {
75 parent->destroyChildItemNode(_item);
76
77 mOutOfDate = true;
78
79 return;
80 }
81
82 // айтем рутовый, мы удаляем
83 for (VectorILayerNode::iterator iter = mChildItems.begin(); iter != mChildItems.end(); ++iter)
84 {
85 if ((*iter) == _item)
86 {
87 delete _item;
88 mChildItems.erase(iter);
89
90 mOutOfDate = true;
91
92 return;
93 }
94 }
95
96 MYGUI_EXCEPT("item node not found");
97 }
98
100 {
101 // если есть отец, то пусть сам рулит
102 ILayerNode* parent = _item->getParent();
103 if (parent != nullptr)
104 {
105 parent->upChildItemNode(_item);
106
107 mOutOfDate = true;
108
109 return;
110 }
111
112 if ((2 > mChildItems.size()) || (mChildItems.back() == _item))
113 return;
114
115 for (VectorILayerNode::iterator iter = mChildItems.begin(); iter != mChildItems.end(); ++iter)
116 {
117 if ((*iter) == _item)
118 {
119 mChildItems.erase(iter);
120 mChildItems.push_back(_item);
121
122 mOutOfDate = true;
123
124 return;
125 }
126 }
127
128 MYGUI_EXCEPT("item node not found");
129 }
130
132 {
133 if (!mIsPick)
134 return nullptr;
135
136 VectorILayerNode::const_reverse_iterator iter = mChildItems.rbegin();
137 while (iter != mChildItems.rend())
138 {
139 ILayerItem* item = (*iter)->getLayerItemByPoint(_left, _top);
140 if (item != nullptr)
141 return item;
142 ++iter;
143 }
144 return nullptr;
145 }
146
147 IntPoint OverlappedLayer::getPosition(int _left, int _top) const
148 {
149 return IntPoint(_left, _top);
150 }
151
153 {
154 for (VectorILayerNode::iterator iter = mChildItems.begin(); iter != mChildItems.end(); ++iter)
155 (*iter)->renderToTarget(_target, _update);
156
157 mOutOfDate = false;
158 }
159
161 {
162 for (VectorILayerNode::iterator iter = mChildItems.begin(); iter != mChildItems.end(); ++iter)
163 (*iter)->resizeView(_viewSize);
164
165 mViewSize = _viewSize;
166 }
167
169 {
171 }
172
174 {
175 return mChildItems.size();
176 }
177
179 {
180 MYGUI_ASSERT_RANGE(_index, mChildItems.size(), "OverlappedLayer::getLayerNodeAt");
181
182 return mChildItems[_index];
183 }
184
186 {
187 return mViewSize;
188 }
189
191 {
192 for (VectorILayerNode::const_iterator iter = mChildItems.begin(); iter != mChildItems.end(); ++iter)
193 {
194 if (static_cast<const LayerNode*>(*iter)->isOutOfDate())
195 return true;
196 }
197
198 return mOutOfDate;
199 }
200
201} // namespace MyGUI
#define MYGUI_EXCEPT(dest)
#define MYGUI_ASSERT_RANGE(index, size, owner)
#define MYGUI_LOG(level, text)
const std::string & getName() const
Definition: MyGUI_ILayer.h:29
std::string mName
Definition: MyGUI_ILayer.h:67
virtual ILayerItem * getLayerItemByPoint(int _left, int _top) const =0
virtual ILayerNode * getParent() const =0
virtual void upChildItemNode(ILayerNode *_node)=0
virtual void destroyChildItemNode(ILayerNode *_node)=0
bool isOutOfDate() const
const IntSize & getSize() const override
void deserialization(xml::ElementPtr _node, Version _version) override
EnumeratorILayerNode getEnumerator() const override
void upChildItemNode(ILayerNode *_node) override
ILayerNode * getLayerNodeAt(size_t _index) const override
void resizeView(const IntSize &_viewSize) override
IntPoint getPosition(int _left, int _top) const override
ILayerItem * getLayerItemByPoint(int _left, int _top) const override
ILayerNode * createChildItemNode() override
void renderToTarget(IRenderTarget *_target, bool _update) override
void destroyChildItemNode(ILayerNode *_node) override
size_t getLayerNodeCount() const override
virtual const IntSize & getViewSize() const =0
static RenderManager & getInstance()
ElementEnumerator getElementEnumerator()
bool findAttribute(const std::string &_name, std::string &_value)
bool parseBool(const std::string &_value)
Enumerator< VectorILayerNode > EnumeratorILayerNode
types::TPoint< int > IntPoint
Definition: MyGUI_Types.h:26