MyGUI 3.4.1
MyGUI_SharedLayer.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_SharedLayer.h"
10#include "MyGUI_LayerNode.h"
11#include "MyGUI_RenderManager.h"
12
13namespace MyGUI
14{
15
17 mIsPick(false),
18 mChildItem(nullptr),
19 mOutOfDate(false)
20 {
22 }
23
25 {
26 if (mChildItem != nullptr)
27 MYGUI_LOG(Critical, "Layer '" << getName() << "' must be empty before destroy");
28 }
29
31 {
32 mName = _node->findAttribute("name");
33 if (_version >= Version(1, 2))
34 {
36 while (propert.next("Property"))
37 {
38 const std::string& key = propert->findAttribute("key");
39 const std::string& value = propert->findAttribute("value");
40 if (key == "Pick")
41 setPick(utility::parseValue<bool>(value));
42 }
43 }
44 else if (_version >= Version(1, 0))
45 {
47 }
48 else
49 {
51 }
52 }
53
54 void SharedLayer::setPick(bool _pick)
55 {
56 mIsPick = _pick;
57 }
58
60 {
61 if (mChildItem == nullptr)
62 mChildItem = new SharedLayerNode(this);
63
65
66 mOutOfDate = true;
67
68 return mChildItem;
69 }
70
72 {
73 // айтем рутовый, мы удаляем
74 if (mChildItem == _item)
75 {
77 if (0 == mChildItem->countUsing())
78 {
79 delete mChildItem;
80 mChildItem = nullptr;
81 }
82
83 mOutOfDate = true;
84
85 return;
86 }
87 //MYGUI_EXCEPT("item node not found");
88 }
89
91 {
92 // если есть отец, то пусть сам рулит
93 ILayerNode* parent = _item->getParent();
94 if (parent != nullptr)
95 parent->upChildItemNode(_item);
96
97 mOutOfDate = true;
98 }
99
101 {
102 if (!mIsPick)
103 return nullptr;
104
105 if (mChildItem != nullptr)
106 {
107 ILayerItem* item = mChildItem->getLayerItemByPoint(_left, _top);
108 if (item != nullptr)
109 return item;
110 }
111 return nullptr;
112 }
113
114 IntPoint SharedLayer::getPosition(int _left, int _top) const
115 {
116 return IntPoint(_left, _top);
117 }
118
119 void SharedLayer::renderToTarget(IRenderTarget* _target, bool _update)
120 {
121 if (mChildItem != nullptr)
122 mChildItem->renderToTarget(_target, _update);
123
124 mOutOfDate = false;
125 }
126
127 void SharedLayer::resizeView(const IntSize& _viewSize)
128 {
129 if (mChildItem != nullptr)
130 mChildItem->resizeView(_viewSize);
131
132 mViewSize = _viewSize;
133 }
134
136 {
137 static VectorILayerNode nodes;
138 if (mChildItem == nullptr)
139 {
140 nodes.clear();
141 }
142 else
143 {
144 if (nodes.empty())
145 nodes.push_back(mChildItem);
146 else
147 nodes[0] = mChildItem;
148 }
149
150 return EnumeratorILayerNode(nodes);
151 }
152
154 {
155 return mChildItem == nullptr ? 0 : 1;
156 }
157
159 {
160 size_t count = getLayerNodeCount();
161 MYGUI_ASSERT_RANGE(_index, count, "SharedLayer::getLayerNodeAt");
162
163 return mChildItem;
164 }
165
167 {
168 return mViewSize;
169 }
170
172 {
173 if (mChildItem->isOutOfDate())
174 return true;
175
176 return mOutOfDate;
177 }
178
179} // namespace MyGUI
#define MYGUI_ASSERT_RANGE(index, size, owner)
#define MYGUI_LOG(level, text)
const std::string & getName() const
Definition: MyGUI_ILayer.h:29
std::string mName
Definition: MyGUI_ILayer.h:67
virtual ILayerNode * getParent() const =0
virtual void upChildItemNode(ILayerNode *_node)=0
bool isOutOfDate() const
void renderToTarget(IRenderTarget *_target, bool _update) override
void resizeView(const IntSize &_viewSize) override
ILayerItem * getLayerItemByPoint(int _left, int _top) const override
virtual const IntSize & getViewSize() const =0
static RenderManager & getInstance()
void upChildItemNode(ILayerNode *_node) override
SharedLayerNode * mChildItem
EnumeratorILayerNode getEnumerator() const override
void deserialization(xml::ElementPtr _node, Version _version) override
void setPick(bool _pick)
ILayerNode * getLayerNodeAt(size_t _index) const override
void renderToTarget(IRenderTarget *_target, bool _update) override
ILayerNode * createChildItemNode() override
void destroyChildItemNode(ILayerNode *_node) override
IntPoint getPosition(int _left, int _top) const override
ILayerItem * getLayerItemByPoint(int _left, int _top) const override
size_t getLayerNodeCount() const override
const IntSize & getSize() const override
void resizeView(const IntSize &_viewSize) override
ElementEnumerator getElementEnumerator()
bool findAttribute(const std::string &_name, std::string &_value)
bool parseBool(const std::string &_value)
std::vector< ILayerNode * > VectorILayerNode
Enumerator< VectorILayerNode > EnumeratorILayerNode
types::TPoint< int > IntPoint
Definition: MyGUI_Types.h:26