Athena IO Library
SpriteFile.hpp
1 #ifndef SSPRITEFILE_HPP
2 #define SSPRITEFILE_HPP
3 
4 #ifndef ATHENA_USE_QT
5 #include <vector>
6 #include <unordered_map>
7 #else
8 #include <QObject>
9 #include <QMap>
10 #include <QList>
11 #include <QSize>
12 #include <QPoint>
13 #endif
14 
15 #include <string>
16 #include "athena/SakuraGlobal.hpp"
17 
18 namespace athena
19 {
20 namespace Sakura
21 {
22 struct STexture
23 {
24  std::string Filepath;
25  bool Preload;
26 };
27 
28 class Sprite;
29 #ifndef ATHENA_USE_QT
31 {
32 #else
33 class SpriteFile : public QObject
34 {
35  Q_OBJECT
36 #endif
37 public:
41  static const atUint32 Major;
42 
46  static const atUint32 Minor;
47 
51  static const atUint32 Revision;
52 
56  static const atUint32 Build;
57 
61  static const atUint32 Version;
62 
66  static const atUint32 Magic;
67 
71  SpriteFile();
72 
80  SpriteFile(atUint32 width, atUint32 height, float originX, float originY);
81 
87 #ifndef ATHENA_USE_QT
88  SpriteFile(const Vector2Di& size, const Vector2Df& origin);
89 #else
90  SpriteFile(const QSize& size, const QPoint& origin);
91 #endif
92 
93  ~SpriteFile();
94 
95 #ifndef ATHENA_USE_QT
96 public:
97 #else
98 public slots:
99 #endif
100 
106  void setSize(atUint32 width, atUint32 height);
107 
112 #ifndef ATHENA_USE_QT
113  void setSize(const Vector2Di& size);
114 #else
115  void setSize(const QSize& size);
116 #endif
117 
122 #ifndef ATHENA_USE_QT
123  Vector2Di size() const;
124 #else
125  QSize size() const;
126 #endif
127 
132  atUint32 width() const;
133 
138  atUint32 height() const;
139 
145  void setOrigin(const float x, const float y);
146 
151 #ifndef ATHENA_USE_QT
152  void setOrigin(const Vector2Df& origin);
153 #else
154  void setOrigin(const QPoint& origin);
155 #endif
156 
161 #ifndef ATHENA_USE_QT
162  Vector2Df origin() const;
163 #else
164  QPoint origin() const;
165 #endif
166 
167 
172  float originX() const;
173 
178  float originY() const;
179 
184  bool addTexture(STexture* texture);
185 
190  void removeTexture(int id);
191 
197  STexture* texture(atUint32 id);
198 
199 #ifndef ATHENA_USE_QT
200  std::vector<STexture*> textures() const;
201 #else
202  QList<STexture*> textures() const;
203 #endif
204  atUint32 textureCount() const;
210 #ifndef ATHENA_USE_QT
211  void setTextures(std::vector<STexture*> textures);
212 #else
213  void setTextures(QList<STexture*> textures);
214 #endif
215 
216  void addSprite(Sprite* sprite);
217 
218 #ifndef ATHENA_USE_QT
219  void removeSprite(const std::string& name);
220 #else
221  void removeSprite(const QString& name);
222 #endif
223  void removeSprite(Sprite* sprite);
224 
225 #ifndef ATHENA_USE_QT
226  void setSprites(std::unordered_map<std::string, Sprite*> sprites);
227 #else
228  void setSprites(QMap<QString, Sprite*> sprites);
229 #endif
230 #ifndef ATHENA_USE_QT
231  Sprite* sprite(const std::string& name);
232  std::unordered_map<std::string, Sprite*> sprites() const;
233 #else
234  Sprite* sprite(const QString& name);
235  QMap<QString, Sprite*> sprites() const;
236 #endif
237 
238  atUint32 spriteCount() const;
239 
240 #ifdef ATHENA_USE_QT
241 signals:
242  void originChanged(QPoint);
243  void sizeChanged(QSize);
244 #endif
245 private:
246 #ifndef ATHENA_USE_QT
247  std::vector<STexture*> m_textures;
248  Vector2Di m_size;
249  Vector2Df m_origin;
250  std::unordered_map<std::string, Sprite*> m_sprites;
251 #else
252  QList<STexture*> m_textures;
253  QSize m_size;
254  QPoint m_origin;
255  QMap<QString, Sprite*> m_sprites;
256 #endif
257 };
258 } // Sakura
259 } // Zelda
260 
261 #ifdef ATHENA_USE_QT
262 Q_DECLARE_METATYPE(athena::Sakura::SpriteFile*)
263 Q_DECLARE_METATYPE(athena::Sakura::STexture*)
264 #endif
265 #endif // SSPRITE_HPP
static const atUint32 Version
Version.
Definition: SpriteFile.hpp:61
static const atUint32 Revision
Revision.
Definition: SpriteFile.hpp:51
static const atUint32 Major
Major.
Definition: SpriteFile.hpp:41
static const atUint32 Minor
Minor.
Definition: SpriteFile.hpp:46
static const atUint32 Build
Patch.
Definition: SpriteFile.hpp:56
static const atUint32 Magic
Magic.
Definition: SpriteFile.hpp:66