MyGUI  3.0.1
MyGUI_OverlappedLayer.cpp
Go to the documentation of this file.
1 
7 /*
8  This file is part of MyGUI.
9 
10  MyGUI is free software: you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  MyGUI is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
22 */
23 
24 #include "MyGUI_Precompiled.h"
25 #include "MyGUI_LayerItem.h"
26 #include "MyGUI_OverlappedLayer.h"
27 #include "MyGUI_LayerNode.h"
28 #include "MyGUI_RenderManager.h"
29 
30 namespace MyGUI
31 {
32 
34  mIsPick(false)
35  {
36  }
37 
39  {
40  MYGUI_ASSERT(mChildItems.empty(), "Layer '" << getName() << "' must be empty before destroy");
41  }
42 
44  {
45  mName = _node->findAttribute("name");
46  if (_version >= Version(1, 2))
47  {
49  while (propert.next("Property"))
50  {
51  const std::string& key = propert->findAttribute("key");
52  const std::string& value = propert->findAttribute("value");
53  if (key == "Pick") mIsPick = utility::parseValue<bool>(value);
54  }
55  }
56  else
57  {
58  mIsPick = utility::parseBool(_version < Version(1, 0) ? _node->findAttribute("peek") : _node->findAttribute("pick"));
59  }
60  }
61 
63  {
64  // создаем рутовый айтем
65  ILayerNode * node = new LayerNode(this);
66  mChildItems.push_back(node);
67 
68  return node;
69  }
70 
72  {
73  // если есть отец, то русть сам и удаляет
74  ILayerNode * parent = _item->getParent();
75  if (parent)
76  {
77  parent->destroyChildItemNode(_item);
78  return;
79  }
80 
81  // айтем рутовый, мы удаляем
82  for (VectorILayerNode::iterator iter=mChildItems.begin(); iter!=mChildItems.end(); ++iter)
83  {
84  if ((*iter) == _item)
85  {
86  delete _item;
87  mChildItems.erase(iter);
88  return;
89  }
90  }
91  MYGUI_EXCEPT("item node not found");
92  }
93 
95  {
96  // если есть отец, то пусть сам рулит
97  ILayerNode* parent = _item->getParent();
98  if (parent != nullptr)
99  {
100  parent->upChildItemNode(_item);
101  return;
102  }
103 
104  if ((2 > mChildItems.size()) || (mChildItems.back() == _item)) return;
105  for (VectorILayerNode::iterator iter=mChildItems.begin(); iter!=mChildItems.end(); ++iter)
106  {
107  if ((*iter) == _item)
108  {
109  mChildItems.erase(iter);
110  mChildItems.push_back(_item);
111  return;
112  }
113  }
114 
115  MYGUI_EXCEPT("item node not found");
116  }
117 
119  {
120  if (!mIsPick) return nullptr;
121  VectorILayerNode::reverse_iterator iter = mChildItems.rbegin();
122  while (iter != mChildItems.rend())
123  {
124  ILayerItem * item = (*iter)->getLayerItemByPoint(_left, _top);
125  if (item != nullptr) return item;
126  ++iter;
127  }
128  return nullptr;
129  }
130 
131  IntPoint OverlappedLayer::getPosition(int _left, int _top) const
132  {
133  return IntPoint(_left, _top);
134  }
135 
136  void OverlappedLayer::renderToTarget(IRenderTarget* _target, bool _update)
137  {
138  for (VectorILayerNode::iterator iter=mChildItems.begin(); iter!=mChildItems.end(); ++iter)
139  {
140  (*iter)->renderToTarget(_target, _update);
141  }
142  }
143 
145  {
147  }
148 
150  {
151  static const char* spacer = " ";
152  MYGUI_LOG(Info, spacer);
153  MYGUI_LOG(Info, "Layer name='" << getName() << "'" << " type='" << getTypeName() << "'" << spacer);
154  MYGUI_LOG(Info, "Count root nodes : " << mChildItems.size() << spacer);
155 
156  for (VectorILayerNode::iterator iter=mChildItems.begin(); iter!=mChildItems.end(); ++iter)
157  {
158  (*iter)->dumpStatisticToLog(0);
159  }
160  }
161 
163  {
165  }
166 
167 } // namespace MyGUI