MyGUI: MyGUI_ResourceImageSet.cpp Source File

MyGUI 3.2.2

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