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