MyGUI  3.0.1
MyGUI_ResourceImageSet.h
Go to the documentation of this file.
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 #ifndef __MYGUI_RESOURCE_IMAGE_SET_H__
00024 #define __MYGUI_RESOURCE_IMAGE_SET_H__
00025 
00026 #include "MyGUI_Prerequest.h"
00027 #include "MyGUI_Macros.h"
00028 #include "MyGUI_XmlDocument.h"
00029 #include "MyGUI_IResource.h"
00030 #include "MyGUI_ImageInfo.h"
00031 #include "MyGUI_Enumerator.h"
00032 #include "MyGUI_ResourceManager.h"
00033 #include "MyGUI_GenericFactory.h"
00034 
00035 namespace MyGUI
00036 {
00037 
00038     class ResourceImageSet;
00039     typedef ResourceImageSet * ResourceImageSetPtr;
00040 
00041     struct IndexImage
00042     {
00043         std::string name;
00044         float rate;
00045         std::vector<IntPoint> frames;
00046     };
00047     typedef std::vector<IndexImage> VectorIndexImage;
00048 
00049     struct GroupImage
00050     {
00051         std::string name;
00052         std::string texture;
00053         IntSize size;
00054         VectorIndexImage indexes;
00055     };
00056     typedef std::vector<GroupImage> VectorGroupImage;
00057     typedef Enumerator<VectorGroupImage> EnumeratorGroupImage;
00058 
00059     class MYGUI_EXPORT ResourceImageSet :
00060         public IResource
00061     {
00062         friend class GenericFactory<ResourceImageSet>;
00063 
00064         MYGUI_RTTI_DERIVED( ResourceImageSet )
00065 
00066     private:
00067         ResourceImageSet() { }
00068         virtual ~ResourceImageSet() { }
00069 
00070         virtual void deserialization(xml::ElementPtr _node, Version _version);
00071 
00072         //-------------------------------------------------------------//
00073     private:
00074         size_t getGroupIndex(const std::string& _name)
00075         {
00076             for (size_t index=0; index<mGroups.size(); ++index)
00077             {
00078                 if (mGroups[index].name == _name) return index;
00079             }
00080             return ITEM_NONE;
00081         }
00082 
00083         size_t getGroupIndex(const IntSize& _size)
00084         {
00085             for (size_t index=0; index<mGroups.size(); ++index)
00086             {
00087                 if (mGroups[index].size == _size) return index;
00088             }
00089             return ITEM_NONE;
00090         }
00091 
00092         size_t getImageIndex(GroupImage& _group, const std::string& _name)
00093         {
00094             VectorIndexImage& indexes = _group.indexes;
00095             for (size_t index=0; index<indexes.size(); ++index)
00096             {
00097                 if (indexes[index].name == _name) return index;
00098             }
00099             return ITEM_NONE;
00100         }
00101 
00102         const IntSize& getGroupSize(size_t _index)
00103         {
00104             if (_index >= mGroups.size()) return mSizeEmpty;
00105             return mGroups[_index].size;
00106         }
00107 
00108         const IntSize& getGroupSize(const std::string& _group)
00109         {
00110             for (size_t index=0; index<mGroups.size(); ++index)
00111             {
00112                 if (mGroups[index].name == _group) return mGroups[index].size;
00113             }
00114             return mSizeEmpty;
00115         }
00116 
00117     public:
00118         ImageIndexInfo getIndexInfo(const std::string& _group, const std::string& _index);
00119         ImageIndexInfo getIndexInfo(size_t _group, const std::string& _index);
00120         ImageIndexInfo getIndexInfo(const std::string& _group, size_t _index);
00121         ImageIndexInfo getIndexInfo(size_t _group, size_t _index);
00122         ImageIndexInfo getIndexInfo(const IntSize& _group, size_t _index);
00123         ImageIndexInfo getIndexInfo(const IntSize& _group, const std::string& _index);
00124 
00126         EnumeratorGroupImage getEnumerator() { return EnumeratorGroupImage(mGroups); }
00127 
00128     private:
00129         VectorGroupImage mGroups;
00130 
00131         static std::string mTextureEmpty;
00132         static IntSize mSizeEmpty;
00133         static std::vector<IntPoint> mFramesEmpty;
00134 
00135     };
00136 
00137 } // namespace MyGUI
00138 
00139 #endif // __MYGUI_RESOURCE_IMAGE_SET_H__