MyGUI: MyGUI_SharedLayer.cpp Source File

MyGUI 3.4.2

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

- File List
- Globals

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
16 SharedLayer::SharedLayer() :
17 mIsPick(false),
18 mChildItem(nullptr),
19 mOutOfDate(false)
20 {
21 mViewSize = RenderManager::getInstance().getViewSize();
22 }
23
24 SharedLayer::~SharedLayer()
25 {
26 if (mChildItem != nullptr)
27 MYGUI_LOG(Critical, "Layer '" << getName() << "' must be empty before destroy");
28 }
29
30 void SharedLayer::deserialization(xml::ElementPtr _node, Version _version)
31 {
32 mName = _node->findAttribute("name");
33 if (_version >= Version(1, 2))
34 {
35 MyGUI::xml::ElementEnumerator propert = _node->getElementEnumerator();
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 {
46 setPick(utility::parseBool(_node->findAttribute("pick")));
47 }
48 else
49 {
50 setPick(utility::parseBool(_node->findAttribute("peek")));
51 }
52 }
53
54 void SharedLayer::setPick(bool _pick)
55 {
56 mIsPick = _pick;
57 }
58
59 ILayerNode* SharedLayer::createChildItemNode()
60 {
61 if (mChildItem == nullptr)
62 mChildItem = new SharedLayerNode(this);
63
64 mChildItem->addUsing();
65
66 mOutOfDate = true;
67
68 return mChildItem;
69 }
70
71 void SharedLayer::destroyChildItemNode(ILayerNode* _item)
72 {
73 // айтем рутовый, мы удаляем
74 if (mChildItem == _item)
75 {
76 mChildItem->removeUsing();
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
90 void SharedLayer::upChildItemNode(ILayerNode* _item)
91 {
92 // если есть отец, то пусть сам рулит
93 ILayerNode* parent = _item->getParent();
94 if (parent != nullptr)
95 parent->upChildItemNode(_item);
96
97 mOutOfDate = true;
98 }
99
100 ILayerItem* SharedLayer::getLayerItemByPoint(int _left, int _top) const
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
135 EnumeratorILayerNode SharedLayer::getEnumerator() const
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
153 size_t SharedLayer::getLayerNodeCount() const
154 {
155 return mChildItem == nullptr ? 0 : 1;
156 }
157
158 ILayerNode* SharedLayer::getLayerNodeAt(size_t _index) const
159 {
160 size_t count = getLayerNodeCount();
161 MYGUI_ASSERT_RANGE(_index, count, "SharedLayer::getLayerNodeAt");
162
163 return mChildItem;
164 }
165
166 const IntSize& SharedLayer::getSize() const
167 {
168 return mViewSize;
169 }
170
171 bool SharedLayer::isOutOfDate() const
172 {
173 if (mChildItem->isOutOfDate())
174 return true;
175
176 return mOutOfDate;
177 }
178
179} // namespace MyGUI
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_Precompiled.h
MyGUI_RenderManager.h
MyGUI_SharedLayer.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::ILayerNode
Definition MyGUI_ILayerNode.h:30
MyGUI::ILayerNode::getParent
virtual ILayerNode * getParent() const =0
MyGUI::ILayerNode::upChildItemNode
virtual void upChildItemNode(ILayerNode *_node)=0
MyGUI::IRenderTarget
Definition MyGUI_IRenderTarget.h:21
MyGUI::LayerNode::isOutOfDate
bool isOutOfDate() const
Definition MyGUI_LayerNode.cpp:322
MyGUI::LayerNode::renderToTarget
void renderToTarget(IRenderTarget *_target, bool _update) override
Definition MyGUI_LayerNode.cpp:86
MyGUI::LayerNode::resizeView
void resizeView(const IntSize &_viewSize) override
Definition MyGUI_LayerNode.cpp:110
MyGUI::LayerNode::getLayerItemByPoint
ILayerItem * getLayerItemByPoint(int _left, int _top) const override
Definition MyGUI_LayerNode.cpp:118
MyGUI::RenderManager::getViewSize
virtual const IntSize & getViewSize() const =0
MyGUI::RenderManager::getInstance
static RenderManager & getInstance()
MyGUI::SharedLayer::upChildItemNode
void upChildItemNode(ILayerNode *_node) override
Definition MyGUI_SharedLayer.cpp:90
MyGUI::SharedLayer::mViewSize
IntSize mViewSize
Definition MyGUI_SharedLayer.h:64
MyGUI::SharedLayer::mChildItem
SharedLayerNode * mChildItem
Definition MyGUI_SharedLayer.h:62
MyGUI::SharedLayer::getEnumerator
EnumeratorILayerNode getEnumerator() const override
Definition MyGUI_SharedLayer.cpp:135
MyGUI::SharedLayer::deserialization
void deserialization(xml::ElementPtr _node, Version _version) override
Definition MyGUI_SharedLayer.cpp:30
MyGUI::SharedLayer::setPick
void setPick(bool _pick)
Definition MyGUI_SharedLayer.cpp:54
MyGUI::SharedLayer::getLayerNodeAt
ILayerNode * getLayerNodeAt(size_t _index) const override
Definition MyGUI_SharedLayer.cpp:158
MyGUI::SharedLayer::renderToTarget
void renderToTarget(IRenderTarget *_target, bool _update) override
Definition MyGUI_SharedLayer.cpp:119
MyGUI::SharedLayer::isOutOfDate
bool isOutOfDate() const
Definition MyGUI_SharedLayer.cpp:171
MyGUI::SharedLayer::createChildItemNode
ILayerNode * createChildItemNode() override
Definition MyGUI_SharedLayer.cpp:59
MyGUI::SharedLayer::destroyChildItemNode
void destroyChildItemNode(ILayerNode *_node) override
Definition MyGUI_SharedLayer.cpp:71
MyGUI::SharedLayer::getPosition
IntPoint getPosition(int _left, int _top) const override
Definition MyGUI_SharedLayer.cpp:114
MyGUI::SharedLayer::~SharedLayer
~SharedLayer() override
Definition MyGUI_SharedLayer.cpp:24
MyGUI::SharedLayer::getLayerItemByPoint
ILayerItem * getLayerItemByPoint(int _left, int _top) const override
Definition MyGUI_SharedLayer.cpp:100
MyGUI::SharedLayer::mOutOfDate
bool mOutOfDate
Definition MyGUI_SharedLayer.h:63
MyGUI::SharedLayer::mIsPick
bool mIsPick
Definition MyGUI_SharedLayer.h:61
MyGUI::SharedLayer::getLayerNodeCount
size_t getLayerNodeCount() const override
Definition MyGUI_SharedLayer.cpp:153
MyGUI::SharedLayer::getSize
const IntSize & getSize() const override
Definition MyGUI_SharedLayer.cpp:166
MyGUI::SharedLayer::SharedLayer
SharedLayer()
Definition MyGUI_SharedLayer.cpp:16
MyGUI::SharedLayer::resizeView
void resizeView(const IntSize &_viewSize) override
Definition MyGUI_SharedLayer.cpp:127
MyGUI::SharedLayerNode
Definition MyGUI_SharedLayerNode.h:18
MyGUI::SharedLayerNode::addUsing
void addUsing()
Definition MyGUI_SharedLayerNode.cpp:19
MyGUI::SharedLayerNode::removeUsing
void removeUsing()
Definition MyGUI_SharedLayerNode.cpp:24
MyGUI::SharedLayerNode::countUsing
size_t countUsing() const
Definition MyGUI_SharedLayerNode.cpp:29
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::VectorILayerNode
std::vector< ILayerNode * > VectorILayerNode
Definition MyGUI_ILayerNode.h:25
MyGUI::EnumeratorILayerNode
Enumerator< VectorILayerNode > EnumeratorILayerNode
Definition MyGUI_ILayerNode.h:26
MyGUI::types::TPoint< int >
MyGUI::types::TSize< int >