MyGUI  3.2.0
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 
33  mIsPick(false),
34  mChildItem(nullptr),
35  mOutOfDate(false)
36  {
38  }
39 
41  {
42  MYGUI_ASSERT(mChildItem == nullptr, "Layer '" << getName() << "' must be empty before destroy");
43  }
44 
46  {
47  mName = _node->findAttribute("name");
48  if (_version >= Version(1, 2))
49  {
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 
70  {
71  if (mChildItem == nullptr)
72  mChildItem = new SharedLayerNode(this);
73 
75 
76  mOutOfDate = true;
77 
78  return mChildItem;
79  }
80 
82  {
83  // айтем рутовый, мы удаляем
84  if (mChildItem == _item)
85  {
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 
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 
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 
164  {
165  return mViewSize;
166  }
167 
169  {
170  if (mChildItem->isOutOfDate())
171  return true;
172 
173  return mOutOfDate;
174  }
175 
176 } // namespace MyGUI
virtual ILayerNode * getParent() const =0
bool isOutOfDate() const
virtual void renderToTarget(IRenderTarget *_target, bool _update)
const std::string & getName() const
Definition: MyGUI_ILayer.h:46
virtual void destroyChildItemNode(ILayerNode *_node)
static RenderManager & getInstance()
virtual void upChildItemNode(ILayerNode *_node)=0
std::vector< ILayerNode * > VectorILayerNode
bool findAttribute(const std::string &_name, std::string &_value)
#define nullptr
virtual const IntSize & getViewSize() const =0
virtual ILayerItem * getLayerItemByPoint(int _left, int _top) const
virtual void renderToTarget(IRenderTarget *_target, bool _update)
virtual ILayerNode * createChildItemNode()
virtual ILayerItem * getLayerItemByPoint(int _left, int _top) const
std::string mName
Definition: MyGUI_ILayer.h:77
SharedLayerNode * mChildItem
virtual const IntSize & getSize() const
virtual IntPoint getPosition(int _left, int _top) const
#define MYGUI_ASSERT(exp, dest)
virtual EnumeratorILayerNode getEnumerator() const
virtual void deserialization(xml::ElementPtr _node, Version _version)
virtual void resizeView(const IntSize &_viewSize)
Enumerator< VectorILayerNode > EnumeratorILayerNode
bool parseBool(const std::string &_value)
virtual void upChildItemNode(ILayerNode *_node)
virtual void resizeView(const IntSize &_viewSize)
ElementEnumerator getElementEnumerator()
types::TPoint< int > IntPoint
Definition: MyGUI_Types.h:41