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