MyGUI  3.4.0
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  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)
66  {
67  size_t index_group = getGroupIndex(_group);
68  if (index_group != ITEM_NONE)
69  {
70  GroupImage& group = mGroups[index_group];
71  size_t index_image = getImageIndex(group, _index);
72  if (index_image != ITEM_NONE)
73  {
74  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)
82  {
83  if (_group < mGroups.size())
84  {
85  GroupImage& group = mGroups[_group];
86  size_t index_image = getImageIndex(group, _index);
87  if (index_image != ITEM_NONE)
88  {
89  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)
97  {
98  size_t index_group = getGroupIndex(_group);
99  if (index_group != ITEM_NONE)
100  {
101  GroupImage& group = mGroups[index_group];
102  if (_index < group.indexes.size())
103  {
104  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)
112  {
113  if (_group < mGroups.size())
114  {
115  GroupImage& group = mGroups[_group];
116  if (_index < group.indexes.size())
117  {
118  IndexImage& index = group.indexes[_index];
119  return ImageIndexInfo(group.texture, group.size, index.rate, index.frames);
120  }
121  }
123  }
124 
126  {
127  size_t index_group = getGroupIndex(_group);
128  if (index_group != ITEM_NONE)
129  {
130  GroupImage& group = mGroups[index_group];
131  if (_index < group.indexes.size())
132  {
133  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)
141  {
142  size_t index_group = getGroupIndex(_group);
143  if (index_group != ITEM_NONE)
144  {
145  GroupImage& group = mGroups[index_group];
146  size_t index_image = getImageIndex(group, _index);
147  if (index_image != ITEM_NONE)
148  {
149  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)
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)
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(GroupImage& _group, const std::string& _name)
177  {
178  VectorIndexImage& indexes = _group.indexes;
179  for (size_t index = 0; index < indexes.size(); ++index)
180  {
181  if (indexes[index].name == _name)
182  return index;
183  }
184  return ITEM_NONE;
185  }
186 
187  const IntSize& ResourceImageSet::getGroupSize(size_t _index)
188  {
189  if (_index >= mGroups.size())
190  return Constants::getZeroIntSize();
191  return mGroups[_index].size;
192  }
193 
194  const IntSize& ResourceImageSet::getGroupSize(const std::string& _group)
195  {
196  for (size_t index = 0; index < mGroups.size(); ++index)
197  {
198  if (mGroups[index].name == _group)
199  return mGroups[index].size;
200  }
201  return Constants::getZeroIntSize();
202  }
203 
205  {
206  return EnumeratorGroupImage(mGroups);
207  }
208 
210  {
211  mGroups.push_back(_group);
212  }
213 
214 } // namespace MyGUI
MyGUI::Singleton< LanguageManager >::getInstance
static LanguageManager & getInstance()
Definition: MyGUI_Singleton.h:44
MyGUI::Constants::getZeroIntSize
static const IntSize & getZeroIntSize()
Definition: MyGUI_Constants.h:28
MyGUI::ResourceImageSet::AddGroupImage
void AddGroupImage(const GroupImage &_group)
Definition: MyGUI_ResourceImageSet.cpp:209
MyGUI_Constants.h
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::utility::parseFloat
float parseFloat(const std::string &_value)
Definition: MyGUI_StringUtility.h:179
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::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:174
MyGUI::ImageIndexInfo
Definition: MyGUI_ImageInfo.h:32
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:65
MyGUI::IndexImage
Definition: MyGUI_ResourceImageSetData.h:16
MyGUI::GroupImage
Definition: MyGUI_ResourceImageSetData.h:29
MyGUI::xml::ElementPtr
Element * ElementPtr
Definition: MyGUI_XmlDocument.h:106
MyGUI_LanguageManager.h
MyGUI::Enumerator
Definition: MyGUI_Enumerator.h:49
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::IntSize
types::TSize< int > IntSize
Definition: MyGUI_Types.h:29
MyGUI::types::TSize< int >::parse
static TSize< int > parse(const std::string &_value)
Definition: MyGUI_TSize.h:120
MyGUI::IntPoint
types::TPoint< int > IntPoint
Definition: MyGUI_Types.h:26
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:204
MyGUI
Definition: MyGUI_ActionController.h:15