MyGUI  3.0.1
MyGUI_SharedLayer.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_SharedLayer.h"
27 #include "MyGUI_LayerNode.h"
28 #include "MyGUI_RenderManager.h"
29 
30 namespace MyGUI
31 {
32 
34  mIsPick(false),
35  mChildItem(nullptr)
36  {
37  }
38 
40  {
41  MYGUI_ASSERT(mChildItem == nullptr, "Layer '" << getName() << "' must be empty before destroy");
42  }
43 
45  {
46  mName = _node->findAttribute("name");
47  if (_version >= Version(1, 2))
48  {
50  while (propert.next("Property"))
51  {
52  const std::string& key = propert->findAttribute("key");
53  const std::string& value = propert->findAttribute("value");
54  if (key == "Pick") mIsPick = utility::parseValue<bool>(value);
55  }
56  }
57  else
58  {
59  mIsPick = utility::parseBool(_version < Version(1, 0) ? _node->findAttribute("peek") : _node->findAttribute("pick"));
60  }
61  }
62 
64  {
65  if (mChildItem == nullptr)
66  {
67  mChildItem = new SharedLayerNode(this);
68  }
69 
71  return mChildItem;
72  }
73 
75  {
76  // айтем рутовый, мы удаляем
77  if (mChildItem == _item)
78  {
80  if (0 == mChildItem->countUsing())
81  {
82  delete mChildItem;
83  mChildItem = nullptr;
84  }
85  return;
86  }
87  //MYGUI_EXCEPT("item node not found");
88  }
89 
91  {
92  // если есть отец, то пусть сам рулит
93  ILayerNode * parent = _item->getParent();
94  if (parent != nullptr)
95  {
96  parent->upChildItemNode(_item);
97  }
98  }
99 
101  {
102  if (!mIsPick) return nullptr;
103  if (mChildItem != nullptr)
104  {
105  ILayerItem * item = mChildItem->getLayerItemByPoint(_left, _top);
106  if (item != nullptr) return item;
107  }
108  return nullptr;
109  }
110 
111  IntPoint SharedLayer::getPosition(int _left, int _top) const
112  {
113  return IntPoint(_left, _top);
114  }
115 
116  void SharedLayer::renderToTarget(IRenderTarget* _target, bool _update)
117  {
118  if (mChildItem != nullptr) mChildItem->renderToTarget(_target, _update);
119  }
120 
122  {
123  static VectorILayerNode nodes;
124  if (mChildItem == nullptr)
125  {
126  nodes.clear();
127  }
128  else
129  {
130  if (nodes.empty()) nodes.push_back(mChildItem);
131  else nodes[0] = mChildItem;
132  }
133 
134  return EnumeratorILayerNode(nodes);
135  }
136 
138  {
139  static const char* spacer = " ";
140  MYGUI_LOG(Info, spacer);
141  MYGUI_LOG(Info, "Layer name='" << getName() << "'" << " type='" << getTypeName() << "'" << spacer);
142  MYGUI_LOG(Info, "Count root nodes : " << (mChildItem == nullptr ? 0 : 1) << spacer);
143 
144  if (mChildItem != nullptr)
145  {
147  }
148  }
149 
151  {
153  }
154 
155 } // namespace MyGUI