MyGUI: MyGUI_ResourceImageSet.cpp Source File

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