MyGUI: MyGUI_SharedLayer.cpp Source File

MyGUI 3.4.3

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 {
18 mViewSize = RenderManager::getInstance().getViewSize();
19 }
20
21 SharedLayer::~SharedLayer()
22 {
23 if (mChildItem != nullptr)
24 MYGUI_LOG(Critical, "Layer '" << getName() << "' must be empty before destroy");
25 }
26
27 void SharedLayer::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 SharedLayer::setPick(bool _pick)
52 {
53 mIsPick = _pick;
54 }
55
56 ILayerNode* SharedLayer::createChildItemNode()
57 {
58 if (mChildItem == nullptr)
59 mChildItem = new SharedLayerNode(this);
60
61 mChildItem->addUsing();
62
63 mOutOfDate = true;
64
65 return mChildItem;
66 }
67
68 void SharedLayer::destroyChildItemNode(ILayerNode* _item)
69 {
70 // айтем рутовый, мы удаляем
71 if (mChildItem == _item)
72 {
73 mChildItem->removeUsing();
74 if (0 == mChildItem->countUsing())
75 {
76 delete mChildItem;
77 mChildItem = nullptr;
78 }
79
80 mOutOfDate = true;
81
82 return;
83 }
84 //MYGUI_EXCEPT("item node not found");
85 }
86
87 void SharedLayer::upChildItemNode(ILayerNode* _item)
88 {
89 // если есть отец, то пусть сам рулит
90 ILayerNode* parent = _item->getParent();
91 if (parent != nullptr)
92 parent->upChildItemNode(_item);
93
94 mOutOfDate = true;
95 }
96
97 ILayerItem* SharedLayer::getLayerItemByPoint(int _left, int _top) const
98 {
99 if (!mIsPick)
100 return nullptr;
101
102 if (mChildItem != nullptr)
103 {
104 ILayerItem* item = mChildItem->getLayerItemByPoint(_left, _top);
105 if (item != nullptr)
106 return item;
107 }
108 return nullptr;
109 }
110
111 IntPoint SharedLayer::getPosition(int _left, int _top) const
112 {
113 return {_left, _top};
114 }
115
116 void SharedLayer::renderToTarget(IRenderTarget* _target, bool _update)
117 {
118 if (mChildItem != nullptr)
119 mChildItem->renderToTarget(_target, _update);
120
121 mOutOfDate = false;
122 }
123
124 void SharedLayer::resizeView(const IntSize& _viewSize)
125 {
126 if (mChildItem != nullptr)
127 mChildItem->resizeView(_viewSize);
128
129 mViewSize = _viewSize;
130 }
131
132 EnumeratorILayerNode SharedLayer::getEnumerator() const
133 {
134 static VectorILayerNode nodes;
135 if (mChildItem == nullptr)
136 {
137 nodes.clear();
138 }
139 else
140 {
141 if (nodes.empty())
142 nodes.push_back(mChildItem);
143 else
144 nodes[0] = mChildItem;
145 }
146
147 return EnumeratorILayerNode(nodes);
148 }
149
150 size_t SharedLayer::getLayerNodeCount() const
151 {
152 return mChildItem == nullptr ? 0 : 1;
153 }
154
155 ILayerNode* SharedLayer::getLayerNodeAt(size_t _index) const
156 {
157 size_t count = getLayerNodeCount();
158 MYGUI_ASSERT_RANGE(_index, count, "SharedLayer::getLayerNodeAt");
159
160 return mChildItem;
161 }
162
163 const IntSize& SharedLayer::getSize() const
164 {
165 return mViewSize;
166 }
167
168 bool SharedLayer::isOutOfDate() const
169 {
170 if (mChildItem->isOutOfDate())
171 return true;
172
173 return mOutOfDate;
174 }
175
176} // namespace MyGUI
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_Precompiled.h
MyGUI_RenderManager.h
MyGUI_SharedLayer.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::ILayerNode
Definition MyGUI_ILayerNode.h:29
MyGUI::ILayerNode::getParent
virtual ILayerNode * getParent() const =0
MyGUI::ILayerNode::upChildItemNode
virtual void upChildItemNode(ILayerNode *_item)=0
MyGUI::IRenderTarget
Definition MyGUI_IRenderTarget.h:21
MyGUI::RenderManager::getViewSize
virtual const IntSize & getViewSize() const =0
MyGUI::RenderManager::getInstance
static RenderManager & getInstance()
MyGUI::SharedLayer::destroyChildItemNode
void destroyChildItemNode(ILayerNode *_item) override
Definition MyGUI_SharedLayer.cpp:68
MyGUI::SharedLayer::mViewSize
IntSize mViewSize
Definition MyGUI_SharedLayer.h:63
MyGUI::SharedLayer::mChildItem
SharedLayerNode * mChildItem
Definition MyGUI_SharedLayer.h:61
MyGUI::SharedLayer::getEnumerator
EnumeratorILayerNode getEnumerator() const override
Definition MyGUI_SharedLayer.cpp:132
MyGUI::SharedLayer::deserialization
void deserialization(xml::ElementPtr _node, Version _version) override
Definition MyGUI_SharedLayer.cpp:27
MyGUI::SharedLayer::setPick
void setPick(bool _pick)
Definition MyGUI_SharedLayer.cpp:51
MyGUI::SharedLayer::getLayerNodeAt
ILayerNode * getLayerNodeAt(size_t _index) const override
Definition MyGUI_SharedLayer.cpp:155
MyGUI::SharedLayer::renderToTarget
void renderToTarget(IRenderTarget *_target, bool _update) override
Definition MyGUI_SharedLayer.cpp:116
MyGUI::SharedLayer::isOutOfDate
bool isOutOfDate() const
Definition MyGUI_SharedLayer.cpp:168
MyGUI::SharedLayer::createChildItemNode
ILayerNode * createChildItemNode() override
Definition MyGUI_SharedLayer.cpp:56
MyGUI::SharedLayer::getPosition
IntPoint getPosition(int _left, int _top) const override
Definition MyGUI_SharedLayer.cpp:111
MyGUI::SharedLayer::~SharedLayer
~SharedLayer() override
Definition MyGUI_SharedLayer.cpp:21
MyGUI::SharedLayer::upChildItemNode
void upChildItemNode(ILayerNode *_item) override
Definition MyGUI_SharedLayer.cpp:87
MyGUI::SharedLayer::getLayerItemByPoint
ILayerItem * getLayerItemByPoint(int _left, int _top) const override
Definition MyGUI_SharedLayer.cpp:97
MyGUI::SharedLayer::mOutOfDate
bool mOutOfDate
Definition MyGUI_SharedLayer.h:62
MyGUI::SharedLayer::mIsPick
bool mIsPick
Definition MyGUI_SharedLayer.h:60
MyGUI::SharedLayer::getLayerNodeCount
size_t getLayerNodeCount() const override
Definition MyGUI_SharedLayer.cpp:150
MyGUI::SharedLayer::getSize
const IntSize & getSize() const override
Definition MyGUI_SharedLayer.cpp:163
MyGUI::SharedLayer::SharedLayer
SharedLayer()
Definition MyGUI_SharedLayer.cpp:16
MyGUI::SharedLayer::resizeView
void resizeView(const IntSize &_viewSize) override
Definition MyGUI_SharedLayer.cpp:124
MyGUI::SharedLayerNode
Definition MyGUI_SharedLayerNode.h:17
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::VectorILayerNode
std::vector< ILayerNode * > VectorILayerNode
Definition MyGUI_ILayerNode.h:25
MyGUI::IntSize
types::TSize< int > IntSize
Definition MyGUI_Types.h:30