MyGUI  3.2.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"
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  }
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  }
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  }
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  }
131  }
132 
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  }
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  }
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 
213  {
214  return EnumeratorGroupImage(mGroups);
215  }
216 
218  {
219  mGroups.push_back(_group);
220  }
221 
222 } // namespace MyGUI