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