MyGUI 3.2.0

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

- File List
- Globals

MyGUI_LayerItem.cpp
Go to the documentation of this file.
1
6 /*
7 This file is part of MyGUI.
8
9 MyGUI is free software: you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 MyGUI is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public License
20 along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
21 */
22 #include "MyGUI_Precompiled.h"
23 #include "MyGUI_LayerItem.h"
24 #include <algorithm>
25
26 namespace MyGUI
27 {
28
29 LayerItem::LayerItem() :
30 mLayer(nullptr),
31 mLayerNode(nullptr),
32 mSaveLayerNode(nullptr),
33 mTexture(nullptr)
34 {
35 }
36
37 LayerItem::~LayerItem()
38 {
39 }
40
41 void LayerItem::addChildItem(LayerItem* _item)
42 {
43 mLayerItems.push_back(_item);
44 if (mLayerNode != nullptr)
45 {
46 _item->attachToLayerItemNode(mLayerNode, false);
47 }
48 }
49
50 void LayerItem::removeChildItem(LayerItem* _item)
51 {
52 VectorLayerItem::iterator item = std::remove(mLayerItems.begin(), mLayerItems.end(), _item);
53 MYGUI_ASSERT(item != mLayerItems.end(), "item not found");
54 mLayerItems.erase(item);
55 }
56
57 void LayerItem::addChildNode(LayerItem* _item)
58 {
59 mLayerNodes.push_back(_item);
60 if (mLayerNode != nullptr)
61 {
62 // создаем оверлаппеду новый айтем
63 ILayerNode* child_node = mLayerNode->createChildItemNode();
64 _item->attachToLayerItemNode(child_node, true);
65 }
66 }
67
68 void LayerItem::removeChildNode(LayerItem* _item)
69 {
70 VectorLayerItem::iterator item = std::remove(mLayerNodes.begin(), mLayerNodes.end(), _item);
71 MYGUI_ASSERT(item != mLayerNodes.end(), "item not found");
72 mLayerNodes.erase(item);
73 }
74
75 void LayerItem::addRenderItem(ISubWidget* _item)
76 {
77 mDrawItems.push_back(_item);
78 }
79
80 void LayerItem::removeAllRenderItems()
81 {
82 detachFromLayerItemNode(false);
83 mDrawItems.clear();
84 }
85
86 void LayerItem::setRenderItemTexture(ITexture* _texture)
87 {
88 mTexture = _texture;
89 if (mLayerNode)
90 {
91 ILayerNode* node = mLayerNode;
92 // позже сделать детач без текста
93 detachFromLayerItemNode(false);
94 attachToLayerItemNode(node, false);
95 }
96 }
97
98 void LayerItem::saveLayerItem()
99 {
100 mSaveLayerNode = mLayerNode;
101 }
102
103 void LayerItem::restoreLayerItem()
104 {
105 mLayerNode = mSaveLayerNode;
106 if (mLayerNode)
107 {
108 attachToLayerItemNode(mLayerNode, false);
109 }
110 }
111
112 void LayerItem::attachItemToNode(ILayer* _layer, ILayerNode* _node)
113 {
114 mLayer = _layer;
115 mLayerNode = _node;
116
117 attachToLayerItemNode(_node, true);
118 }
119
120 void LayerItem::detachFromLayer()
121 {
122 // мы уже отдетачены в доску
123 if (nullptr == mLayer) return;
124
125 // такого быть не должно
126 MYGUI_ASSERT(mLayerNode, "_item->mLayerNode == nullptr");
127
128 // отписываемся от пиккинга
129 mLayerNode->detachLayerItem(this);
130
131 // при детаче обнулиться
132 ILayerNode* save = mLayerNode;
133
134 // физически отсоединяем
135 detachFromLayerItemNode(true);
136
137 // отсоединяем леер и обнуляем у рутового виджета
138 mLayer->destroyChildItemNode(save);
139 mLayerNode = nullptr;
140 mLayer = nullptr;
141 }
142
143 void LayerItem::upLayerItem()
144 {
145 if (mLayerNode) mLayerNode->getLayer()->upChildItemNode(mLayerNode);
146 }
147
148 void LayerItem::attachToLayerItemNode(ILayerNode* _item, bool _deep)
149 {
150 MYGUI_DEBUG_ASSERT(nullptr != _item, "attached item must be valid");
151
152 // сохраняем, чтобы последующие дети могли приаттачиться
153 mLayerNode = _item;
154
155 for (VectorSubWidget::iterator skin = mDrawItems.begin(); skin != mDrawItems.end(); ++skin)
156 {
157 (*skin)->createDrawItem(mTexture, _item);
158 }
159
160 for (VectorLayerItem::iterator item = mLayerItems.begin(); item != mLayerItems.end(); ++item)
161 {
162 (*item)->attachToLayerItemNode(_item, _deep);
163 }
164
165 for (VectorLayerItem::iterator item = mLayerNodes.begin(); item != mLayerNodes.end(); ++item)
166 {
167 // создаем оверлаппеду новый айтем
168 if (_deep)
169 {
170 ILayerNode* child_node = _item->createChildItemNode();
171 (*item)->attachToLayerItemNode(child_node, _deep);
172 }
173 }
174 }
175
176 void LayerItem::detachFromLayerItemNode(bool _deep)
177 {
178 for (VectorLayerItem::iterator item = mLayerItems.begin(); item != mLayerItems.end(); ++item)
179 {
180 (*item)->detachFromLayerItemNode(_deep);
181 }
182
183 for (VectorLayerItem::iterator item = mLayerNodes.begin(); item != mLayerNodes.end(); ++item)
184 {
185 if (_deep)
186 {
187 ILayerNode* node = (*item)->mLayerNode;
188 (*item)->detachFromLayerItemNode(_deep);
189 if (node)
190 {
191 node->getLayer()->destroyChildItemNode(node);
192 }
193 }
194 }
195
196 // мы уже отаттачены
197 ILayerNode* node = mLayerNode;
198 if (node)
199 {
200 //for (VectorWidgetPtr::iterator widget = mWidgetChildSkin.begin(); widget != mWidgetChildSkin.end(); ++widget) (*widget)->_detachFromLayerItemKeeperByStyle(_deep);
201 for (VectorSubWidget::iterator skin = mDrawItems.begin(); skin != mDrawItems.end(); ++skin)
202 {
203 (*skin)->destroyDrawItem();
204 }
205
206 // при глубокой очистке, если мы оверлаппед, то для нас создавали айтем
207 /*if (_deep && !this->isRootWidget() && mWidgetStyle == WidgetStyle::Overlapped)
208 {
209 node->destroyItemNode();
210 }*/
211 // очищаем
212 mLayerNode = nullptr;
213 }
214 }
215
216 ILayer* LayerItem::getLayer() const
217 {
218 return mLayer;
219 }
220
221 } // namespace MyGUI
MyGUI::LayerItem
Definition: MyGUI_LayerItem.h:35
MyGUI::LayerItem::addChildNode
void addChildNode(LayerItem *_item)
Definition: MyGUI_LayerItem.cpp:57
MyGUI::LayerItem::LayerItem
LayerItem()
Definition: MyGUI_LayerItem.cpp:29
MyGUI::LayerItem::addChildItem
void addChildItem(LayerItem *_item)
Definition: MyGUI_LayerItem.cpp:41
MyGUI::LayerItem::detachFromLayer
virtual void detachFromLayer()
Definition: MyGUI_LayerItem.cpp:120
MyGUI::ILayerNode
Definition: MyGUI_ILayerNode.h:42
MyGUI::LayerItem::detachFromLayerItemNode
void detachFromLayerItemNode(bool _deep)
Definition: MyGUI_LayerItem.cpp:176
MyGUI_Precompiled.h
MyGUI::LayerItem::attachItemToNode
virtual void attachItemToNode(ILayer *_layer, ILayerNode *_node)
Definition: MyGUI_LayerItem.cpp:112
MyGUI::LayerItem::setRenderItemTexture
void setRenderItemTexture(ITexture *_texture)
Definition: MyGUI_LayerItem.cpp:86
MyGUI::LayerItem::~LayerItem
virtual ~LayerItem()
Definition: MyGUI_LayerItem.cpp:37
MyGUI::ISubWidget
Definition: MyGUI_ISubWidget.h:39
MyGUI::LayerItem::upLayerItem
virtual void upLayerItem()
Definition: MyGUI_LayerItem.cpp:143
nullptr
#define nullptr
Definition: MyGUI_Prerequest.h:47
MyGUI::ILayer::upChildItemNode
virtual void upChildItemNode(ILayerNode *_node)=0
MyGUI::LayerItem::removeChildNode
void removeChildNode(LayerItem *_item)
Definition: MyGUI_LayerItem.cpp:68
MyGUI::LayerItem::saveLayerItem
void saveLayerItem()
Definition: MyGUI_LayerItem.cpp:98
MyGUI::ILayerNode::createChildItemNode
virtual ILayerNode * createChildItemNode()=0
MyGUI::ILayer
Definition: MyGUI_ILayer.h:36
MyGUI::LayerItem::attachToLayerItemNode
void attachToLayerItemNode(ILayerNode *_node, bool _deep)
Definition: MyGUI_LayerItem.cpp:148
MYGUI_ASSERT
#define MYGUI_ASSERT(exp, dest)
Definition: MyGUI_Diagnostic.h:58
MyGUI::ITexture
Definition: MyGUI_ITexture.h:41
MyGUI::LayerItem::removeAllRenderItems
void removeAllRenderItems()
Definition: MyGUI_LayerItem.cpp:80
MyGUI_LayerItem.h
MyGUI::ILayer::destroyChildItemNode
virtual void destroyChildItemNode(ILayerNode *_node)=0
MyGUI::LayerItem::addRenderItem
void addRenderItem(ISubWidget *_item)
Definition: MyGUI_LayerItem.cpp:75
MyGUI::LayerItem::removeChildItem
void removeChildItem(LayerItem *_item)
Definition: MyGUI_LayerItem.cpp:50
MYGUI_DEBUG_ASSERT
#define MYGUI_DEBUG_ASSERT(exp, dest)
Definition: MyGUI_Diagnostic.h:83
MyGUI::ILayerNode::getLayer
virtual ILayer * getLayer() const =0
MyGUI::LayerItem::getLayer
ILayer * getLayer() const
Definition: MyGUI_LayerItem.cpp:216
MyGUI::LayerItem::restoreLayerItem
void restoreLayerItem()
Definition: MyGUI_LayerItem.cpp:103
MyGUI::ILayerNode::detachLayerItem
virtual void detachLayerItem(ILayerItem *_root)=0