MyGUI: MyGUI_OverlappedLayer.cpp Source File

MyGUI 3.4.2

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

- File List
- Globals

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