MyGUI 3.2.0

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

- File List
- Globals

MyGUI_OverlappedLayer.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
23 #include "MyGUI_Precompiled.h"
24 #include "MyGUI_LayerItem.h"
25 #include "MyGUI_OverlappedLayer.h"
26 #include "MyGUI_LayerNode.h"
27 #include "MyGUI_RenderManager.h"
28
29 namespace MyGUI
30 {
31
32 OverlappedLayer::OverlappedLayer() :
33 mIsPick(false),
34 mOutOfDate(false)
35 {
36 mViewSize = RenderManager::getInstance().getViewSize();
37 }
38
39 OverlappedLayer::~OverlappedLayer()
40 {
41 MYGUI_ASSERT(mChildItems.empty(), "Layer '" << getName() << "' must be empty before destroy");
42 }
43
44 void OverlappedLayer::deserialization(xml::ElementPtr _node, Version _version)
45 {
46 mName = _node->findAttribute("name");
47 if (_version >= Version(1, 2))
48 {
49 MyGUI::xml::ElementEnumerator propert = _node->getElementEnumerator();
50 while (propert.next("Property"))
51 {
52 const std::string& key = propert->findAttribute("key");
53 const std::string& value = propert->findAttribute("value");
54 if (key == "Pick")
55 mIsPick = utility::parseValue<bool>(value);
56 }
57 }
58 else if (_version >= Version(1, 0))
59 {
60 mIsPick = utility::parseBool(_node->findAttribute("pick"));
61 }
62 else
63 {
64 mIsPick = utility::parseBool(_node->findAttribute("peek"));
65 }
66 }
67
68 ILayerNode* OverlappedLayer::createChildItemNode()
69 {
70 // создаем рутовый айтем
71 ILayerNode* node = new LayerNode(this);
72 mChildItems.push_back(node);
73
74 mOutOfDate = true;
75
76 return node;
77 }
78
79 void OverlappedLayer::destroyChildItemNode(ILayerNode* _item)
80 {
81 // если есть отец, то русть сам и удаляет
82 ILayerNode* parent = _item->getParent();
83 if (parent)
84 {
85 parent->destroyChildItemNode(_item);
86
87 mOutOfDate = true;
88
89 return;
90 }
91
92 // айтем рутовый, мы удаляем
93 for (VectorILayerNode::iterator iter = mChildItems.begin(); iter != mChildItems.end(); ++iter)
94 {
95 if ((*iter) == _item)
96 {
97 delete _item;
98 mChildItems.erase(iter);
99
100 mOutOfDate = true;
101
102 return;
103 }
104 }
105
106 MYGUI_EXCEPT("item node not found");
107 }
108
109 void OverlappedLayer::upChildItemNode(ILayerNode* _item)
110 {
111 // если есть отец, то пусть сам рулит
112 ILayerNode* parent = _item->getParent();
113 if (parent != nullptr)
114 {
115 parent->upChildItemNode(_item);
116
117 mOutOfDate = true;
118
119 return;
120 }
121
122 if ((2 > mChildItems.size()) || (mChildItems.back() == _item))
123 return;
124
125 for (VectorILayerNode::iterator iter = mChildItems.begin(); iter != mChildItems.end(); ++iter)
126 {
127 if ((*iter) == _item)
128 {
129 mChildItems.erase(iter);
130 mChildItems.push_back(_item);
131
132 mOutOfDate = true;
133
134 return;
135 }
136 }
137
138 MYGUI_EXCEPT("item node not found");
139 }
140
141 ILayerItem* OverlappedLayer::getLayerItemByPoint(int _left, int _top) const
142 {
143 if (!mIsPick)
144 return nullptr;
145
146 VectorILayerNode::const_reverse_iterator iter = mChildItems.rbegin();
147 while (iter != mChildItems.rend())
148 {
149 ILayerItem* item = (*iter)->getLayerItemByPoint(_left, _top);
150 if (item != nullptr)
151 return item;
152 ++iter;
153 }
154 return nullptr;
155 }
156
157 IntPoint OverlappedLayer::getPosition(int _left, int _top) const
158 {
159 return IntPoint(_left, _top);
160 }
161
162 void OverlappedLayer::renderToTarget(IRenderTarget* _target, bool _update)
163 {
164 for (VectorILayerNode::iterator iter = mChildItems.begin(); iter != mChildItems.end(); ++iter)
165 (*iter)->renderToTarget(_target, _update);
166
167 mOutOfDate = false;
168 }
169
170 void OverlappedLayer::resizeView(const IntSize& _viewSize)
171 {
172 for (VectorILayerNode::iterator iter = mChildItems.begin(); iter != mChildItems.end(); ++iter)
173 (*iter)->resizeView(_viewSize);
174
175 mViewSize = _viewSize;
176 }
177
178 EnumeratorILayerNode OverlappedLayer::getEnumerator() const
179 {
180 return EnumeratorILayerNode(mChildItems);
181 }
182
183 const IntSize& OverlappedLayer::getSize() const
184 {
185 return mViewSize;
186 }
187
188 bool OverlappedLayer::isOutOfDate() const
189 {
190 for (VectorILayerNode::const_iterator iter = mChildItems.begin(); iter != mChildItems.end(); ++iter)
191 {
192 if (static_cast<const LayerNode*>(*iter)->isOutOfDate())
193 return true;
194 }
195
196 return mOutOfDate;
197 }
198
199 } // namespace MyGUI
MyGUI::ILayerNode::getParent
virtual ILayerNode * getParent() const =0
MyGUI::types::TPoint< int >
MyGUI::ILayerNode
Definition: MyGUI_ILayerNode.h:42
MyGUI::OverlappedLayer::getEnumerator
virtual EnumeratorILayerNode getEnumerator() const
Definition: MyGUI_OverlappedLayer.cpp:178
MyGUI::ILayerItem::getLayerItemByPoint
virtual ILayerItem * getLayerItemByPoint(int _left, int _top) const =0
MyGUI::OverlappedLayer::createChildItemNode
virtual ILayerNode * createChildItemNode()
Definition: MyGUI_OverlappedLayer.cpp:68
MyGUI::ILayer::getName
const std::string & getName() const
Definition: MyGUI_ILayer.h:46
MyGUI_Precompiled.h
MyGUI::types::TSize< int >
MyGUI::Singleton< RenderManager >::getInstance
static RenderManager & getInstance()
Definition: MyGUI_Singleton.h:53
MyGUI::ILayerNode::upChildItemNode
virtual void upChildItemNode(ILayerNode *_node)=0
MyGUI::LayerNode
Definition: MyGUI_LayerNode.h:37
MyGUI::xml::Element::findAttribute
bool findAttribute(const std::string &_name, std::string &_value)
Definition: MyGUI_XmlDocument.cpp:261
MyGUI::OverlappedLayer::OverlappedLayer
OverlappedLayer()
Definition: MyGUI_OverlappedLayer.cpp:32
MyGUI::RenderManager::getViewSize
virtual const IntSize & getViewSize() const =0
MyGUI_OverlappedLayer.h
MyGUI::Enumerator
Definition: MyGUI_Enumerator.h:63
MyGUI::xml::ElementEnumerator
Definition: MyGUI_XmlDocument.h:124
MyGUI::OverlappedLayer::~OverlappedLayer
virtual ~OverlappedLayer()
Definition: MyGUI_OverlappedLayer.cpp:39
MyGUI::OverlappedLayer::mOutOfDate
bool mOutOfDate
Definition: MyGUI_OverlappedLayer.h:71
MyGUI_RenderManager.h
MyGUI::OverlappedLayer::isOutOfDate
bool isOutOfDate() const
Definition: MyGUI_OverlappedLayer.cpp:188
MYGUI_EXCEPT
#define MYGUI_EXCEPT(dest)
Definition: MyGUI_Diagnostic.h:49
MyGUI::ILayer::mName
std::string mName
Definition: MyGUI_ILayer.h:77
MyGUI::xml::ElementEnumerator::next
bool next()
Definition: MyGUI_XmlDocument.cpp:115
MyGUI::OverlappedLayer::destroyChildItemNode
virtual void destroyChildItemNode(ILayerNode *_node)
Definition: MyGUI_OverlappedLayer.cpp:79
MYGUI_ASSERT
#define MYGUI_ASSERT(exp, dest)
Definition: MyGUI_Diagnostic.h:58
MyGUI::IRenderTarget
Definition: MyGUI_IRenderTarget.h:35
MyGUI::OverlappedLayer::getSize
virtual const IntSize & getSize() const
Definition: MyGUI_OverlappedLayer.cpp:183
MyGUI_LayerItem.h
MyGUI::xml::Element
Definition: MyGUI_XmlDocument.h:168
MyGUI::OverlappedLayer::mIsPick
bool mIsPick
Definition: MyGUI_OverlappedLayer.h:69
MyGUI::Version
Definition: MyGUI_Version.h:32
MyGUI::EnumeratorILayerNode
Enumerator< VectorILayerNode > EnumeratorILayerNode
Definition: MyGUI_ILayerNode.h:40
MyGUI::ILayerItem
Definition: MyGUI_ILayerItem.h:33
MyGUI_LayerNode.h
MyGUI::utility::parseBool
bool parseBool(const std::string &_value)
Definition: MyGUI_StringUtility.h:206
MyGUI::OverlappedLayer::getPosition
virtual IntPoint getPosition(int _left, int _top) const
Definition: MyGUI_OverlappedLayer.cpp:157
MyGUI::xml::Element::getElementEnumerator
ElementEnumerator getElementEnumerator()
Definition: MyGUI_XmlDocument.cpp:367
MyGUI::OverlappedLayer::getLayerItemByPoint
virtual ILayerItem * getLayerItemByPoint(int _left, int _top) const
Definition: MyGUI_OverlappedLayer.cpp:141
MyGUI::OverlappedLayer::mChildItems
VectorILayerNode mChildItems
Definition: MyGUI_OverlappedLayer.h:70
MyGUI::ILayerNode::destroyChildItemNode
virtual void destroyChildItemNode(ILayerNode *_node)=0
MyGUI::OverlappedLayer::deserialization
virtual void deserialization(xml::ElementPtr _node, Version _version)
Definition: MyGUI_OverlappedLayer.cpp:44
MyGUI::OverlappedLayer::renderToTarget
virtual void renderToTarget(IRenderTarget *_target, bool _update)
Definition: MyGUI_OverlappedLayer.cpp:162
MyGUI::OverlappedLayer::mViewSize
IntSize mViewSize
Definition: MyGUI_OverlappedLayer.h:72
MyGUI::OverlappedLayer::resizeView
virtual void resizeView(const IntSize &_viewSize)
Definition: MyGUI_OverlappedLayer.cpp:170
MyGUI::OverlappedLayer::upChildItemNode
virtual void upChildItemNode(ILayerNode *_node)
Definition: MyGUI_OverlappedLayer.cpp:109
MyGUI::IntPoint
types::TPoint< int > IntPoint
Definition: MyGUI_Types.h:41