MyGUI
3.2.0
|
00001 00006 /* 00007 This file is part of MyGUI. 00008 00009 MyGUI is free software: you can redistribute it and/or modify 00010 it under the terms of the GNU Lesser General Public License as published by 00011 the Free Software Foundation, either version 3 of the License, or 00012 (at your option) any later version. 00013 00014 MyGUI is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 GNU Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public License 00020 along with MyGUI. If not, see <http://www.gnu.org/licenses/>. 00021 */ 00022 #include "MyGUI_Precompiled.h" 00023 #include "MyGUI_ResourceImageSet.h" 00024 #include "MyGUI_ResourceManager.h" 00025 #include "MyGUI_LanguageManager.h" 00026 #include "MyGUI_Constants.h" 00027 00028 namespace MyGUI 00029 { 00030 00031 std::vector<IntPoint> ResourceImageSet::mFramesEmpty; 00032 00033 ResourceImageSet::ResourceImageSet() 00034 { 00035 } 00036 00037 ResourceImageSet::~ResourceImageSet() 00038 { 00039 } 00040 00041 void ResourceImageSet::deserialization(xml::ElementPtr _node, Version _version) 00042 { 00043 Base::deserialization(_node, _version); 00044 00045 // берем детей и крутимся, основной цикл 00046 xml::ElementEnumerator group_node = _node->getElementEnumerator(); 00047 while (group_node.next("Group")) 00048 { 00049 GroupImage group; 00050 group.name = group_node->findAttribute("name"); 00051 00052 group.texture = group_node->findAttribute("texture"); 00053 // поддержка замены тегов 00054 if (_version >= Version(1, 1)) 00055 { 00056 group.texture = LanguageManager::getInstance().replaceTags(group.texture); 00057 } 00058 00059 group.size = IntSize::parse(group_node->findAttribute("size")); 00060 00061 xml::ElementEnumerator index_node = group_node->getElementEnumerator(); 00062 while (index_node.next("Index")) 00063 { 00064 IndexImage index; 00065 index.name = index_node->findAttribute("name"); 00066 index.rate = utility::parseFloat(index_node->findAttribute("rate")); 00067 00068 xml::ElementEnumerator frame_node = index_node->getElementEnumerator(); 00069 while (frame_node.next("Frame")) 00070 { 00071 size_t count = utility::parseSizeT(frame_node->findAttribute("count")); 00072 const IntPoint& point = IntPoint::parse(frame_node->findAttribute("point")); 00073 if ((count < 1) || (count > 256)) count = 1; 00074 while (count > 0) 00075 { 00076 index.frames.push_back(point); 00077 -- count; 00078 } 00079 } 00080 00081 group.indexes.push_back(index); 00082 } 00083 00084 mGroups.push_back(group); 00085 } 00086 } 00087 00088 ImageIndexInfo ResourceImageSet::getIndexInfo(const std::string& _group, const std::string& _index) 00089 { 00090 size_t index_group = getGroupIndex(_group); 00091 if (index_group != ITEM_NONE) 00092 { 00093 GroupImage& group = mGroups[index_group]; 00094 size_t index_image = getImageIndex(group, _index); 00095 if (index_image != ITEM_NONE) 00096 { 00097 IndexImage& index = group.indexes[index_image]; 00098 return ImageIndexInfo(group.texture, group.size, index.rate, index.frames); 00099 } 00100 } 00101 return ImageIndexInfo(Constants::getEmptyString(), Constants::getZeroIntSize(), 0, mFramesEmpty); 00102 } 00103 00104 ImageIndexInfo ResourceImageSet::getIndexInfo(size_t _group, const std::string& _index) 00105 { 00106 if (_group < mGroups.size()) 00107 { 00108 GroupImage& group = mGroups[_group]; 00109 size_t index_image = getImageIndex(group, _index); 00110 if (index_image != ITEM_NONE) 00111 { 00112 IndexImage& index = group.indexes[index_image]; 00113 return ImageIndexInfo(group.texture, group.size, index.rate, index.frames); 00114 } 00115 } 00116 return ImageIndexInfo(Constants::getEmptyString(), Constants::getZeroIntSize(), 0, mFramesEmpty); 00117 } 00118 00119 ImageIndexInfo ResourceImageSet::getIndexInfo(const std::string& _group, size_t _index) 00120 { 00121 size_t index_group = getGroupIndex(_group); 00122 if (index_group != ITEM_NONE) 00123 { 00124 GroupImage& group = mGroups[index_group]; 00125 if (_index < group.indexes.size()) 00126 { 00127 IndexImage& index = group.indexes[_index]; 00128 return ImageIndexInfo(group.texture, group.size, index.rate, index.frames); 00129 } 00130 } 00131 return ImageIndexInfo(Constants::getEmptyString(), Constants::getZeroIntSize(), 0, mFramesEmpty); 00132 } 00133 00134 ImageIndexInfo ResourceImageSet::getIndexInfo(size_t _group, size_t _index) 00135 { 00136 if (_group < mGroups.size()) 00137 { 00138 GroupImage& group = mGroups[_group]; 00139 if (_index < group.indexes.size()) 00140 { 00141 IndexImage& index = group.indexes[_index]; 00142 return ImageIndexInfo(group.texture, group.size, index.rate, index.frames); 00143 } 00144 } 00145 return ImageIndexInfo(Constants::getEmptyString(), Constants::getZeroIntSize(), 0, mFramesEmpty); 00146 } 00147 00148 ImageIndexInfo ResourceImageSet::getIndexInfo(const IntSize& _group, size_t _index) 00149 { 00150 size_t index_group = getGroupIndex(_group); 00151 if (index_group != ITEM_NONE) 00152 { 00153 GroupImage& group = mGroups[index_group]; 00154 if (_index < group.indexes.size()) 00155 { 00156 IndexImage& index = group.indexes[_index]; 00157 return ImageIndexInfo(group.texture, group.size, index.rate, index.frames); 00158 } 00159 } 00160 return ImageIndexInfo(Constants::getEmptyString(), Constants::getZeroIntSize(), 0, mFramesEmpty); 00161 } 00162 00163 ImageIndexInfo ResourceImageSet::getIndexInfo(const IntSize& _group, const std::string& _index) 00164 { 00165 size_t index_group = getGroupIndex(_group); 00166 if (index_group != ITEM_NONE) 00167 { 00168 GroupImage& group = mGroups[index_group]; 00169 size_t index_image = getImageIndex(group, _index); 00170 if (index_image != ITEM_NONE) 00171 { 00172 IndexImage& index = group.indexes[index_image]; 00173 return ImageIndexInfo(group.texture, group.size, index.rate, index.frames); 00174 } 00175 } 00176 return ImageIndexInfo(Constants::getEmptyString(), Constants::getZeroIntSize(), 0, mFramesEmpty); 00177 } 00178 00179 size_t ResourceImageSet::getGroupIndex(const std::string& _name) 00180 { 00181 for (size_t index = 0; index < mGroups.size(); ++index) 00182 { 00183 if (mGroups[index].name == _name) 00184 return index; 00185 } 00186 return ITEM_NONE; 00187 } 00188 00189 size_t ResourceImageSet::getGroupIndex(const IntSize& _size) 00190 { 00191 for (size_t index = 0; index < mGroups.size(); ++index) 00192 { 00193 if (mGroups[index].size == _size) 00194 return index; 00195 } 00196 return ITEM_NONE; 00197 } 00198 00199 size_t ResourceImageSet::getImageIndex(GroupImage& _group, const std::string& _name) 00200 { 00201 VectorIndexImage& indexes = _group.indexes; 00202 for (size_t index = 0; index < indexes.size(); ++index) 00203 { 00204 if (indexes[index].name == _name) 00205 return index; 00206 } 00207 return ITEM_NONE; 00208 } 00209 00210 const IntSize& ResourceImageSet::getGroupSize(size_t _index) 00211 { 00212 if (_index >= mGroups.size()) 00213 return Constants::getZeroIntSize(); 00214 return mGroups[_index].size; 00215 } 00216 00217 const IntSize& ResourceImageSet::getGroupSize(const std::string& _group) 00218 { 00219 for (size_t index = 0; index < mGroups.size(); ++index) 00220 { 00221 if (mGroups[index].name == _group) 00222 return mGroups[index].size; 00223 } 00224 return Constants::getZeroIntSize(); 00225 } 00226 00227 EnumeratorGroupImage ResourceImageSet::getEnumerator() const 00228 { 00229 return EnumeratorGroupImage(mGroups); 00230 } 00231 00232 } // namespace MyGUI