MyGUI 3.4.1
MyGUI_ResourceImageSet.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"
11#include "MyGUI_Constants.h"
12
13namespace MyGUI
14{
15
16 std::vector<IntPoint> ResourceImageSet::mFramesEmpty;
17
18 void ResourceImageSet::deserialization(xml::ElementPtr _node, Version _version)
19 {
20 Base::deserialization(_node, _version);
21
22 // берем детей и крутимся, основной цикл
23 xml::ElementEnumerator group_node = _node->getElementEnumerator();
24 while (group_node.next("Group"))
25 {
26 GroupImage group;
27 group.name = group_node->findAttribute("name");
28
29 group.texture = group_node->findAttribute("texture");
30 // tags replacement support for Skins
31 if (_version >= Version(1, 1))
32 {
33 group.texture = LanguageManager::getInstance().replaceTags(group.texture);
34 }
35
36 group.size = IntSize::parse(group_node->findAttribute("size"));
37
38 xml::ElementEnumerator index_node = group_node->getElementEnumerator();
39 while (index_node.next("Index"))
40 {
41 IndexImage index;
42 index.name = index_node->findAttribute("name");
43 index.rate = utility::parseFloat(index_node->findAttribute("rate"));
44
45 xml::ElementEnumerator frame_node = index_node->getElementEnumerator();
46 while (frame_node.next("Frame"))
47 {
48 size_t count = utility::parseSizeT(frame_node->findAttribute("count"));
49 const IntPoint& point = IntPoint::parse(frame_node->findAttribute("point"));
50 if ((count < 1) || (count > 256)) count = 1;
51 while (count > 0)
52 {
53 index.frames.push_back(point);
54 -- count;
55 }
56 }
57
58 group.indexes.push_back(index);
59 }
60
61 AddGroupImage(group);
62 }
63 }
64
65 ImageIndexInfo ResourceImageSet::getIndexInfo(const std::string& _group, const std::string& _index) const
66 {
67 size_t index_group = getGroupIndex(_group);
68 if (index_group != ITEM_NONE)
69 {
70 const GroupImage& group = mGroups[index_group];
71 size_t index_image = getImageIndex(group, _index);
72 if (index_image != ITEM_NONE)
73 {
74 const IndexImage& index = group.indexes[index_image];
75 return ImageIndexInfo(group.texture, group.size, index.rate, index.frames);
76 }
77 }
79 }
80
81 ImageIndexInfo ResourceImageSet::getIndexInfo(size_t _group, const std::string& _index) const
82 {
83 if (_group < mGroups.size())
84 {
85 const GroupImage& group = mGroups[_group];
86 size_t index_image = getImageIndex(group, _index);
87 if (index_image != ITEM_NONE)
88 {
89 const IndexImage& index = group.indexes[index_image];
90 return ImageIndexInfo(group.texture, group.size, index.rate, index.frames);
91 }
92 }
94 }
95
96 ImageIndexInfo ResourceImageSet::getIndexInfo(const std::string& _group, size_t _index) const
97 {
98 size_t index_group = getGroupIndex(_group);
99 if (index_group != ITEM_NONE)
100 {
101 const GroupImage& group = mGroups[index_group];
102 if (_index < group.indexes.size())
103 {
104 const IndexImage& index = group.indexes[_index];
105 return ImageIndexInfo(group.texture, group.size, index.rate, index.frames);
106 }
107 }
109 }
110
111 ImageIndexInfo ResourceImageSet::getIndexInfo(size_t _group, size_t _index) const
112 {
113 if (_group < mGroups.size())
114 {
115 const GroupImage& group = mGroups[_group];
116 if (_index < group.indexes.size())
117 {
118 const IndexImage& index = group.indexes[_index];
119 return ImageIndexInfo(group.texture, group.size, index.rate, index.frames);
120 }
121 }
123 }
124
125 ImageIndexInfo ResourceImageSet::getIndexInfo(const IntSize& _group, size_t _index) const
126 {
127 size_t index_group = getGroupIndex(_group);
128 if (index_group != ITEM_NONE)
129 {
130 const GroupImage& group = mGroups[index_group];
131 if (_index < group.indexes.size())
132 {
133 const IndexImage& index = group.indexes[_index];
134 return ImageIndexInfo(group.texture, group.size, index.rate, index.frames);
135 }
136 }
138 }
139
140 ImageIndexInfo ResourceImageSet::getIndexInfo(const IntSize& _group, const std::string& _index) const
141 {
142 size_t index_group = getGroupIndex(_group);
143 if (index_group != ITEM_NONE)
144 {
145 const GroupImage& group = mGroups[index_group];
146 size_t index_image = getImageIndex(group, _index);
147 if (index_image != ITEM_NONE)
148 {
149 const IndexImage& index = group.indexes[index_image];
150 return ImageIndexInfo(group.texture, group.size, index.rate, index.frames);
151 }
152 }
154 }
155
156 size_t ResourceImageSet::getGroupIndex(const std::string& _name) const
157 {
158 for (size_t index = 0; index < mGroups.size(); ++index)
159 {
160 if (mGroups[index].name == _name)
161 return index;
162 }
163 return ITEM_NONE;
164 }
165
166 size_t ResourceImageSet::getGroupIndex(const IntSize& _size) const
167 {
168 for (size_t index = 0; index < mGroups.size(); ++index)
169 {
170 if (mGroups[index].size == _size)
171 return index;
172 }
173 return ITEM_NONE;
174 }
175
176 size_t ResourceImageSet::getImageIndex(const GroupImage& _group, const std::string& _name) const
177 {
178 const VectorIndexImage& indices = _group.indexes;
179 for (size_t index = 0; index < indices.size(); ++index)
180 {
181 if (indices[index].name == _name)
182 return index;
183 }
184 return ITEM_NONE;
185 }
186
188 {
189 return EnumeratorGroupImage(mGroups);
190 }
191
193 {
194 mGroups.push_back(_group);
195 }
196
197} // namespace MyGUI
static const std::string & getEmptyString()
static const IntSize & getZeroIntSize()
static LanguageManager & getInstance()
UString replaceTags(const UString &_line)
ImageIndexInfo getIndexInfo(const std::string &_group, const std::string &_index) const
EnumeratorGroupImage getEnumerator() const
void AddGroupImage(const GroupImage &_group)
size_type size() const
Returns the number of code points in the current string.
size_t parseSizeT(const std::string &_value)
float parseFloat(const std::string &_value)
Element * ElementPtr
std::vector< IndexImage > VectorIndexImage
Enumerator< VectorGroupImage > EnumeratorGroupImage
types::TSize< int > IntSize
Definition: MyGUI_Types.h:29
const size_t ITEM_NONE
Definition: MyGUI_Macros.h:17
types::TPoint< int > IntPoint
Definition: MyGUI_Types.h:26
std::vector< IntPoint > frames
static TPoint< int > parse(const std::string &_value)
Definition: MyGUI_TPoint.h:120
static TSize< int > parse(const std::string &_value)
Definition: MyGUI_TSize.h:120