MyGUI: MyGUI_LayerNode.cpp Source File

MyGUI 3.4.2

- Main Page
- Related Pages
- Namespaces
- Data Structures
- Files
- Examples

- File List
- Globals

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"
12#include "MyGUI_ISubWidgetText.h"
13
14namespace MyGUI
15{
16
17 LayerNode::LayerNode(ILayer* _layer, ILayerNode* _parent) :
18 mLastNotEmptyItem(0),
19 mParent(_parent),
20 mLayer(_layer),
21 mOutOfDate(false),
22 mOutOfDateCompression(false),
23 mDepth(0.0f)
24 {
25 }
26
27 LayerNode::~LayerNode()
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
42 ILayerNode* LayerNode::createChildItemNode()
43 {
44 LayerNode* layer = new LayerNode(mLayer, this);
45 mChildItems.push_back(layer);
46
47 mOutOfDate = true;
48
49 return layer;
50 }
51
52 void LayerNode::destroyChildItemNode(ILayerNode* _node)
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
69 void LayerNode::upChildItemNode(ILayerNode* _item)
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
90 if (mOutOfDateCompression)
91 {
92 updateCompression();
93 mOutOfDateCompression = false;
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
150 RenderItem* LayerNode::addToRenderItemFirstQueue(ITexture* _texture, bool _manualRender)
151 {
152 if (mFirstRenderItems.empty() || _manualRender)
153 {
154 RenderItem* item = new RenderItem();
155 item->setTexture(_texture);
156 item->setManualRender(_manualRender);
157 mLastNotEmptyItem = mFirstRenderItems.size();
158 mFirstRenderItems.push_back(item);
159
160 return item;
161 }
162
163 mOutOfDateCompression = true;
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)
170 if (mLastNotEmptyItem < mFirstRenderItems.size())
171 {
172 RenderItem* item = mFirstRenderItems[mLastNotEmptyItem];
173 if (!item->getManualRender() && item->getTexture() == _texture)
174 {
175 return item;
176 }
177 }
178
179 if (mLastNotEmptyItem + 1 < mFirstRenderItems.size())
180 {
181 ++mLastNotEmptyItem;
182 mFirstRenderItems[mLastNotEmptyItem]->setTexture(_texture);
183 return mFirstRenderItems[mLastNotEmptyItem];
184 }
185
186 // not found, create new
187 RenderItem* item = new RenderItem();
188 item->setTexture(_texture);
189 item->setManualRender(_manualRender);
190 mLastNotEmptyItem = mFirstRenderItems.size();
191 mFirstRenderItems.push_back(item);
192
193 return item;
194 }
195
196 RenderItem* LayerNode::addToRenderItemSecondQueue(ITexture* _texture, bool _manualRender)
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
223 void LayerNode::attachLayerItem(ILayerItem* _item)
224 {
225 mLayerItems.push_back(_item);
226 _item->attachItemToNode(mLayer, this);
227
228 mOutOfDate = true;
229 }
230
231 void LayerNode::detachLayerItem(ILayerItem* _item)
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
247 void LayerNode::outOfDate(RenderItem* _item)
248 {
249 mOutOfDate = true;
250 if (_item)
251 _item->outOfDate();
252 }
253
254 EnumeratorILayerNode LayerNode::getEnumerator() const
255 {
256 return EnumeratorILayerNode(mChildItems);
257 }
258
259 size_t LayerNode::getLayerNodeCount() const
260 {
261 return mChildItems.size();
262 }
263
264 ILayerNode* LayerNode::getLayerNodeAt(size_t _index) const
265 {
266 MYGUI_ASSERT_RANGE(_index, mChildItems.size(), "LayerNode::getLayerNodeAt");
267
268 return mChildItems[_index];
269 }
270
271 void LayerNode::updateCompression()
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 {
288 mLastNotEmptyItem = mFirstRenderItems.size() - 1;
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
312 ILayer* LayerNode::getLayer() const
313 {
314 return mLayer;
315 }
316
317 ILayerNode* LayerNode::getParent() const
318 {
319 return mParent;
320 }
321
322 bool LayerNode::isOutOfDate() const
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
345 float LayerNode::getNodeDepth() const
346 {
347 return mDepth;
348 }
349
350} // namespace MyGUI
MYGUI_EXCEPT
#define MYGUI_EXCEPT(dest)
Definition MyGUI_Diagnostic.h:21
MYGUI_ASSERT_RANGE
#define MYGUI_ASSERT_RANGE(index, size, owner)
Definition MyGUI_Diagnostic.h:40
MyGUI_ILayerItem.h
MyGUI_ISubWidget.h
MyGUI_ISubWidgetText.h
MyGUI_ITexture.h
MyGUI_LayerNode.h
MyGUI_Precompiled.h
MyGUI::Enumerator
Definition MyGUI_Enumerator.h:49
MyGUI::ILayer
Definition MyGUI_ILayer.h:23
MyGUI::ILayer::getSize
virtual const IntSize & getSize() const =0
MyGUI::ILayerItem
Definition MyGUI_ILayerItem.h:20
MyGUI::ILayerItem::attachItemToNode
virtual void attachItemToNode(ILayer *_layer, ILayerNode *_node)=0
MyGUI::ILayerItem::getLayerItemByPoint
virtual ILayerItem * getLayerItemByPoint(int _left, int _top) const =0
MyGUI::ILayerNode
Definition MyGUI_ILayerNode.h:30
MyGUI::IRenderTarget
Definition MyGUI_IRenderTarget.h:21
MyGUI::IRenderTarget::getInfo
virtual const RenderTargetInfo & getInfo() const =0
MyGUI::ITexture
Definition MyGUI_ITexture.h:28
MyGUI::LayerNode
Definition MyGUI_LayerNode.h:24
MyGUI::LayerNode::mLayer
ILayer * mLayer
Definition MyGUI_LayerNode.h:95
MyGUI::LayerNode::getNodeDepth
float getNodeDepth() const override
Definition MyGUI_LayerNode.cpp:345
MyGUI::LayerNode::isOutOfDate
bool isOutOfDate() const
Definition MyGUI_LayerNode.cpp:322
MyGUI::LayerNode::mOutOfDate
bool mOutOfDate
Definition MyGUI_LayerNode.h:96
MyGUI::LayerNode::getParent
ILayerNode * getParent() const override
Definition MyGUI_LayerNode.cpp:317
MyGUI::LayerNode::~LayerNode
~LayerNode() override
Definition MyGUI_LayerNode.cpp:27
MyGUI::LayerNode::mSecondRenderItems
VectorRenderItem mSecondRenderItems
Definition MyGUI_LayerNode.h:84
MyGUI::LayerNode::createChildItemNode
ILayerNode * createChildItemNode() override
Definition MyGUI_LayerNode.cpp:42
MyGUI::LayerNode::mLayerItems
VectorLayerItem mLayerItems
Definition MyGUI_LayerNode.h:90
MyGUI::LayerNode::getLayer
ILayer * getLayer() const override
Definition MyGUI_LayerNode.cpp:312
MyGUI::LayerNode::getLayerNodeCount
size_t getLayerNodeCount() const override
Definition MyGUI_LayerNode.cpp:259
MyGUI::LayerNode::attachLayerItem
void attachLayerItem(ILayerItem *_item) override
Definition MyGUI_LayerNode.cpp:223
MyGUI::LayerNode::detachLayerItem
void detachLayerItem(ILayerItem *_item) override
Definition MyGUI_LayerNode.cpp:231
MyGUI::LayerNode::destroyChildItemNode
void destroyChildItemNode(ILayerNode *_node) override
Definition MyGUI_LayerNode.cpp:52
MyGUI::LayerNode::mLastNotEmptyItem
size_t mLastNotEmptyItem
Definition MyGUI_LayerNode.h:86
MyGUI::LayerNode::mFirstRenderItems
VectorRenderItem mFirstRenderItems
Definition MyGUI_LayerNode.h:83
MyGUI::LayerNode::mParent
ILayerNode * mParent
Definition MyGUI_LayerNode.h:94
MyGUI::LayerNode::mDepth
float mDepth
Definition MyGUI_LayerNode.h:98
MyGUI::LayerNode::upChildItemNode
void upChildItemNode(ILayerNode *_node) override
Definition MyGUI_LayerNode.cpp:69
MyGUI::LayerNode::updateCompression
void updateCompression()
Definition MyGUI_LayerNode.cpp:271
MyGUI::LayerNode::getEnumerator
EnumeratorILayerNode getEnumerator() const override
Definition MyGUI_LayerNode.cpp:254
MyGUI::LayerNode::renderToTarget
void renderToTarget(IRenderTarget *_target, bool _update) override
Definition MyGUI_LayerNode.cpp:86
MyGUI::LayerNode::resizeView
void resizeView(const IntSize &_viewSize) override
Definition MyGUI_LayerNode.cpp:110
MyGUI::LayerNode::addToRenderItem
RenderItem * addToRenderItem(ITexture *_texture, bool _firstQueue, bool _manualRender) override
Definition MyGUI_LayerNode.cpp:138
MyGUI::LayerNode::mChildItems
VectorILayerNode mChildItems
Definition MyGUI_LayerNode.h:92
MyGUI::LayerNode::getLayerItemByPoint
ILayerItem * getLayerItemByPoint(int _left, int _top) const override
Definition MyGUI_LayerNode.cpp:118
MyGUI::LayerNode::outOfDate
void outOfDate(RenderItem *_item) override
Definition MyGUI_LayerNode.cpp:247
MyGUI::LayerNode::addToRenderItemFirstQueue
RenderItem * addToRenderItemFirstQueue(ITexture *_texture, bool _manualRender)
Definition MyGUI_LayerNode.cpp:150
MyGUI::LayerNode::LayerNode
LayerNode(ILayer *_layer, ILayerNode *_parent=nullptr)
Definition MyGUI_LayerNode.cpp:17
MyGUI::LayerNode::addToRenderItemSecondQueue
RenderItem * addToRenderItemSecondQueue(ITexture *_texture, bool _manualRender)
Definition MyGUI_LayerNode.cpp:196
MyGUI::LayerNode::getLayerNodeAt
ILayerNode * getLayerNodeAt(size_t _index) const override
Definition MyGUI_LayerNode.cpp:264
MyGUI::LayerNode::mOutOfDateCompression
bool mOutOfDateCompression
Definition MyGUI_LayerNode.h:97
MyGUI::RenderItem
Definition MyGUI_RenderItem.h:23
MyGUI::RenderItem::setManualRender
void setManualRender(bool _value)
Definition MyGUI_RenderItem.cpp:195
MyGUI::RenderItem::setTexture
void setTexture(ITexture *_value)
Definition MyGUI_RenderItem.cpp:165
MyGUI::RenderItem::getManualRender
bool getManualRender() const
Definition MyGUI_RenderItem.cpp:200
MyGUI::RenderItem::outOfDate
void outOfDate()
Definition MyGUI_RenderItem.cpp:205
MyGUI::RenderItem::getTexture
ITexture * getTexture() const
Definition MyGUI_RenderItem.cpp:180
MyGUI
Definition MyGUI_ActionController.h:15
MyGUI::VectorRenderItem
std::vector< RenderItem * > VectorRenderItem
Definition MyGUI_LayerNode.h:19
MyGUI::EnumeratorILayerNode
Enumerator< VectorILayerNode > EnumeratorILayerNode
Definition MyGUI_ILayerNode.h:26
MyGUI::RenderTargetInfo::maximumDepth
float maximumDepth
Definition MyGUI_RenderTargetInfo.h:37
MyGUI::types::TSize< int >