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