atlasloader.h

00001 /***************************************************************************
00002  *   Copyright (C) 2005-2011 by the FIFE team                              *
00003  *   http://www.fifengine.net                                              *
00004  *   This file is part of FIFE.                                            *
00005  *                                                                         *
00006  *   FIFE is free software; you can redistribute it and/or                 *
00007  *   modify it under the terms of the GNU Lesser General Public            *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2.1 of the License, or (at your option) any later version.    *
00010  *                                                                         *
00011  *   This library is distributed in the hope that it will be useful,       *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00014  *   Lesser General Public License for more details.                       *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Lesser General Public      *
00017  *   License along with this library; if not, write to the                 *
00018  *   Free Software Foundation, Inc.,                                       *
00019  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
00020  ***************************************************************************/
00021 
00022 #ifndef FIFE_ATLAS_LOADER_H
00023 #define FIFE_ATLAS_LOADER_H
00024 
00025 // Standard C++ library includes
00026 
00027 // 3rd party library includes
00028 
00029 // FIFE includes
00030 // These includes are split up in two parts, separated by one empty line
00031 // First block: files included from the FIFE root src directory
00032 // Second block: files included from the same folder
00033 #include "util/structures/rect.h" 
00034 #include "video/image.h" 
00035 #include "video/imagemanager.h" 
00036 
00037 #include "iatlasloader.h"
00038 
00039 class TiXmlElement;
00040 
00041 namespace FIFE {
00042     class VFS;
00043     class ImageManager;
00044 
00045     struct AtlasData {
00046         Rect rect;
00047         ImagePtr image;
00048     };
00049 
00050     class Atlas {
00051     public:
00052         Atlas(const std::string& name)
00053             : m_name(name) {;}
00054         ~Atlas() {;}
00055 
00056 
00059         size_t getImageCount() const;
00060 
00063         ImagePtr& getPackedImage();
00064 
00067         ImagePtr getImage(const std::string& id);
00068 
00071         ImagePtr getImage(uint32_t index);
00072 
00077         bool addImage(const std::string& imagename, const AtlasData& data);
00078 
00082         void setPackedImage(const ImagePtr& image);
00083 
00084         const std::string& getName() const;
00085     protected:
00086         typedef std::map<std::string, AtlasData> SubimageMap;
00087         SubimageMap m_subimages;
00088         ImagePtr m_image;
00089 
00090         // Unique atlas name
00091         std::string m_name;
00092     };
00093 
00094     class AtlasLoader : public IAtlasLoader {
00095     public:
00096         AtlasLoader(Model* model, VFS* vfs, ImageManager* imageManager);
00097 
00098         virtual ~AtlasLoader();
00099 
00103         virtual bool isLoadable(const std::string& filename);
00104 
00108         virtual AtlasPtr load(const std::string& filename);
00109 
00110     private:
00111         Model* m_model;
00112         VFS* m_vfs;
00113         ImageManager* m_imageManager;
00114         std::string m_atlasFilename;
00115 
00116         void parseObject(Atlas* atlas, TiXmlElement* root, bool exists);
00117     };
00118 
00123     AtlasLoader* createDefaultAtlasLoader(Model* model, VFS* vfs, ImageManager* imageManager);
00124 }
00125 
00126 #endif