MyGUI: MyGUI_LayerItem.cpp Source File

MyGUI 3.4.2

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

- File List
- Globals

MyGUI_LayerItem.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 <algorithm>
10
11namespace MyGUI
12{
13
14 LayerItem::LayerItem() :
15 mLayer(nullptr),
16 mLayerNode(nullptr),
17 mSaveLayerNode(nullptr),
18 mTexture(nullptr)
19 {
20 }
21
22 void LayerItem::addChildItem(LayerItem* _item)
23 {
24 mLayerItems.push_back(_item);
25 if (mLayerNode != nullptr)
26 {
27 _item->attachToLayerItemNode(mLayerNode, false);
28 }
29 }
30
31 void LayerItem::removeChildItem(LayerItem* _item)
32 {
33 VectorLayerItem::iterator item = std::remove(mLayerItems.begin(), mLayerItems.end(), _item);
34 MYGUI_ASSERT(item != mLayerItems.end(), "item not found");
35 mLayerItems.erase(item);
36 }
37
38 void LayerItem::addChildNode(LayerItem* _item)
39 {
40 mLayerNodes.push_back(_item);
41 if (mLayerNode != nullptr)
42 {
43 // создаем оверлаппеду новый айтем
44 ILayerNode* child_node = mLayerNode->createChildItemNode();
45 _item->attachToLayerItemNode(child_node, true);
46 }
47 }
48
49 void LayerItem::removeChildNode(LayerItem* _item)
50 {
51 VectorLayerItem::iterator item = std::remove(mLayerNodes.begin(), mLayerNodes.end(), _item);
52 MYGUI_ASSERT(item != mLayerNodes.end(), "item not found");
53 mLayerNodes.erase(item);
54 }
55
56 void LayerItem::addRenderItem(ISubWidget* _item)
57 {
58 mDrawItems.push_back(_item);
59 }
60
61 void LayerItem::removeAllRenderItems()
62 {
63 detachFromLayerItemNode(false);
64 mDrawItems.clear();
65 }
66
67 void LayerItem::setRenderItemTexture(ITexture* _texture)
68 {
69 if (mTexture == _texture)
70 return;
71
72 mTexture = _texture;
73 if (mLayerNode)
74 {
75 ILayerNode* node = mLayerNode;
76 // позже сделать детач без текста
77 detachFromLayerItemNode(false);
78 attachToLayerItemNode(node, false);
79 }
80 }
81
82 void LayerItem::saveLayerItem()
83 {
84 mSaveLayerNode = mLayerNode;
85 }
86
87 void LayerItem::restoreLayerItem()
88 {
89 mLayerNode = mSaveLayerNode;
90 if (mLayerNode)
91 {
92 attachToLayerItemNode(mLayerNode, false);
93 }
94 }
95
96 void LayerItem::attachItemToNode(ILayer* _layer, ILayerNode* _node)
97 {
98 mLayer = _layer;
99 mLayerNode = _node;
100
101 attachToLayerItemNode(_node, true);
102 }
103
104 void LayerItem::detachFromLayer()
105 {
106 // мы уже отдетачены в доску
107 if (nullptr == mLayer)
108 return;
109
110 // такого быть не должно
111 MYGUI_ASSERT(mLayerNode, "mLayerNode == nullptr");
112
113 // отписываемся от пиккинга
114 mLayerNode->detachLayerItem(this);
115
116 // при детаче обнулиться
117 ILayerNode* save = mLayerNode;
118
119 // физически отсоединяем
120 detachFromLayerItemNode(true);
121
122 // отсоединяем леер и обнуляем у рутового виджета
123 mLayer->destroyChildItemNode(save);
124 mLayerNode = nullptr;
125 mLayer = nullptr;
126 }
127
128 void LayerItem::upLayerItem()
129 {
130 MyGUI::ILayerNode* node = mLayerNode;
131 while (node)
132 {
133 node->getLayer()->upChildItemNode(node);
134 node = node->getParent();
135 }
136 }
137
138 void LayerItem::attachToLayerItemNode(ILayerNode* _item, bool _deep)
139 {
140 MYGUI_DEBUG_ASSERT(nullptr != _item, "attached item must be valid");
141
142 // сохраняем, чтобы последующие дети могли приаттачиться
143 mLayerNode = _item;
144
145 for (VectorSubWidget::iterator skin = mDrawItems.begin(); skin != mDrawItems.end(); ++skin)
146 {
147 (*skin)->createDrawItem(mTexture, _item);
148 }
149
150 for (VectorLayerItem::iterator item = mLayerItems.begin(); item != mLayerItems.end(); ++item)
151 {
152 (*item)->attachToLayerItemNode(_item, _deep);
153 }
154
155 for (VectorLayerItem::iterator item = mLayerNodes.begin(); item != mLayerNodes.end(); ++item)
156 {
157 // создаем оверлаппеду новый айтем
158 if (_deep)
159 {
160 ILayerNode* child_node = _item->createChildItemNode();
161 (*item)->attachToLayerItemNode(child_node, _deep);
162 }
163 }
164 }
165
166 void LayerItem::detachFromLayerItemNode(bool _deep)
167 {
168 for (VectorLayerItem::iterator item = mLayerItems.begin(); item != mLayerItems.end(); ++item)
169 {
170 (*item)->detachFromLayerItemNode(_deep);
171 }
172
173 for (VectorLayerItem::iterator item = mLayerNodes.begin(); item != mLayerNodes.end(); ++item)
174 {
175 if (_deep)
176 {
177 ILayerNode* node = (*item)->mLayerNode;
178 (*item)->detachFromLayerItemNode(_deep);
179 if (node)
180 {
181 node->getLayer()->destroyChildItemNode(node);
182 }
183 }
184 }
185
186 // мы уже отаттачены
187 ILayerNode* node = mLayerNode;
188 if (node)
189 {
190 //for (VectorWidgetPtr::iterator widget = mWidgetChildSkin.begin(); widget != mWidgetChildSkin.end(); ++widget) (*widget)->_detachFromLayerItemKeeperByStyle(_deep);
191 for (VectorSubWidget::iterator skin = mDrawItems.begin(); skin != mDrawItems.end(); ++skin)
192 {
193 (*skin)->destroyDrawItem();
194 }
195
196 // при глубокой очистке, если мы оверлаппед, то для нас создавали айтем
197 /*if (_deep && !this->isRootWidget() && mWidgetStyle == WidgetStyle::Overlapped)
198 {
199 node->destroyItemNode();
200 }*/
201 // очищаем
202 mLayerNode = nullptr;
203 }
204 }
205
206 ILayer* LayerItem::getLayer() const
207 {
208 return mLayer;
209 }
210
211 ILayerNode* LayerItem::getLayerNode() const
212 {
213 return mLayerNode;
214 }
215
216} // namespace MyGUI
MYGUI_ASSERT
#define MYGUI_ASSERT(exp, dest)
Definition MyGUI_Diagnostic.h:29
MYGUI_DEBUG_ASSERT
#define MYGUI_DEBUG_ASSERT(exp, dest)
Definition MyGUI_Diagnostic.h:50
MyGUI_LayerItem.h
MyGUI_Precompiled.h
MyGUI::ILayer
Definition MyGUI_ILayer.h:23
MyGUI::ILayer::upChildItemNode
virtual void upChildItemNode(ILayerNode *_node)=0
MyGUI::ILayer::destroyChildItemNode
virtual void destroyChildItemNode(ILayerNode *_node)=0
MyGUI::ILayerNode
Definition MyGUI_ILayerNode.h:30
MyGUI::ILayerNode::getParent
virtual ILayerNode * getParent() const =0
MyGUI::ILayerNode::detachLayerItem
virtual void detachLayerItem(ILayerItem *_root)=0
MyGUI::ILayerNode::getLayer
virtual ILayer * getLayer() const =0
MyGUI::ILayerNode::createChildItemNode
virtual ILayerNode * createChildItemNode()=0
MyGUI::ISubWidget
Definition MyGUI_ISubWidget.h:27
MyGUI::ITexture
Definition MyGUI_ITexture.h:28
MyGUI::LayerItem
Definition MyGUI_LayerItem.h:22
MyGUI::LayerItem::removeChildNode
void removeChildNode(LayerItem *_item)
Definition MyGUI_LayerItem.cpp:49
MyGUI::LayerItem::getLayerNode
ILayerNode * getLayerNode() const
Definition MyGUI_LayerItem.cpp:211
MyGUI::LayerItem::detachFromLayerItemNode
void detachFromLayerItemNode(bool _deep)
Definition MyGUI_LayerItem.cpp:166
MyGUI::LayerItem::addChildItem
void addChildItem(LayerItem *_item)
Definition MyGUI_LayerItem.cpp:22
MyGUI::LayerItem::addChildNode
void addChildNode(LayerItem *_item)
Definition MyGUI_LayerItem.cpp:38
MyGUI::LayerItem::removeChildItem
void removeChildItem(LayerItem *_item)
Definition MyGUI_LayerItem.cpp:31
MyGUI::LayerItem::removeAllRenderItems
void removeAllRenderItems()
Definition MyGUI_LayerItem.cpp:61
MyGUI::LayerItem::LayerItem
LayerItem()
Definition MyGUI_LayerItem.cpp:14
MyGUI::LayerItem::getLayer
ILayer * getLayer() const
Definition MyGUI_LayerItem.cpp:206
MyGUI::LayerItem::addRenderItem
void addRenderItem(ISubWidget *_item)
Definition MyGUI_LayerItem.cpp:56
MyGUI::LayerItem::detachFromLayer
void detachFromLayer() override
Definition MyGUI_LayerItem.cpp:104
MyGUI::LayerItem::restoreLayerItem
void restoreLayerItem()
Definition MyGUI_LayerItem.cpp:87
MyGUI::LayerItem::upLayerItem
void upLayerItem() override
Definition MyGUI_LayerItem.cpp:128
MyGUI::LayerItem::saveLayerItem
void saveLayerItem()
Definition MyGUI_LayerItem.cpp:82
MyGUI::LayerItem::attachItemToNode
void attachItemToNode(ILayer *_layer, ILayerNode *_node) override
Definition MyGUI_LayerItem.cpp:96
MyGUI::LayerItem::setRenderItemTexture
void setRenderItemTexture(ITexture *_texture)
Definition MyGUI_LayerItem.cpp:67
MyGUI::LayerItem::attachToLayerItemNode
void attachToLayerItemNode(ILayerNode *_node, bool _deep)
Definition MyGUI_LayerItem.cpp:138
MyGUI
Definition MyGUI_ActionController.h:15