MyGUI: MyGUI_ResourceImageSet.cpp Source File

MyGUI 3.4.2

- Main Page
- Related Pages
- Namespaces
- Data Structures
- Files
- Examples

- File List
- Globals

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 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) const
66 {
67 size_t index_group = getGroupIndex(_group);
68 if (index_group != ITEM_NONE)
69 {
70 const GroupImage& group = mGroups[index_group];
71 size_t index_image = getImageIndex(group, _index);
72 if (index_image != ITEM_NONE)
73 {
74 const IndexImage& index = group.indexes[index_image];
75 return ImageIndexInfo(group.texture, group.size, index.rate, index.frames);
76 }
77 }
78 return ImageIndexInfo(Constants::getEmptyString(), Constants::getZeroIntSize(), 0, mFramesEmpty);
79 }
80
81 ImageIndexInfo ResourceImageSet::getIndexInfo(size_t _group, const std::string& _index) const
82 {
83 if (_group < mGroups.size())
84 {
85 const GroupImage& group = mGroups[_group];
86 size_t index_image = getImageIndex(group, _index);
87 if (index_image != ITEM_NONE)
88 {
89 const IndexImage& index = group.indexes[index_image];
90 return ImageIndexInfo(group.texture, group.size, index.rate, index.frames);
91 }
92 }
93 return ImageIndexInfo(Constants::getEmptyString(), Constants::getZeroIntSize(), 0, mFramesEmpty);
94 }
95
96 ImageIndexInfo ResourceImageSet::getIndexInfo(const std::string& _group, size_t _index) const
97 {
98 size_t index_group = getGroupIndex(_group);
99 if (index_group != ITEM_NONE)
100 {
101 const GroupImage& group = mGroups[index_group];
102 if (_index < group.indexes.size())
103 {
104 const IndexImage& index = group.indexes[_index];
105 return ImageIndexInfo(group.texture, group.size, index.rate, index.frames);
106 }
107 }
108 return ImageIndexInfo(Constants::getEmptyString(), Constants::getZeroIntSize(), 0, mFramesEmpty);
109 }
110
111 ImageIndexInfo ResourceImageSet::getIndexInfo(size_t _group, size_t _index) const
112 {
113 if (_group < mGroups.size())
114 {
115 const GroupImage& group = mGroups[_group];
116 if (_index < group.indexes.size())
117 {
118 const IndexImage& index = group.indexes[_index];
119 return ImageIndexInfo(group.texture, group.size, index.rate, index.frames);
120 }
121 }
122 return ImageIndexInfo(Constants::getEmptyString(), Constants::getZeroIntSize(), 0, mFramesEmpty);
123 }
124
125 ImageIndexInfo ResourceImageSet::getIndexInfo(const IntSize& _group, size_t _index) const
126 {
127 size_t index_group = getGroupIndex(_group);
128 if (index_group != ITEM_NONE)
129 {
130 const GroupImage& group = mGroups[index_group];
131 if (_index < group.indexes.size())
132 {
133 const IndexImage& index = group.indexes[_index];
134 return ImageIndexInfo(group.texture, group.size, index.rate, index.frames);
135 }
136 }
137 return ImageIndexInfo(Constants::getEmptyString(), Constants::getZeroIntSize(), 0, mFramesEmpty);
138 }
139
140 ImageIndexInfo ResourceImageSet::getIndexInfo(const IntSize& _group, const std::string& _index) const
141 {
142 size_t index_group = getGroupIndex(_group);
143 if (index_group != ITEM_NONE)
144 {
145 const GroupImage& group = mGroups[index_group];
146 size_t index_image = getImageIndex(group, _index);
147 if (index_image != ITEM_NONE)
148 {
149 const IndexImage& index = group.indexes[index_image];
150 return ImageIndexInfo(group.texture, group.size, index.rate, index.frames);
151 }
152 }
153 return ImageIndexInfo(Constants::getEmptyString(), Constants::getZeroIntSize(), 0, mFramesEmpty);
154 }
155
156 size_t ResourceImageSet::getGroupIndex(const std::string& _name) const
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) const
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(const GroupImage& _group, const std::string& _name) const
177 {
178 const VectorIndexImage& indices = _group.indexes;
179 for (size_t index = 0; index < indices.size(); ++index)
180 {
181 if (indices[index].name == _name)
182 return index;
183 }
184 return ITEM_NONE;
185 }
186
187 EnumeratorGroupImage ResourceImageSet::getEnumerator() const
188 {
189 return EnumeratorGroupImage(mGroups);
190 }
191
192 void ResourceImageSet::AddGroupImage(const GroupImage& _group)
193 {
194 mGroups.push_back(_group);
195 }
196
197} // namespace MyGUI
MyGUI_Constants.h
MyGUI_LanguageManager.h
MyGUI_Precompiled.h
MyGUI_ResourceImageSet.h
MyGUI_ResourceManager.h
MyGUI::Constants::getEmptyString
static const std::string & getEmptyString()
Definition MyGUI_Constants.h:24
MyGUI::Constants::getZeroIntSize
static const IntSize & getZeroIntSize()
Definition MyGUI_Constants.h:28
MyGUI::Enumerator
Definition MyGUI_Enumerator.h:49
MyGUI::LanguageManager::getInstance
static LanguageManager & getInstance()
Definition MyGUI_LanguageManager.cpp:18
MyGUI::LanguageManager::replaceTags
UString replaceTags(const UString &_line)
Definition MyGUI_LanguageManager.cpp:195
MyGUI::ResourceImageSet::getIndexInfo
ImageIndexInfo getIndexInfo(const std::string &_group, const std::string &_index) const
Definition MyGUI_ResourceImageSet.cpp:65
MyGUI::ResourceImageSet::getEnumerator
EnumeratorGroupImage getEnumerator() const
Definition MyGUI_ResourceImageSet.cpp:187
MyGUI::ResourceImageSet::AddGroupImage
void AddGroupImage(const GroupImage &_group)
Definition MyGUI_ResourceImageSet.cpp:192
MyGUI::utility::parseSizeT
size_t parseSizeT(const std::string &_value)
Definition MyGUI_StringUtility.h:174
MyGUI::utility::parseFloat
float parseFloat(const std::string &_value)
Definition MyGUI_StringUtility.h:179
MyGUI::xml::ElementPtr
Element * ElementPtr
Definition MyGUI_XmlDocument.h:106
MyGUI
Definition MyGUI_ActionController.h:15
MyGUI::VectorIndexImage
std::vector< IndexImage > VectorIndexImage
Definition MyGUI_ResourceImageSetData.h:26
MyGUI::IntPoint
types::TPoint< int > IntPoint
Definition MyGUI_Types.h:27
MyGUI::EnumeratorGroupImage
Enumerator< VectorGroupImage > EnumeratorGroupImage
Definition MyGUI_ResourceImageSetData.h:36
MyGUI::IntSize
types::TSize< int > IntSize
Definition MyGUI_Types.h:30
MyGUI::ITEM_NONE
const size_t ITEM_NONE
Definition MyGUI_Macros.h:18
MyGUI::GroupImage
Definition MyGUI_ResourceImageSetData.h:29
MyGUI::GroupImage::indexes
VectorIndexImage indexes
Definition MyGUI_ResourceImageSetData.h:33
MyGUI::GroupImage::texture
std::string texture
Definition MyGUI_ResourceImageSetData.h:31
MyGUI::GroupImage::size
IntSize size
Definition MyGUI_ResourceImageSetData.h:32
MyGUI::ImageIndexInfo
Definition MyGUI_ImageInfo.h:32
MyGUI::IndexImage
Definition MyGUI_ResourceImageSetData.h:16
MyGUI::IndexImage::rate
float rate
Definition MyGUI_ResourceImageSetData.h:23
MyGUI::IndexImage::frames
std::vector< IntPoint > frames
Definition MyGUI_ResourceImageSetData.h:24
MyGUI::types::TPoint< int >::parse
static TPoint< int > parse(const std::string &_value)
Definition MyGUI_TPoint.h:120
MyGUI::types::TSize< int >
MyGUI::types::TSize< int >::parse
static TSize< int > parse(const std::string &_value)
Definition MyGUI_TSize.h:120