MyGUI 3.4.2
MyGUI_ResourceLayout.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"
10#include "MyGUI_RenderManager.h"
12#include "MyGUI_LayoutManager.h"
13#include "MyGUI_Widget.h"
14#include "MyGUI_Gui.h"
15
16namespace MyGUI
17{
18
20 {
21 }
22
24 {
25 // FIXME hardcoded version
26 deserialization(_node, Version(1, 0, 0));
28 }
29
31 {
33
34 mLayoutData.clear();
35
36 xml::ElementEnumerator widget = _node->getElementEnumerator();
37 while (widget.next("Widget"))
38 mLayoutData.push_back(parseWidget(widget));
39 }
40
42 {
44
45 std::string tmp;
46
47 _widget->findAttribute("type", widgetInfo.type);
48 _widget->findAttribute("skin", widgetInfo.skin);
49 _widget->findAttribute("layer", widgetInfo.layer);
50
51 if (_widget->findAttribute("align", tmp)) widgetInfo.align = Align::parse(tmp);
52
53 _widget->findAttribute("name", widgetInfo.name);
54
55 if (_widget->findAttribute("style", tmp)) widgetInfo.style = WidgetStyle::parse(tmp);
56
57 IntCoord coord;
58 if (_widget->findAttribute("position", tmp))
59 {
60 widgetInfo.intCoord = IntCoord::parse(tmp);
61 widgetInfo.positionType = WidgetInfo::Pixels;
62 }
63 else if (_widget->findAttribute("position_real", tmp))
64 {
65 widgetInfo.floatCoord = FloatCoord::parse(tmp);
66 widgetInfo.positionType = WidgetInfo::Relative;
67 }
68
69 // берем детей и крутимся
70 xml::ElementEnumerator node = _widget->getElementEnumerator();
71 while (node.next())
72 {
73 if (node->getName() == "Widget")
74 {
75 widgetInfo.childWidgetsInfo.push_back(parseWidget(node));
76 }
77 else if (node->getName() == "Property")
78 {
79 widgetInfo.properties.push_back(PairString(node->findAttribute("key"), node->findAttribute("value")));
80 }
81 else if (node->getName() == "UserString")
82 {
83 widgetInfo.userStrings[node->findAttribute("key")] = node->findAttribute("value");
84 }
85 else if (node->getName() == "Controller")
86 {
88 controllerInfo.type = node->findAttribute("type");
89
90 xml::ElementEnumerator prop = node->getElementEnumerator();
91 while (prop.next("Property"))
92 controllerInfo.properties[prop->findAttribute("key")] = prop->findAttribute("value");
93
94 widgetInfo.controllers.push_back(controllerInfo);
95 }
96 }
97
98 return widgetInfo;
99 }
100
102 {
104
105 for (VectorWidgetInfo::iterator iter = mLayoutData.begin(); iter != mLayoutData.end(); ++iter)
106 {
108 widgets.push_back(widget);
109 }
110
111 return widgets;
112 }
113
115 {
116 std::string widgetName = _widgetInfo.name;
117 WidgetStyle style = _widgetInfo.style;
118 std::string widgetLayer = _widgetInfo.layer;
119
120 if (!widgetName.empty()) widgetName = _prefix + widgetName;
121
122 if (_parent != nullptr && style != WidgetStyle::Popup) widgetLayer.clear();
123 if (_parent == nullptr && widgetLayer.empty())
124 {
125 MYGUI_LOG(Warning, "Root widget's layer is not specified, widget won't be visible. Specify layer or parent or attach it to another widget after load." << " [" << LayoutManager::getInstance().getCurrentLayout() << "]");
126 }
127
128 IntCoord coord;
129 if (_widgetInfo.positionType == WidgetInfo::Pixels) coord = _widgetInfo.intCoord;
130 else if (_widgetInfo.positionType == WidgetInfo::Relative)
131 {
132 if (_parent == nullptr || style == WidgetStyle::Popup)
134 else
135 coord = CoordConverter::convertFromRelative(_widgetInfo.floatCoord, _parent->getClientCoord().size());
136 }
137
138 Widget* wid;
139 if (nullptr == _parent)
140 wid = Gui::getInstance().createWidgetT(_widgetInfo.type, _widgetInfo.skin, coord, _widgetInfo.align, widgetLayer, widgetName);
141 else if (_template)
142 wid = _parent->_createSkinWidget(style, _widgetInfo.type, _widgetInfo.skin, coord, _widgetInfo.align, widgetLayer, widgetName);
143 else
144 wid = _parent->createWidgetT(style, _widgetInfo.type, _widgetInfo.skin, coord, _widgetInfo.align, widgetLayer, widgetName);
145
146 for (VectorStringPairs::const_iterator iter = _widgetInfo.properties.begin(); iter != _widgetInfo.properties.end(); ++iter)
147 {
148 wid->setProperty(iter->first, iter->second);
149 }
150
151 for (MapString::const_iterator iter = _widgetInfo.userStrings.begin(); iter != _widgetInfo.userStrings.end(); ++iter)
152 {
153 wid->setUserString(iter->first, iter->second);
154 if (!_template)
155 LayoutManager::getInstance().eventAddUserString(wid, iter->first, iter->second);
156 }
157
158 for (VectorWidgetInfo::const_iterator iter = _widgetInfo.childWidgetsInfo.begin(); iter != _widgetInfo.childWidgetsInfo.end(); ++iter)
159 {
161 }
162
163 for (std::vector<ControllerInfo>::const_iterator iter = _widgetInfo.controllers.begin(); iter != _widgetInfo.controllers.end(); ++iter)
164 {
166 if (item)
167 {
168 for (MapString::const_iterator iterProp = iter->properties.begin(); iterProp != iter->properties.end(); ++iterProp)
169 {
170 item->setProperty(iterProp->first, iterProp->second);
171 }
173 }
174 else
175 {
176 MYGUI_LOG(Warning, "Controller '" << iter->type << "' not found");
177 }
178 }
179
180 LayoutManager::getInstance().eventCreateWidget(wid, _widgetInfo);
181
182 return wid;
183 }
184
186 {
187 return mLayoutData;
188 }
189
190} // namespace MyGUI
#define MYGUI_LOG(level, text)
virtual void setProperty(const std::string &, const std::string &)
static ControllerManager & getInstance()
static IntCoord convertFromRelative(const FloatCoord &_coord, const IntSize &_view)
static Gui & getInstance()
std::string mResourceName
static LayoutManager & getInstance()
static RenderManager & getInstance()
void deserialization(xml::ElementPtr _node, Version _version) override
WidgetInfo parseWidget(xml::ElementEnumerator &_widget)
const VectorWidgetInfo & getLayoutData() const
Widget * createWidget(const WidgetInfo &_widgetInfo, const std::string &_prefix="", Widget *_parent=nullptr, bool _template=false)
VectorWidgetPtr createLayout(const std::string &_prefix="", Widget *_parent=nullptr)
widget description should be here.
std::pair< std::string, std::string > PairString
Definition MyGUI_Types.h:42
std::vector< WidgetInfo > VectorWidgetInfo
std::vector< Widget * > VectorWidgetPtr
static Align parse(const std::string &_value)
static WidgetStyle parse(const std::string &_value)
static TCoord< int > parse(const std::string &_value)