MyGUI 3.2.0

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

- File List
- Globals

MyGUI_ResourceImageSet.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_ResourceImageSet.h"
24 #include "MyGUI_ResourceManager.h"
25 #include "MyGUI_LanguageManager.h"
26 #include "MyGUI_Constants.h"
27
28 namespace MyGUI
29 {
30
31 std::vector<IntPoint> ResourceImageSet::mFramesEmpty;
32
33 ResourceImageSet::ResourceImageSet()
34 {
35 }
36
37 ResourceImageSet::~ResourceImageSet()
38 {
39 }
40
41 void ResourceImageSet::deserialization(xml::ElementPtr _node, Version _version)
42 {
43 Base::deserialization(_node, _version);
44
45 // берем детей и крутимся, основной цикл
46 xml::ElementEnumerator group_node = _node->getElementEnumerator();
47 while (group_node.next("Group"))
48 {
49 GroupImage group;
50 group.name = group_node->findAttribute("name");
51
52 group.texture = group_node->findAttribute("texture");
53 // поддержка замены тегов
54 if (_version >= Version(1, 1))
55 {
56 group.texture = LanguageManager::getInstance().replaceTags(group.texture);
57 }
58
59 group.size = IntSize::parse(group_node->findAttribute("size"));
60
61 xml::ElementEnumerator index_node = group_node->getElementEnumerator();
62 while (index_node.next("Index"))
63 {
64 IndexImage index;
65 index.name = index_node->findAttribute("name");
66 index.rate = utility::parseFloat(index_node->findAttribute("rate"));
67
68 xml::ElementEnumerator frame_node = index_node->getElementEnumerator();
69 while (frame_node.next("Frame"))
70 {
71 size_t count = utility::parseSizeT(frame_node->findAttribute("count"));
72 const IntPoint& point = IntPoint::parse(frame_node->findAttribute("point"));
73 if ((count < 1) || (count > 256)) count = 1;
74 while (count > 0)
75 {
76 index.frames.push_back(point);
77 -- count;
78 }
79 }
80
81 group.indexes.push_back(index);
82 }
83
84 mGroups.push_back(group);
85 }
86 }
87
88 ImageIndexInfo ResourceImageSet::getIndexInfo(const std::string& _group, const std::string& _index)
89 {
90 size_t index_group = getGroupIndex(_group);
91 if (index_group != ITEM_NONE)
92 {
93 GroupImage& group = mGroups[index_group];
94 size_t index_image = getImageIndex(group, _index);
95 if (index_image != ITEM_NONE)
96 {
97 IndexImage& index = group.indexes[index_image];
98 return ImageIndexInfo(group.texture, group.size, index.rate, index.frames);
99 }
100 }
101 return ImageIndexInfo(Constants::getEmptyString(), Constants::getZeroIntSize(), 0, mFramesEmpty);
102 }
103
104 ImageIndexInfo ResourceImageSet::getIndexInfo(size_t _group, const std::string& _index)
105 {
106 if (_group < mGroups.size())
107 {
108 GroupImage& group = mGroups[_group];
109 size_t index_image = getImageIndex(group, _index);
110 if (index_image != ITEM_NONE)
111 {
112 IndexImage& index = group.indexes[index_image];
113 return ImageIndexInfo(group.texture, group.size, index.rate, index.frames);
114 }
115 }
116 return ImageIndexInfo(Constants::getEmptyString(), Constants::getZeroIntSize(), 0, mFramesEmpty);
117 }
118
119 ImageIndexInfo ResourceImageSet::getIndexInfo(const std::string& _group, size_t _index)
120 {
121 size_t index_group = getGroupIndex(_group);
122 if (index_group != ITEM_NONE)
123 {
124 GroupImage& group = mGroups[index_group];
125 if (_index < group.indexes.size())
126 {
127 IndexImage& index = group.indexes[_index];
128 return ImageIndexInfo(group.texture, group.size, index.rate, index.frames);
129 }
130 }
131 return ImageIndexInfo(Constants::getEmptyString(), Constants::getZeroIntSize(), 0, mFramesEmpty);
132 }
133
134 ImageIndexInfo ResourceImageSet::getIndexInfo(size_t _group, size_t _index)
135 {
136 if (_group < mGroups.size())
137 {
138 GroupImage& group = mGroups[_group];
139 if (_index < group.indexes.size())
140 {
141 IndexImage& index = group.indexes[_index];
142 return ImageIndexInfo(group.texture, group.size, index.rate, index.frames);
143 }
144 }
145 return ImageIndexInfo(Constants::getEmptyString(), Constants::getZeroIntSize(), 0, mFramesEmpty);
146 }
147
148 ImageIndexInfo ResourceImageSet::getIndexInfo(const IntSize& _group, size_t _index)
149 {
150 size_t index_group = getGroupIndex(_group);
151 if (index_group != ITEM_NONE)
152 {
153 GroupImage& group = mGroups[index_group];
154 if (_index < group.indexes.size())
155 {
156 IndexImage& index = group.indexes[_index];
157 return ImageIndexInfo(group.texture, group.size, index.rate, index.frames);
158 }
159 }
160 return ImageIndexInfo(Constants::getEmptyString(), Constants::getZeroIntSize(), 0, mFramesEmpty);
161 }
162
163 ImageIndexInfo ResourceImageSet::getIndexInfo(const IntSize& _group, const std::string& _index)
164 {
165 size_t index_group = getGroupIndex(_group);
166 if (index_group != ITEM_NONE)
167 {
168 GroupImage& group = mGroups[index_group];
169 size_t index_image = getImageIndex(group, _index);
170 if (index_image != ITEM_NONE)
171 {
172 IndexImage& index = group.indexes[index_image];
173 return ImageIndexInfo(group.texture, group.size, index.rate, index.frames);
174 }
175 }
176 return ImageIndexInfo(Constants::getEmptyString(), Constants::getZeroIntSize(), 0, mFramesEmpty);
177 }
178
179 size_t ResourceImageSet::getGroupIndex(const std::string& _name)
180 {
181 for (size_t index = 0; index < mGroups.size(); ++index)
182 {
183 if (mGroups[index].name == _name)
184 return index;
185 }
186 return ITEM_NONE;
187 }
188
189 size_t ResourceImageSet::getGroupIndex(const IntSize& _size)
190 {
191 for (size_t index = 0; index < mGroups.size(); ++index)
192 {
193 if (mGroups[index].size == _size)
194 return index;
195 }
196 return ITEM_NONE;
197 }
198
199 size_t ResourceImageSet::getImageIndex(GroupImage& _group, const std::string& _name)
200 {
201 VectorIndexImage& indexes = _group.indexes;
202 for (size_t index = 0; index < indexes.size(); ++index)
203 {
204 if (indexes[index].name == _name)
205 return index;
206 }
207 return ITEM_NONE;
208 }
209
210 const IntSize& ResourceImageSet::getGroupSize(size_t _index)
211 {
212 if (_index >= mGroups.size())
213 return Constants::getZeroIntSize();
214 return mGroups[_index].size;
215 }
216
217 const IntSize& ResourceImageSet::getGroupSize(const std::string& _group)
218 {
219 for (size_t index = 0; index < mGroups.size(); ++index)
220 {
221 if (mGroups[index].name == _group)
222 return mGroups[index].size;
223 }
224 return Constants::getZeroIntSize();
225 }
226
227 EnumeratorGroupImage ResourceImageSet::getEnumerator() const
228 {
229 return EnumeratorGroupImage(mGroups);
230 }
231
232 } // namespace MyGUI
MyGUI::IndexImage::frames
std::vector< IntPoint > frames
Definition: MyGUI_ResourceImageSetData.h:34
MyGUI::IndexImage
Definition: MyGUI_ResourceImageSetData.h:30
MyGUI::GroupImage
Definition: MyGUI_ResourceImageSetData.h:38
MyGUI::IntSize
types::TSize< int > IntSize
Definition: MyGUI_Types.h:44
MyGUI_Precompiled.h
MyGUI::ResourceImageSet::getIndexInfo
ImageIndexInfo getIndexInfo(const std::string &_group, const std::string &_index)
Definition: MyGUI_ResourceImageSet.cpp:88
MyGUI::types::TSize< int >
MyGUI::xml::ElementPtr
Element * ElementPtr
Definition: MyGUI_XmlDocument.h:114
MyGUI::Singleton< LanguageManager >::getInstance
static LanguageManager & getInstance()
Definition: MyGUI_Singleton.h:53
MyGUI::IndexImage::rate
float rate
Definition: MyGUI_ResourceImageSetData.h:33
MyGUI::utility::parseSizeT
size_t parseSizeT(const std::string &_value)
Definition: MyGUI_StringUtility.h:191
MyGUI_ResourceImageSet.h
MyGUI::ITEM_NONE
const size_t ITEM_NONE
Definition: MyGUI_Macros.h:32
MyGUI::types::TSize< int >::parse
static TSize< int > parse(const std::string &_value)
Definition: MyGUI_TSize.h:135
MyGUI_LanguageManager.h
MyGUI::Constants::getEmptyString
static const std::string & getEmptyString()
Definition: MyGUI_Constants.h:36
MyGUI::GroupImage::indexes
VectorIndexImage indexes
Definition: MyGUI_ResourceImageSetData.h:43
MyGUI::Enumerator
Definition: MyGUI_Enumerator.h:63
MyGUI_Constants.h
MyGUI::ImageIndexInfo
Definition: MyGUI_ImageInfo.h:45
MyGUI::GroupImage::texture
std::string texture
Definition: MyGUI_ResourceImageSetData.h:41
MyGUI::GroupImage::size
IntSize size
Definition: MyGUI_ResourceImageSetData.h:42
MyGUI::VectorIndexImage
std::vector< IndexImage > VectorIndexImage
Definition: MyGUI_ResourceImageSetData.h:36
MyGUI::utility::parseFloat
float parseFloat(const std::string &_value)
Definition: MyGUI_StringUtility.h:196
MyGUI_ResourceManager.h
MyGUI::types::TPoint< int >::parse
static TPoint< int > parse(const std::string &_value)
Definition: MyGUI_TPoint.h:135
MyGUI::LanguageManager::replaceTags
UString replaceTags(const UString &_line)
Definition: MyGUI_LanguageManager.cpp:210
MyGUI::ResourceImageSet::getEnumerator
EnumeratorGroupImage getEnumerator() const
Definition: MyGUI_ResourceImageSet.cpp:227
MyGUI::UString::size
size_type size() const
Returns the number of code points in the current string.
Definition: MyGUI_UString.cpp:601
MyGUI::Constants::getZeroIntSize
static const IntSize & getZeroIntSize()
Definition: MyGUI_Constants.h:37
MyGUI::EnumeratorGroupImage
Enumerator< VectorGroupImage > EnumeratorGroupImage
Definition: MyGUI_ResourceImageSetData.h:46
MyGUI::IntPoint
types::TPoint< int > IntPoint
Definition: MyGUI_Types.h:41