MyGUI: MyGUI_OverlappedLayer.cpp Source File

MyGUI 3.4.3

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