MyGUI: MyGUI_LayerItem.cpp Source File

MyGUI 3.4.3

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