MyGUI  3.2.0
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  }
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  }
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  }
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  }
146  }
147 
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  }
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  }
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 
228  {
229  return EnumeratorGroupImage(mGroups);
230  }
231 
232 } // namespace MyGUI
std::vector< IntPoint > frames
types::TSize< int > IntSize
Definition: MyGUI_Types.h:44
ImageIndexInfo getIndexInfo(const std::string &_group, const std::string &_index)
Element * ElementPtr
static LanguageManager & getInstance()
size_t parseSizeT(const std::string &_value)
const size_t ITEM_NONE
Definition: MyGUI_Macros.h:32
static TSize< int > parse(const std::string &_value)
Definition: MyGUI_TSize.h:135
static const std::string & getEmptyString()
std::vector< IndexImage > VectorIndexImage
float parseFloat(const std::string &_value)
static TPoint< int > parse(const std::string &_value)
Definition: MyGUI_TPoint.h:135
UString replaceTags(const UString &_line)
EnumeratorGroupImage getEnumerator() const
size_type size() const
Returns the number of code points in the current string.
static const IntSize & getZeroIntSize()
Enumerator< VectorGroupImage > EnumeratorGroupImage
types::TPoint< int > IntPoint
Definition: MyGUI_Types.h:41