Debian Codegraph @

engine/core/loaders/native/map/atlasloader.h

raw
1 /***************************************************************************
2 * Copyright (C) 2005-2019 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 class AnimationManager;
45
46 struct AtlasData {
47 Rect rect;
48 ImagePtr image;
49 };
50
51 class Atlas {
52 public:
53 Atlas(const std::string& name)
54 : m_name(name) {;}
55 ~Atlas() {;}
56
57
58 /** Returns the number of subimages that belongs to this atlas.
59 */
60 size_t getImageCount() const;
61
62 /** Returns an (packed) Image for this atlas.
63 */
64 ImagePtr& getPackedImage();
65
66 /** Return an Image of given id.
67 */
68 ImagePtr getImage(const std::string& id);
69
70 /** Return an Image of given (serial) index in atlas
71 */
72 ImagePtr getImage(uint32_t index);
73
74 /** Adds new information about subimage that belongs to this atlas.
75 * @remarks This is essential function in parsing atlas files.
76 * @returns True, when image of given name hasn't been added before.
77 */
78 bool addImage(const std::string& imagename, const AtlasData& data);
79
80 /** Sets the image for atlas to use it for rendering.
81 * @remarks Should only be used during loading stage
82 */
83 void setPackedImage(const ImagePtr& image);
84
85 const std::string& getName() const;
86 protected:
87 typedef std::map<std::string, AtlasData> SubimageMap;
88 SubimageMap m_subimages;
89 ImagePtr m_image;
90
91 // Unique atlas name
92 std::string m_name;
93 };
94
95 class AtlasLoader : public IAtlasLoader {
96 public:
97 AtlasLoader(Model* model, VFS* vfs, ImageManager* imageManager, AnimationManager* animationManager);
98
99 virtual ~AtlasLoader();
100
101 /**
102 * @see IAtlasLoader::isLoadable
103 */
104 virtual bool isLoadable(const std::string& filename);
105
106 /**
107 * @see IAtlasLoader::load
108 */
109 virtual AtlasPtr load(const std::string& filename);
110
111 /**
112 * @see IAtlasLoader::loadMultiple
113 */
114 virtual std::vector<AtlasPtr> loadMultiple(const std::string& filename);
115
116 private:
117 AtlasPtr loadAtlas(const std::string& filename, TiXmlElement* atlasElem);
118
119 Model* m_model;
120 VFS* m_vfs;
121 ImageManager* m_imageManager;
122 AnimationManager* m_animationManager;
123 };
124
125 /** convenience function for creating the default fife atlas loader
126 * deleting the object returned from this function is the
127 * responsibility of the caller
128 */
129 AtlasLoader* createDefaultAtlasLoader(Model* model, VFS* vfs, ImageManager* imageManager, AnimationManager* animationManager);
130 }
131
132 #endif