MyGUI 3.2.0

- Main Page
- Related Pages
- Namespaces
- Data Structures
- Files
- Examples

- File List
- Globals

MyGUI_ResourceSkin.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 #include "MyGUI_Precompiled.h"
23 #include "MyGUI_ResourceSkin.h"
24 #include "MyGUI_FactoryManager.h"
25 #include "MyGUI_LanguageManager.h"
26
27 namespace MyGUI
28 {
29
30 ResourceSkin::ResourceSkin()
31 {
32 }
33
34 ResourceSkin::~ResourceSkin()
35 {
36 for (MapWidgetStateInfo::iterator item = mStates.begin(); item != mStates.end(); ++ item)
37 {
38 for (VectorStateInfo::iterator info = (*item).second.begin(); info != (*item).second.end(); ++ info)
39 delete (*info);
40 }
41 mStates.clear();
42 }
43
44 void ResourceSkin::deserialization(xml::ElementPtr _node, Version _version)
45 {
46 Base::deserialization(_node, _version);
47
48 // парсим атрибуты скина
49 std::string name, texture, tmp;
50 IntSize size;
51 _node->findAttribute("name", name);
52 _node->findAttribute("texture", texture);
53 if (_node->findAttribute("size", tmp)) size = IntSize::parse(tmp);
54
55 LanguageManager& localizator = LanguageManager::getInstance();
56
57 // вспомогательный класс для биндинга сабскинов
58 SubWidgetBinding bind;
59
60 // поддержка замены тегов в скинах
61 if (_version >= Version(1, 1))
62 {
63 texture = localizator.replaceTags(texture);
64 }
65
66 setInfo(size, texture);
67
68 // проверяем маску
69 if (_node->findAttribute("mask", tmp))
70 addProperty("MaskPick", tmp);
71
72 // берем детей и крутимся, цикл с саб скинами
73 xml::ElementEnumerator basis = _node->getElementEnumerator();
74 while (basis.next())
75 {
76 if (basis->getName() == "Property")
77 {
78 // загружаем свойства
79 std::string key, value;
80 if (!basis->findAttribute("key", key)) continue;
81 if (!basis->findAttribute("value", value)) continue;
82
83 // поддержка замены тегов в скинах
84 if (_version >= Version(1, 1))
85 {
86 value = localizator.replaceTags(value);
87 }
88
89 // добавляем свойство
90 addProperty(key, value);
91 }
92 else if (basis->getName() == "Child")
93 {
94 ChildSkinInfo child(
95 basis->findAttribute("type"),
96 WidgetStyle::parse(basis->findAttribute("style")),
97 basis->findAttribute("skin"),
98 IntCoord::parse(basis->findAttribute("offset")),
99 Align::parse(basis->findAttribute("align")),
100 basis->findAttribute("layer"),
101 basis->findAttribute("name")
102 );
103
104 xml::ElementEnumerator child_params = basis->getElementEnumerator();
105 while (child_params.next("Property"))
106 child.addParam(child_params->findAttribute("key"), child_params->findAttribute("value"));
107
108 addChild(child);
109 //continue;
110 }
111 else if (basis->getName() == "BasisSkin")
112 {
113 // парсим атрибуты
114 std::string basisSkinType, tmp_str;
115 IntCoord offset;
116 Align align = Align::Default;
117 basis->findAttribute("type", basisSkinType);
118 if (basis->findAttribute("offset", tmp_str)) offset = IntCoord::parse(tmp_str);
119 if (basis->findAttribute("align", tmp_str)) align = Align::parse(tmp_str);
120
121 bind.create(offset, align, basisSkinType);
122
123 // берем детей и крутимся, цикл со стейтами
124 xml::ElementEnumerator state = basis->getElementEnumerator();
125
126 // проверяем на новый формат стейтов
127 bool new_format = false;
128 // если версия меньше 1.0 то переименовываем стейты
129 if (_version < Version(1, 0))
130 {
131 while (state.next())
132 {
133 if (state->getName() == "State")
134 {
135 const std::string& name_state = state->findAttribute("name");
136 if ((name_state == "normal_checked") || (state->findAttribute("name") == "normal_check"))
137 {
138 new_format = true;
139 break;
140 }
141 }
142 }
143 // обновляем
144 state = basis->getElementEnumerator();
145 }
146
147 while (state.next())
148 {
149 if (state->getName() == "State")
150 {
151 // парсим атрибуты стейта
152 std::string basisStateName;
153 state->findAttribute("name", basisStateName);
154
155 // если версия меньше 1.0 то переименовываем стейты
156 if (_version < Version(1, 0))
157 {
158 // это обсолет новых типов
159 if (basisStateName == "disable_check") basisStateName = "disabled_checked";
160 else if (basisStateName == "normal_check") basisStateName = "normal_checked";
161 else if (basisStateName == "active_check") basisStateName = "highlighted_checked";
162 else if (basisStateName == "pressed_check") basisStateName = "pushed_checked";
163 else if (basisStateName == "disable") basisStateName = "disabled";
164 else if (basisStateName == "active") basisStateName = "highlighted";
165 else if (basisStateName == "select") basisStateName = "pushed";
166 else if (basisStateName == "pressed")
167 {
168 if (new_format) basisStateName = "pushed";
169 else basisStateName = "normal_checked";
170 }
171 }
172
173 // конвертируем инфу о стейте
174 IStateInfo* data = nullptr;
175 IObject* object = FactoryManager::getInstance().createObject("BasisSkin/State", basisSkinType);
176 if (object != nullptr)
177 {
178 data = object->castType<IStateInfo>();
179 data->deserialization(state.current(), _version);
180 }
181
182 // добавляем инфо о стайте
183 bind.add(basisStateName, data, name);
184 }
185 }
186
187 // теперь всё вместе добавляем в скин
188 addInfo(bind);
189 }
190
191 }
192 }
193
194 void ResourceSkin::setInfo(const IntSize& _size, const std::string& _texture)
195 {
196 mSize = _size;
197 mTexture = _texture;
198 }
199
200 void ResourceSkin::addInfo(const SubWidgetBinding& _bind)
201 {
202 checkState(_bind.mStates);
203 mBasis.push_back(SubWidgetInfo(_bind.mType, _bind.mOffset, _bind.mAlign));
204 checkBasis();
205 fillState(_bind.mStates, mBasis.size() - 1);
206 }
207
208 void ResourceSkin::addProperty(const std::string& _key, const std::string& _value)
209 {
210 mProperties[_key] = _value;
211 }
212
213 void ResourceSkin::addChild(const ChildSkinInfo& _child)
214 {
215 mChilds.push_back(_child);
216 }
217
218 void ResourceSkin::clear()
219 {
220 for (MapWidgetStateInfo::iterator iter = mStates.begin(); iter != mStates.end(); ++iter)
221 {
222 for (VectorStateInfo::iterator iter2 = iter->second.begin(); iter2 != iter->second.end(); ++iter2)
223 {
224 delete *iter2;
225 }
226 }
227 }
228
229 void ResourceSkin::checkState(const MapStateInfo& _states)
230 {
231 for (MapStateInfo::const_iterator iter = _states.begin(); iter != _states.end(); ++iter)
232 {
233 checkState(iter->first);
234 }
235 }
236
237 void ResourceSkin::checkState(const std::string& _name)
238 {
239 // ищем такой же ключ
240 MapWidgetStateInfo::const_iterator iter = mStates.find(_name);
241 if (iter == mStates.end())
242 {
243 // добавляем новый стейт
244 mStates[_name] = VectorStateInfo();
245 }
246 }
247
248 void ResourceSkin::checkBasis()
249 {
250 // и увеличиваем размер смещений по колличеству сабвиджетов
251 for (MapWidgetStateInfo::iterator iter = mStates.begin(); iter != mStates.end(); ++iter)
252 {
253 iter->second.resize(mBasis.size());
254 }
255 }
256
257 void ResourceSkin::fillState(const MapStateInfo& _states, size_t _index)
258 {
259 for (MapStateInfo::const_iterator iter = _states.begin(); iter != _states.end(); ++iter)
260 {
261 mStates[iter->first][_index] = iter->second;
262 }
263 }
264
265 const IntSize& ResourceSkin::getSize() const
266 {
267 return mSize;
268 }
269
270 const std::string& ResourceSkin::getTextureName() const
271 {
272 return mTexture;
273 }
274
275 const VectorSubWidgetInfo& ResourceSkin::getBasisInfo() const
276 {
277 return mBasis;
278 }
279
280 const MapWidgetStateInfo& ResourceSkin::getStateInfo() const
281 {
282 return mStates;
283 }
284
285 const MapString& ResourceSkin::getProperties() const
286 {
287 return mProperties;
288 }
289
290 const VectorChildSkinInfo& ResourceSkin::getChild() const
291 {
292 return mChilds;
293 }
294
295 const std::string& ResourceSkin::getSkinName() const
296 {
297 return mSkinName;
298 }
299
300 } // namespace MyGUI
MyGUI::types::TCoord< int >
MyGUI_FactoryManager.h
MyGUI::MapWidgetStateInfo
std::map< std::string, VectorStateInfo > MapWidgetStateInfo
Definition: MyGUI_IStateInfo.h:42
MyGUI::ResourceSkin::getProperties
const MapString & getProperties() const
Definition: MyGUI_ResourceSkin.cpp:285
MyGUI_Precompiled.h
MyGUI::ISerializable::deserialization
virtual void deserialization(xml::ElementPtr _node, Version _version)
Definition: MyGUI_ISerializable.h:43
MyGUI::IStateInfo
Definition: MyGUI_IStateInfo.h:31
MyGUI::types::TSize< int >
MyGUI::ResourceSkin::getTextureName
const std::string & getTextureName() const
Definition: MyGUI_ResourceSkin.cpp:270
MyGUI::Singleton< LanguageManager >::getInstance
static LanguageManager & getInstance()
Definition: MyGUI_Singleton.h:53
MyGUI::LanguageManager
Definition: MyGUI_LanguageManager.h:35
MyGUI::WidgetStyle::parse
static WidgetStyle parse(const std::string &_value)
Definition: MyGUI_WidgetStyle.h:51
MyGUI::ChildSkinInfo
Definition: MyGUI_ChildSkinInfo.h:31
MyGUI::xml::Element::findAttribute
bool findAttribute(const std::string &_name, std::string &_value)
Definition: MyGUI_XmlDocument.cpp:261
MyGUI::Align::parse
static Align parse(const std::string &_value)
Definition: MyGUI_Align.h:142
MyGUI::ResourceSkin::getChild
const VectorChildSkinInfo & getChild() const
Definition: MyGUI_ResourceSkin.cpp:290
MyGUI::ResourceSkin::getSize
const IntSize & getSize() const
Definition: MyGUI_ResourceSkin.cpp:265
MyGUI::SubWidgetBinding::add
void add(const std::string &_name, IStateInfo *_data, const std::string &_skin)
Definition: MyGUI_SubWidgetBinding.cpp:53
MyGUI::types::TSize< int >::parse
static TSize< int > parse(const std::string &_value)
Definition: MyGUI_TSize.h:135
MyGUI::ResourceSkin::deserialization
virtual void deserialization(xml::ElementPtr _node, Version _version)
Definition: MyGUI_ResourceSkin.cpp:44
MyGUI_LanguageManager.h
MyGUI::Align::Default
Definition: MyGUI_Align.h:51
MyGUI::xml::ElementEnumerator
Definition: MyGUI_XmlDocument.h:124
MyGUI::xml::ElementEnumerator::next
bool next()
Definition: MyGUI_XmlDocument.cpp:115
MyGUI::ResourceSkin::getBasisInfo
const VectorSubWidgetInfo & getBasisInfo() const
Definition: MyGUI_ResourceSkin.cpp:275
MyGUI::ResourceSkin::~ResourceSkin
virtual ~ResourceSkin()
Definition: MyGUI_ResourceSkin.cpp:34
MyGUI::MapStateInfo
std::map< std::string, IStateInfo * > MapStateInfo
Definition: MyGUI_IStateInfo.h:41
MyGUI::VectorStateInfo
std::vector< IStateInfo * > VectorStateInfo
Definition: MyGUI_IStateInfo.h:40
MyGUI::ResourceSkin::getStateInfo
const MapWidgetStateInfo & getStateInfo() const
Definition: MyGUI_ResourceSkin.cpp:280
MyGUI::MapString
std::map< std::string, std::string > MapString
Definition: MyGUI_Types.h:53
MyGUI::xml::Element
Definition: MyGUI_XmlDocument.h:168
MyGUI_ResourceSkin.h
MyGUI::VectorSubWidgetInfo
std::vector< SubWidgetInfo > VectorSubWidgetInfo
Definition: MyGUI_SubWidgetInfo.h:47
MyGUI::IObject::castType
Type * castType(bool _throw=true)
Definition: MyGUI_IObject.h:33
MyGUI::Version
Definition: MyGUI_Version.h:32
MyGUI::ResourceSkin::ResourceSkin
ResourceSkin()
Definition: MyGUI_ResourceSkin.cpp:30
MyGUI::IObject
Definition: MyGUI_IObject.h:31
MyGUI::xml::Element::getElementEnumerator
ElementEnumerator getElementEnumerator()
Definition: MyGUI_XmlDocument.cpp:367
MyGUI::ResourceSkin::getSkinName
const std::string & getSkinName() const
Definition: MyGUI_ResourceSkin.cpp:295
MyGUI::xml::Element::getName
const std::string & getName() const
Definition: MyGUI_XmlDocument.cpp:347
MyGUI::LanguageManager::replaceTags
UString replaceTags(const UString &_line)
Definition: MyGUI_LanguageManager.cpp:210
MyGUI::Align
Definition: MyGUI_Align.h:34
MyGUI::SubWidgetBinding::create
void create(const IntCoord &_coord, Align _aligin, const std::string &_type)
Definition: MyGUI_SubWidgetBinding.cpp:38
MyGUI::VectorChildSkinInfo
std::vector< ChildSkinInfo > VectorChildSkinInfo
Definition: MyGUI_ChildSkinInfo.h:47
MyGUI::SubWidgetBinding
Definition: MyGUI_SubWidgetBinding.h:32
MyGUI::types::TCoord< int >::parse
static TCoord< int > parse(const std::string &_value)
Definition: MyGUI_TCoord.h:222
MyGUI::FactoryManager::createObject
IObject * createObject(const std::string &_category, const std::string &_type)
Definition: MyGUI_FactoryManager.cpp:87
MyGUI::xml::ElementEnumerator::current
ElementPtr current()
Definition: MyGUI_XmlDocument.cpp:146