MyGUI  3.0.1
MyGUI_ResourceImageSet.cpp
Go to the documentation of this file.
1 
7 /*
8  This file is part of MyGUI.
9 
10  MyGUI is free software: you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  MyGUI is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
22 */
23 #include "MyGUI_Precompiled.h"
24 #include "MyGUI_ResourceImageSet.h"
25 #include "MyGUI_ResourceManager.h"
26 #include "MyGUI_LanguageManager.h"
27 
28 namespace MyGUI
29 {
30 
31  std::string ResourceImageSet::mTextureEmpty;
32  IntSize ResourceImageSet::mSizeEmpty;
33  std::vector<IntPoint> ResourceImageSet::mFramesEmpty;
34 
35  void ResourceImageSet::deserialization(xml::ElementPtr _node, Version _version)
36  {
37  Base::deserialization(_node, _version);
38 
39  // берем детей и крутимся, основной цикл
40  xml::ElementEnumerator group_node = _node->getElementEnumerator();
41  while (group_node.next("Group"))
42  {
43  GroupImage group;
44  group.name = group_node->findAttribute("name");
45 
46  group.texture = group_node->findAttribute("texture");
47  // поддержка замены тегов
48  if (_version >= Version(1, 1))
49  {
50  group.texture = LanguageManager::getInstance().replaceTags(group.texture);
51  }
52 
53  group.size = IntSize::parse(group_node->findAttribute("size"));
54 
55  xml::ElementEnumerator index_node = group_node->getElementEnumerator();
56  while (index_node.next("Index"))
57  {
58  IndexImage index;
59  index.name = index_node->findAttribute("name");
60  index.rate = utility::parseFloat(index_node->findAttribute("rate"));
61 
62  xml::ElementEnumerator frame_node = index_node->getElementEnumerator();
63  while (frame_node.next("Frame"))
64  {
65  size_t count = utility::parseSizeT(frame_node->findAttribute("count"));
66  const IntPoint& point = IntPoint::parse(frame_node->findAttribute("point"));
67  if ((count < 1) || (count > 256)) count = 1;
68  while (count > 0)
69  {
70  index.frames.push_back(point);
71  -- count;
72  }
73  }
74 
75  group.indexes.push_back(index);
76  }
77 
78  mGroups.push_back(group);
79  }
80  }
81 
82  ImageIndexInfo ResourceImageSet::getIndexInfo(const std::string& _group, const std::string& _index)
83  {
84  size_t index_group = getGroupIndex(_group);
85  if (index_group != ITEM_NONE)
86  {
87  GroupImage& group = mGroups[index_group];
88  size_t index_image = getImageIndex(group, _index);
89  if (index_image != ITEM_NONE)
90  {
91  IndexImage& index = group.indexes[index_image];
92  return ImageIndexInfo(group.texture, group.size, index.rate, index.frames);
93  }
94  }
95  return ImageIndexInfo(mTextureEmpty, mSizeEmpty, 0, mFramesEmpty);
96  }
97 
98  ImageIndexInfo ResourceImageSet::getIndexInfo(size_t _group, const std::string& _index)
99  {
100  if (_group < mGroups.size())
101  {
102  GroupImage& group = mGroups[_group];
103  size_t index_image = getImageIndex(group, _index);
104  if (index_image != ITEM_NONE)
105  {
106  IndexImage& index = group.indexes[index_image];
107  return ImageIndexInfo(group.texture, group.size, index.rate, index.frames);
108  }
109  }
110  return ImageIndexInfo(mTextureEmpty, mSizeEmpty, 0, mFramesEmpty);
111  }
112 
113  ImageIndexInfo ResourceImageSet::getIndexInfo(const std::string& _group, size_t _index)
114  {
115  size_t index_group = getGroupIndex(_group);
116  if (index_group != ITEM_NONE)
117  {
118  GroupImage& group = mGroups[index_group];
119  if (_index < group.indexes.size())
120  {
121  IndexImage& index = group.indexes[_index];
122  return ImageIndexInfo(group.texture, group.size, index.rate, index.frames);
123  }
124  }
125  return ImageIndexInfo(mTextureEmpty, mSizeEmpty, 0, mFramesEmpty);
126  }
127 
128  ImageIndexInfo ResourceImageSet::getIndexInfo(size_t _group, size_t _index)
129  {
130  if (_group < mGroups.size())
131  {
132  GroupImage& group = mGroups[_group];
133  if (_index < group.indexes.size())
134  {
135  IndexImage& index = group.indexes[_index];
136  return ImageIndexInfo(group.texture, group.size, index.rate, index.frames);
137  }
138  }
139  return ImageIndexInfo(mTextureEmpty, mSizeEmpty, 0, mFramesEmpty);
140  }
141 
143  {
144  size_t index_group = getGroupIndex(_group);
145  if (index_group != ITEM_NONE)
146  {
147  GroupImage& group = mGroups[index_group];
148  if (_index < group.indexes.size())
149  {
150  IndexImage& index = group.indexes[_index];
151  return ImageIndexInfo(group.texture, group.size, index.rate, index.frames);
152  }
153  }
154  return ImageIndexInfo(mTextureEmpty, mSizeEmpty, 0, mFramesEmpty);
155  }
156 
157  ImageIndexInfo ResourceImageSet::getIndexInfo(const IntSize& _group, const std::string& _index)
158  {
159  size_t index_group = getGroupIndex(_group);
160  if (index_group != ITEM_NONE)
161  {
162  GroupImage& group = mGroups[index_group];
163  size_t index_image = getImageIndex(group, _index);
164  if (index_image != ITEM_NONE)
165  {
166  IndexImage& index = group.indexes[index_image];
167  return ImageIndexInfo(group.texture, group.size, index.rate, index.frames);
168  }
169  }
170  return ImageIndexInfo(mTextureEmpty, mSizeEmpty, 0, mFramesEmpty);
171  }
172 
173 } // namespace MyGUI