MyGUI 3.5.3
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"
11#include "MyGUI_Constants.h"
12
13#include <pugixml.hpp>
14
15namespace MyGUI
16{
17
18 void ResourceImageSet::deserialization(xml::ElementPtr _node, Version _version)
19 {
20 Base::deserialization(_node, _version);
21
22 for (auto group_node : _node.node().children("Group"))
23 {
24 GroupImage group;
25 group.name = group_node.attribute("name").value();
26
27 group.texture = group_node.attribute("texture").value();
28 // tags replacement support for Skins
29 if (_version >= Version(1, 1))
30 {
31 group.texture = LanguageManager::getInstance().replaceTags(group.texture);
32 }
33
34 group.size = IntSize::parse(group_node.attribute("size").value());
35
36 for (auto index_node : group_node.children("Index"))
37 {
38 IndexImage index;
39 index.name = index_node.attribute("name").value();
40 index.rate = utility::parseFloat(index_node.attribute("rate").value());
41
42 for (auto frame_node : index_node.children("Frame"))
43 {
44 size_t count = utility::parseSizeT(frame_node.attribute("count").value());
45 const IntPoint& point = IntPoint::parse(frame_node.attribute("point").value());
46 if ((count < 1) || (count > 256))
47 count = 1;
48 while (count > 0)
49 {
50 index.frames.push_back(point);
51 --count;
52 }
53 }
54
55 group.indexes.push_back(index);
56 }
57
58 AddGroupImage(group);
59 }
60 }
61
62 ImageIndexInfo ResourceImageSet::getIndexInfo(std::string_view _group, std::string_view _index) const
63 {
64 size_t index_group = getGroupIndex(_group);
65 if (index_group != ITEM_NONE)
66 {
67 const GroupImage& group = mGroups[index_group];
68 size_t index_image = getImageIndex(group, _index);
69 if (index_image != ITEM_NONE)
70 {
71 const IndexImage& index = group.indexes[index_image];
72 return {group.texture, group.size, index.rate, index.frames};
73 }
74 }
75 return {std::string_view{}, Constants::getZeroIntSize(), 0, {}};
76 }
77
78 ImageIndexInfo ResourceImageSet::getIndexInfo(size_t _group, std::string_view _index) const
79 {
80 if (_group < mGroups.size())
81 {
82 const GroupImage& group = mGroups[_group];
83 size_t index_image = getImageIndex(group, _index);
84 if (index_image != ITEM_NONE)
85 {
86 const IndexImage& index = group.indexes[index_image];
87 return {group.texture, group.size, index.rate, index.frames};
88 }
89 }
90 return {std::string_view{}, Constants::getZeroIntSize(), 0, {}};
91 }
92
93 ImageIndexInfo ResourceImageSet::getIndexInfo(std::string_view _group, size_t _index) const
94 {
95 size_t index_group = getGroupIndex(_group);
96 if (index_group != ITEM_NONE)
97 {
98 const GroupImage& group = mGroups[index_group];
99 if (_index < group.indexes.size())
100 {
101 const IndexImage& index = group.indexes[_index];
102 return {group.texture, group.size, index.rate, index.frames};
103 }
104 }
105 return {std::string_view{}, Constants::getZeroIntSize(), 0, {}};
106 }
107
108 ImageIndexInfo ResourceImageSet::getIndexInfo(size_t _group, size_t _index) const
109 {
110 if (_group < mGroups.size())
111 {
112 const GroupImage& group = mGroups[_group];
113 if (_index < group.indexes.size())
114 {
115 const IndexImage& index = group.indexes[_index];
116 return {group.texture, group.size, index.rate, index.frames};
117 }
118 }
119 return {std::string_view{}, Constants::getZeroIntSize(), 0, {}};
120 }
121
122 ImageIndexInfo ResourceImageSet::getIndexInfo(const IntSize& _group, size_t _index) const
123 {
124 size_t index_group = getGroupIndex(_group);
125 if (index_group != ITEM_NONE)
126 {
127 const GroupImage& group = mGroups[index_group];
128 if (_index < group.indexes.size())
129 {
130 const IndexImage& index = group.indexes[_index];
131 return {group.texture, group.size, index.rate, index.frames};
132 }
133 }
134 return {std::string_view{}, Constants::getZeroIntSize(), 0, {}};
135 }
136
137 ImageIndexInfo ResourceImageSet::getIndexInfo(const IntSize& _group, std::string_view _index) const
138 {
139 size_t index_group = getGroupIndex(_group);
140 if (index_group != ITEM_NONE)
141 {
142 const GroupImage& group = mGroups[index_group];
143 size_t index_image = getImageIndex(group, _index);
144 if (index_image != ITEM_NONE)
145 {
146 const IndexImage& index = group.indexes[index_image];
147 return {group.texture, group.size, index.rate, index.frames};
148 }
149 }
150 return {std::string_view{}, Constants::getZeroIntSize(), 0, {}};
151 }
152
153 size_t ResourceImageSet::getGroupIndex(std::string_view _name) const
154 {
155 for (size_t index = 0; index < mGroups.size(); ++index)
156 {
157 if (mGroups[index].name == _name)
158 return index;
159 }
160 return ITEM_NONE;
161 }
162
163 size_t ResourceImageSet::getGroupIndex(const IntSize& _size) const
164 {
165 for (size_t index = 0; index < mGroups.size(); ++index)
166 {
167 if (mGroups[index].size == _size)
168 return index;
169 }
170 return ITEM_NONE;
171 }
172
173 size_t ResourceImageSet::getImageIndex(const GroupImage& _group, std::string_view _name) const
174 {
175 const VectorIndexImage& indices = _group.indexes;
176 for (size_t index = 0; index < indices.size(); ++index)
177 {
178 if (indices[index].name == _name)
179 return index;
180 }
181 return ITEM_NONE;
182 }
183
184 const VectorGroupImage& ResourceImageSet::getGroups() const
185 {
186 return mGroups;
187 }
188
189 void ResourceImageSet::AddGroupImage(const GroupImage& _group)
190 {
191 mGroups.push_back(_group);
192 }
193
194} // namespace MyGUI
float parseFloat(std::string_view _value)
size_t parseSizeT(std::string_view _value)
types::TPoint< int > IntPoint
Definition MyGUI_Types.h:26
std::vector< IndexImage > VectorIndexImage
constexpr size_t ITEM_NONE
types::TSize< int > IntSize
Definition MyGUI_Types.h:29
std::vector< GroupImage > VectorGroupImage
static TPoint< int > parse(std::string_view _value)
static TSize< int > parse(std::string_view _value)