MyGUI 3.4.1
MyGUI_LayerNode.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_LayerNode.h"
9#include "MyGUI_ILayerItem.h"
10#include "MyGUI_ITexture.h"
11#include "MyGUI_ISubWidget.h"
13
14namespace MyGUI
15{
16
18 mLastNotEmptyItem(0),
19 mParent(_parent),
20 mLayer(_layer),
21 mOutOfDate(false),
22 mOutOfDateCompression(false),
23 mDepth(0.0f)
24 {
25 }
26
28 {
29 for (VectorRenderItem::iterator iter = mFirstRenderItems.begin(); iter != mFirstRenderItems.end(); ++iter)
30 delete (*iter);
31 mFirstRenderItems.clear();
32
33 for (VectorRenderItem::iterator iter = mSecondRenderItems.begin(); iter != mSecondRenderItems.end(); ++iter)
34 delete (*iter);
35 mSecondRenderItems.clear();
36
37 for (VectorILayerNode::iterator iter = mChildItems.begin(); iter != mChildItems.end(); ++iter)
38 delete (*iter);
39 mChildItems.clear();
40 }
41
43 {
44 LayerNode* layer = new LayerNode(mLayer, this);
45 mChildItems.push_back(layer);
46
47 mOutOfDate = true;
48
49 return layer;
50 }
51
53 {
54 for (VectorILayerNode::iterator iter = mChildItems.begin(); iter != mChildItems.end(); ++iter)
55 {
56 if ((*iter) == _node)
57 {
58 delete _node;
59 mChildItems.erase(iter);
60
61 mOutOfDate = true;
62
63 return;
64 }
65 }
66 MYGUI_EXCEPT("item node not found");
67 }
68
70 {
71 for (VectorILayerNode::iterator iter = mChildItems.begin(); iter != mChildItems.end(); ++iter)
72 {
73 if ((*iter) == _item)
74 {
75 mChildItems.erase(iter);
76 mChildItems.push_back(_item);
77
78 mOutOfDate = true;
79
80 return;
81 }
82 }
83 MYGUI_EXCEPT("item node not found");
84 }
85
86 void LayerNode::renderToTarget(IRenderTarget* _target, bool _update)
87 {
88 mDepth = _target->getInfo().maximumDepth;
89
91 {
94 }
95
96 // сначала отрисовываем свое
97 for (VectorRenderItem::iterator iter = mFirstRenderItems.begin(); iter != mFirstRenderItems.end(); ++iter)
98 (*iter)->renderToTarget(_target, _update);
99
100 for (VectorRenderItem::iterator iter = mSecondRenderItems.begin(); iter != mSecondRenderItems.end(); ++iter)
101 (*iter)->renderToTarget(_target, _update);
102
103 // теперь отрисовываем дочерние узлы
104 for (VectorILayerNode::iterator iter = mChildItems.begin(); iter != mChildItems.end(); ++iter)
105 (*iter)->renderToTarget(_target, _update);
106
107 mOutOfDate = false;
108 }
109
110 void LayerNode::resizeView(const IntSize& _viewSize)
111 {
112 IntSize oldSize = mLayer->getSize();
113
114 for (VectorLayerItem::const_iterator iter = mLayerItems.begin(); iter != mLayerItems.end(); ++iter)
115 (*iter)->resizeLayerItemView(oldSize, _viewSize);
116 }
117
118 ILayerItem* LayerNode::getLayerItemByPoint(int _left, int _top) const
119 {
120 // сначала пикаем детей
121 for (VectorILayerNode::const_iterator iter = mChildItems.begin(); iter != mChildItems.end(); ++iter)
122 {
123 ILayerItem* item = (*iter)->getLayerItemByPoint(_left, _top);
124 if (nullptr != item)
125 return item;
126 }
127
128 for (VectorLayerItem::const_iterator iter = mLayerItems.begin(); iter != mLayerItems.end(); ++iter)
129 {
130 ILayerItem* item = (*iter)->getLayerItemByPoint(_left, _top);
131 if (nullptr != item)
132 return item;
133 }
134
135 return nullptr;
136 }
137
138 RenderItem* LayerNode::addToRenderItem(ITexture* _texture, bool _firstQueue, bool _manualRender)
139 {
140 RenderItem* item = nullptr;
141 if (_firstQueue)
142 item = addToRenderItemFirstQueue(_texture, _manualRender);
143 else
144 item = addToRenderItemSecondQueue(_texture, _manualRender);
145
146 mOutOfDate = false;
147 return item;
148 }
149
151 {
152 if (mFirstRenderItems.empty() || _manualRender)
153 {
154 RenderItem* item = new RenderItem();
155 item->setTexture(_texture);
156 item->setManualRender(_manualRender);
158 mFirstRenderItems.push_back(item);
159
160 return item;
161 }
162
164 mOutOfDate = true;
165
166 // first queue keep order
167
168 // use either last non-empty buffer if it have same texture
169 // or empty buffer (if found in the end)
171 {
173 if (!item->getManualRender() && item->getTexture() == _texture)
174 {
175 return item;
176 }
177 }
178
179 if (mLastNotEmptyItem + 1 < mFirstRenderItems.size())
180 {
182 mFirstRenderItems[mLastNotEmptyItem]->setTexture(_texture);
184 }
185
186 // not found, create new
187 RenderItem* item = new RenderItem();
188 item->setTexture(_texture);
189 item->setManualRender(_manualRender);
191 mFirstRenderItems.push_back(item);
192
193 return item;
194 }
195
197 {
198 // order is not important in second queue
199 // use first buffer with same texture or empty buffer
200 for (VectorRenderItem::iterator iter = mSecondRenderItems.begin(); iter != mSecondRenderItems.end(); ++iter)
201 {
202 if ((*iter)->getTexture() == _texture)
203 {
204 return (*iter);
205 }
206 else if ((*iter)->getNeedVertexCount() == 0)
207 {
208 (*iter)->setTexture(_texture);
209
210 return (*iter);
211 }
212 }
213
214 // not found, create new
215 RenderItem* item = new RenderItem();
216 item->setTexture(_texture);
217 item->setManualRender(_manualRender);
218 mSecondRenderItems.push_back(item);
219
220 return item;
221 }
222
224 {
225 mLayerItems.push_back(_item);
226 _item->attachItemToNode(mLayer, this);
227
228 mOutOfDate = true;
229 }
230
232 {
233 for (VectorLayerItem::iterator iter = mLayerItems.begin(); iter != mLayerItems.end(); ++iter)
234 {
235 if ((*iter) == _item)
236 {
237 mLayerItems.erase(iter);
238
239 mOutOfDate = true;
240
241 return;
242 }
243 }
244 MYGUI_EXCEPT("layer item not found");
245 }
246
248 {
249 mOutOfDate = true;
250 if (_item)
251 _item->outOfDate();
252 }
253
255 {
257 }
258
260 {
261 return mChildItems.size();
262 }
263
265 {
266 MYGUI_ASSERT_RANGE(_index, mChildItems.size(), "LayerNode::getLayerNodeAt");
267
268 return mChildItems[_index];
269 }
270
272 {
273 if (mFirstRenderItems.size() <= 1)
274 return;
275
276 bool need_compression = false;
277 for (VectorRenderItem::iterator iter = mFirstRenderItems.begin(); iter != mFirstRenderItems.end(); ++iter)
278 {
279 if ((*iter)->getNeedCompression())
280 {
281 need_compression = true;
282 break;
283 }
284 }
285
286 if (!need_compression)
287 {
289 }
290 else
291 {
292 // pushing all empty buffers to the end of buffers list
293 VectorRenderItem nonEmptyItems;
294 nonEmptyItems.reserve(mFirstRenderItems.size());
295 VectorRenderItem emptyItems;
296
297 for (VectorRenderItem::const_iterator iter = mFirstRenderItems.begin(); iter != mFirstRenderItems.end(); ++iter)
298 {
299 (*iter)->setNeedCompression(false);
300
301 if ((*iter)->getNeedVertexCount() == 0 && !(*iter)->getManualRender())
302 emptyItems.push_back(*iter);
303 else
304 nonEmptyItems.push_back(*iter);
305 }
306 mLastNotEmptyItem = nonEmptyItems.size() - 1;
307 nonEmptyItems.insert(nonEmptyItems.end(), emptyItems.begin(), emptyItems.end());
308 std::swap(mFirstRenderItems, nonEmptyItems);
309 }
310 }
311
313 {
314 return mLayer;
315 }
316
318 {
319 return mParent;
320 }
321
323 {
324 for (VectorRenderItem::const_iterator item = mFirstRenderItems.begin(); item != mFirstRenderItems.end(); ++item)
325 {
326 if ((*item)->isOutOfDate())
327 return true;
328 }
329
330 for (VectorRenderItem::const_iterator item = mSecondRenderItems.begin(); item != mSecondRenderItems.end(); ++item)
331 {
332 if ((*item)->isOutOfDate())
333 return true;
334 }
335
336 for (VectorILayerNode::const_iterator item = mChildItems.begin(); item != mChildItems.end(); ++item)
337 {
338 if (static_cast<const LayerNode*>(*item)->isOutOfDate())
339 return true;
340 }
341
342 return mOutOfDate;
343 }
344
346 {
347 return mDepth;
348 }
349
350} // namespace MyGUI
#define MYGUI_EXCEPT(dest)
#define MYGUI_ASSERT_RANGE(index, size, owner)
virtual const IntSize & getSize() const =0
virtual void attachItemToNode(ILayer *_layer, ILayerNode *_node)=0
virtual ILayerItem * getLayerItemByPoint(int _left, int _top) const =0
virtual const RenderTargetInfo & getInfo() const =0
float getNodeDepth() const override
bool isOutOfDate() const
ILayerNode * getParent() const override
VectorRenderItem mSecondRenderItems
ILayerNode * createChildItemNode() override
VectorLayerItem mLayerItems
ILayer * getLayer() const override
size_t getLayerNodeCount() const override
void attachLayerItem(ILayerItem *_item) override
void detachLayerItem(ILayerItem *_item) override
void destroyChildItemNode(ILayerNode *_node) override
VectorRenderItem mFirstRenderItems
ILayerNode * mParent
void upChildItemNode(ILayerNode *_node) override
EnumeratorILayerNode getEnumerator() const override
void renderToTarget(IRenderTarget *_target, bool _update) override
void resizeView(const IntSize &_viewSize) override
RenderItem * addToRenderItem(ITexture *_texture, bool _firstQueue, bool _manualRender) override
VectorILayerNode mChildItems
ILayerItem * getLayerItemByPoint(int _left, int _top) const override
void outOfDate(RenderItem *_item) override
RenderItem * addToRenderItemFirstQueue(ITexture *_texture, bool _manualRender)
LayerNode(ILayer *_layer, ILayerNode *_parent=nullptr)
RenderItem * addToRenderItemSecondQueue(ITexture *_texture, bool _manualRender)
ILayerNode * getLayerNodeAt(size_t _index) const override
void setManualRender(bool _value)
void setTexture(ITexture *_value)
bool getManualRender() const
ITexture * getTexture() const
std::vector< RenderItem * > VectorRenderItem
Enumerator< VectorILayerNode > EnumeratorILayerNode