FIFE  2008.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
atlasloader.h
1 /***************************************************************************
2  * Copyright (C) 2005-2011 by the FIFE team *
3  * http://www.fifengine.net *
4  * This file is part of FIFE. *
5  * *
6  * FIFE is free software; you can redistribute it and/or *
7  * modify it under the terms of the GNU Lesser General Public *
8  * License as published by the Free Software Foundation; either *
9  * version 2.1 of the License, or (at your option) any later version. *
10  * *
11  * This library is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14  * Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with this library; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20  ***************************************************************************/
21 
22 #ifndef FIFE_ATLAS_LOADER_H
23 #define FIFE_ATLAS_LOADER_H
24 
25 // Standard C++ library includes
26 
27 // 3rd party library includes
28 
29 // FIFE includes
30 // These includes are split up in two parts, separated by one empty line
31 // First block: files included from the FIFE root src directory
32 // Second block: files included from the same folder
33 #include "util/structures/rect.h"
34 #include "video/image.h"
35 #include "video/imagemanager.h"
36 
37 #include "iatlasloader.h"
38 
39 class TiXmlElement;
40 
41 namespace FIFE {
42  class VFS;
43  class ImageManager;
44 
45  struct AtlasData {
46  Rect rect;
47  ImagePtr image;
48  };
49 
50  class Atlas {
51  public:
52  Atlas(const std::string& name)
53  : m_name(name) {;}
54  ~Atlas() {;}
55 
56 
59  size_t getImageCount() const;
60 
63  ImagePtr& getPackedImage();
64 
67  ImagePtr getImage(const std::string& id);
68 
71  ImagePtr getImage(uint32_t index);
72 
77  bool addImage(const std::string& imagename, const AtlasData& data);
78 
82  void setPackedImage(const ImagePtr& image);
83 
84  const std::string& getName() const;
85  protected:
86  typedef std::map<std::string, AtlasData> SubimageMap;
87  SubimageMap m_subimages;
88  ImagePtr m_image;
89 
90  // Unique atlas name
91  std::string m_name;
92  };
93 
94  class AtlasLoader : public IAtlasLoader {
95  public:
96  AtlasLoader(Model* model, VFS* vfs, ImageManager* imageManager);
97 
98  virtual ~AtlasLoader();
99 
103  virtual bool isLoadable(const std::string& filename);
104 
108  virtual AtlasPtr load(const std::string& filename);
109 
110  private:
111  Model* m_model;
112  VFS* m_vfs;
113  ImageManager* m_imageManager;
114  std::string m_atlasFilename;
115 
116  void parseObject(Atlas* atlas, TiXmlElement* root, bool exists);
117  };
118 
123  AtlasLoader* createDefaultAtlasLoader(Model* model, VFS* vfs, ImageManager* imageManager);
124 }
125 
126 #endif