MyGUI 3.2.0

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

- File List
- Globals

MyGUI_SharedLayer.cpp
Go to the documentation of this file.
1
6 /*
7 This file is part of MyGUI.
8
9 MyGUI is free software: you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 MyGUI is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public License
20 along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23 #include "MyGUI_Precompiled.h"
24 #include "MyGUI_LayerItem.h"
25 #include "MyGUI_SharedLayer.h"
26 #include "MyGUI_LayerNode.h"
27 #include "MyGUI_RenderManager.h"
28
29 namespace MyGUI
30 {
31
32 SharedLayer::SharedLayer() :
33 mIsPick(false),
34 mChildItem(nullptr),
35 mOutOfDate(false)
36 {
37 mViewSize = RenderManager::getInstance().getViewSize();
38 }
39
40 SharedLayer::~SharedLayer()
41 {
42 MYGUI_ASSERT(mChildItem == nullptr, "Layer '" << getName() << "' must be empty before destroy");
43 }
44
45 void SharedLayer::deserialization(xml::ElementPtr _node, Version _version)
46 {
47 mName = _node->findAttribute("name");
48 if (_version >= Version(1, 2))
49 {
50 MyGUI::xml::ElementEnumerator propert = _node->getElementEnumerator();
51 while (propert.next("Property"))
52 {
53 const std::string& key = propert->findAttribute("key");
54 const std::string& value = propert->findAttribute("value");
55 if (key == "Pick")
56 mIsPick = utility::parseValue<bool>(value);
57 }
58 }
59 else if (_version >= Version(1, 0))
60 {
61 mIsPick = utility::parseBool(_node->findAttribute("pick"));
62 }
63 else
64 {
65 mIsPick = utility::parseBool(_node->findAttribute("peek"));
66 }
67 }
68
69 ILayerNode* SharedLayer::createChildItemNode()
70 {
71 if (mChildItem == nullptr)
72 mChildItem = new SharedLayerNode(this);
73
74 mChildItem->addUsing();
75
76 mOutOfDate = true;
77
78 return mChildItem;
79 }
80
81 void SharedLayer::destroyChildItemNode(ILayerNode* _item)
82 {
83 // айтем рутовый, мы удаляем
84 if (mChildItem == _item)
85 {
86 mChildItem->removeUsing();
87 if (0 == mChildItem->countUsing())
88 {
89 delete mChildItem;
90 mChildItem = nullptr;
91 }
92
93 mOutOfDate = true;
94
95 return;
96 }
97 //MYGUI_EXCEPT("item node not found");
98 }
99
100 void SharedLayer::upChildItemNode(ILayerNode* _item)
101 {
102 // если есть отец, то пусть сам рулит
103 ILayerNode* parent = _item->getParent();
104 if (parent != nullptr)
105 parent->upChildItemNode(_item);
106
107 mOutOfDate = true;
108 }
109
110 ILayerItem* SharedLayer::getLayerItemByPoint(int _left, int _top) const
111 {
112 if (!mIsPick)
113 return nullptr;
114
115 if (mChildItem != nullptr)
116 {
117 ILayerItem* item = mChildItem->getLayerItemByPoint(_left, _top);
118 if (item != nullptr)
119 return item;
120 }
121 return nullptr;
122 }
123
124 IntPoint SharedLayer::getPosition(int _left, int _top) const
125 {
126 return IntPoint(_left, _top);
127 }
128
129 void SharedLayer::renderToTarget(IRenderTarget* _target, bool _update)
130 {
131 if (mChildItem != nullptr)
132 mChildItem->renderToTarget(_target, _update);
133
134 mOutOfDate = false;
135 }
136
137 void SharedLayer::resizeView(const IntSize& _viewSize)
138 {
139 if (mChildItem != nullptr)
140 mChildItem->resizeView(_viewSize);
141
142 mViewSize = _viewSize;
143 }
144
145 EnumeratorILayerNode SharedLayer::getEnumerator() const
146 {
147 static VectorILayerNode nodes;
148 if (mChildItem == nullptr)
149 {
150 nodes.clear();
151 }
152 else
153 {
154 if (nodes.empty())
155 nodes.push_back(mChildItem);
156 else
157 nodes[0] = mChildItem;
158 }
159
160 return EnumeratorILayerNode(nodes);
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::ILayerNode::getParent
virtual ILayerNode * getParent() const =0
MyGUI::types::TPoint< int >
MyGUI::ILayerNode
Definition: MyGUI_ILayerNode.h:42
MyGUI::LayerNode::isOutOfDate
bool isOutOfDate() const
Definition: MyGUI_LayerNode.cpp:325
MyGUI::LayerNode::renderToTarget
virtual void renderToTarget(IRenderTarget *_target, bool _update)
Definition: MyGUI_LayerNode.cpp:99
MyGUI::ILayer::getName
const std::string & getName() const
Definition: MyGUI_ILayer.h:46
MyGUI_Precompiled.h
MyGUI::SharedLayer::destroyChildItemNode
virtual void destroyChildItemNode(ILayerNode *_node)
Definition: MyGUI_SharedLayer.cpp:81
MyGUI::types::TSize< int >
MyGUI::Singleton< RenderManager >::getInstance
static RenderManager & getInstance()
Definition: MyGUI_Singleton.h:53
MyGUI::ILayerNode::upChildItemNode
virtual void upChildItemNode(ILayerNode *_node)=0
MyGUI::VectorILayerNode
std::vector< ILayerNode * > VectorILayerNode
Definition: MyGUI_ILayerNode.h:37
MyGUI::xml::Element::findAttribute
bool findAttribute(const std::string &_name, std::string &_value)
Definition: MyGUI_XmlDocument.cpp:261
MyGUI::SharedLayer::mIsPick
bool mIsPick
Definition: MyGUI_SharedLayer.h:70
nullptr
#define nullptr
Definition: MyGUI_Prerequest.h:47
MyGUI::RenderManager::getViewSize
virtual const IntSize & getViewSize() const =0
MyGUI::SharedLayer::~SharedLayer
virtual ~SharedLayer()
Definition: MyGUI_SharedLayer.cpp:40
MyGUI::SharedLayer::SharedLayer
SharedLayer()
Definition: MyGUI_SharedLayer.cpp:32
MyGUI::SharedLayer::mOutOfDate
bool mOutOfDate
Definition: MyGUI_SharedLayer.h:72
MyGUI::LayerNode::getLayerItemByPoint
virtual ILayerItem * getLayerItemByPoint(int _left, int _top) const
Definition: MyGUI_LayerNode.cpp:137
MyGUI::SharedLayerNode::addUsing
void addUsing()
Definition: MyGUI_SharedLayerNode.cpp:39
MyGUI::SharedLayer::renderToTarget
virtual void renderToTarget(IRenderTarget *_target, bool _update)
Definition: MyGUI_SharedLayer.cpp:129
MyGUI::SharedLayerNode::countUsing
size_t countUsing() const
Definition: MyGUI_SharedLayerNode.cpp:49
MyGUI::Enumerator
Definition: MyGUI_Enumerator.h:63
MyGUI::xml::ElementEnumerator
Definition: MyGUI_XmlDocument.h:124
MyGUI::SharedLayer::mViewSize
IntSize mViewSize
Definition: MyGUI_SharedLayer.h:73
MyGUI::SharedLayerNode
Definition: MyGUI_SharedLayerNode.h:31
MyGUI::SharedLayer::createChildItemNode
virtual ILayerNode * createChildItemNode()
Definition: MyGUI_SharedLayer.cpp:69
MyGUI::SharedLayer::getLayerItemByPoint
virtual ILayerItem * getLayerItemByPoint(int _left, int _top) const
Definition: MyGUI_SharedLayer.cpp:110
MyGUI_RenderManager.h
MyGUI::ILayer::mName
std::string mName
Definition: MyGUI_ILayer.h:77
MyGUI::SharedLayer::mChildItem
SharedLayerNode * mChildItem
Definition: MyGUI_SharedLayer.h:71
MyGUI::xml::ElementEnumerator::next
bool next()
Definition: MyGUI_XmlDocument.cpp:115
MyGUI::SharedLayer::getSize
virtual const IntSize & getSize() const
Definition: MyGUI_SharedLayer.cpp:163
MyGUI::SharedLayer::getPosition
virtual IntPoint getPosition(int _left, int _top) const
Definition: MyGUI_SharedLayer.cpp:124
MYGUI_ASSERT
#define MYGUI_ASSERT(exp, dest)
Definition: MyGUI_Diagnostic.h:58
MyGUI::SharedLayer::getEnumerator
virtual EnumeratorILayerNode getEnumerator() const
Definition: MyGUI_SharedLayer.cpp:145
MyGUI::IRenderTarget
Definition: MyGUI_IRenderTarget.h:35
MyGUI::SharedLayer::deserialization
virtual void deserialization(xml::ElementPtr _node, Version _version)
Definition: MyGUI_SharedLayer.cpp:45
MyGUI::SharedLayer::resizeView
virtual void resizeView(const IntSize &_viewSize)
Definition: MyGUI_SharedLayer.cpp:137
MyGUI_LayerItem.h
MyGUI::xml::Element
Definition: MyGUI_XmlDocument.h:168
MyGUI::Version
Definition: MyGUI_Version.h:32
MyGUI::SharedLayerNode::removeUsing
void removeUsing()
Definition: MyGUI_SharedLayerNode.cpp:44
MyGUI_SharedLayer.h
MyGUI::EnumeratorILayerNode
Enumerator< VectorILayerNode > EnumeratorILayerNode
Definition: MyGUI_ILayerNode.h:40
MyGUI::ILayerItem
Definition: MyGUI_ILayerItem.h:33
MyGUI_LayerNode.h
MyGUI::utility::parseBool
bool parseBool(const std::string &_value)
Definition: MyGUI_StringUtility.h:206
MyGUI::SharedLayer::upChildItemNode
virtual void upChildItemNode(ILayerNode *_node)
Definition: MyGUI_SharedLayer.cpp:100
MyGUI::LayerNode::resizeView
virtual void resizeView(const IntSize &_viewSize)
Definition: MyGUI_LayerNode.cpp:129
MyGUI::xml::Element::getElementEnumerator
ElementEnumerator getElementEnumerator()
Definition: MyGUI_XmlDocument.cpp:367
MyGUI::SharedLayer::isOutOfDate
bool isOutOfDate() const
Definition: MyGUI_SharedLayer.cpp:168
MyGUI::IntPoint
types::TPoint< int > IntPoint
Definition: MyGUI_Types.h:41