Athena IO Library
SpriteFile.hpp
1 #ifndef ATHENA_NO_SAKURA
2 // This file is part of libAthena.
3 //
4 // libAthena is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // libAthena is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with libAthena. If not, see <http://www.gnu.org/licenses/>
16 
17 #ifndef SSPRITEFILE_HPP
18 #define SSPRITEFILE_HPP
19 
20 #ifndef ATHENA_USE_QT
21 #include <vector>
22 #include <unordered_map>
23 #else
24 #include <QObject>
25 #include <QMap>
26 #include <QList>
27 #include <QSize>
28 #include <QPoint>
29 #endif
30 
31 #include <string>
32 #include "Athena/Global.hpp"
33 
34 namespace Athena
35 {
36 namespace Sakura
37 {
38 struct STexture
39 {
40  std::string Filepath;
41  bool Preload;
42 };
43 
44 class Sprite;
45 #ifndef ATHENA_USE_QT
47 {
48 #else
49 class SpriteFile : public QObject
50 {
51  Q_OBJECT
52 #endif
53 public:
57  static const atUint32 Major;
58 
62  static const atUint32 Minor;
63 
67  static const atUint32 Revision;
68 
72  static const atUint32 Build;
73 
77  static const atUint32 Version;
78 
82  static const atUint32 Magic;
83 
87  SpriteFile();
88 
96  SpriteFile(atUint32 width, atUint32 height, float originX, float originY);
97 
103 #ifndef ATHENA_USE_QT
104  SpriteFile(const Vector2Di& size, const Vector2Df& origin);
105 #else
106  SpriteFile(const QSize& size, const QPoint& origin);
107 #endif
108 
109  ~SpriteFile();
110 
111 #ifndef ATHENA_USE_QT
112 public:
113 #else
114 public slots:
115 #endif
116 
122  void setSize(atUint32 width, atUint32 height);
123 
128 #ifndef ATHENA_USE_QT
129  void setSize(const Vector2Di& size);
130 #else
131  void setSize(const QSize& size);
132 #endif
133 
138 #ifndef ATHENA_USE_QT
139  Vector2Di size() const;
140 #else
141  QSize size() const;
142 #endif
143 
148  atUint32 width() const;
149 
154  atUint32 height() const;
155 
161  void setOrigin(const float x, const float y);
162 
167 #ifndef ATHENA_USE_QT
168  void setOrigin(const Vector2Df& origin);
169 #else
170  void setOrigin(const QPoint& origin);
171 #endif
172 
177 #ifndef ATHENA_USE_QT
178  Vector2Df origin() const;
179 #else
180  QPoint origin() const;
181 #endif
182 
183 
188  float originX() const;
189 
194  float originY() const;
195 
200  bool addTexture(STexture* texture);
201 
206  void removeTexture(int id);
207 
213  STexture* texture(atUint32 id);
214 
215 #ifndef ATHENA_USE_QT
216  std::vector<STexture*> textures() const;
217 #else
218  QList<STexture*> textures() const;
219 #endif
220  atUint32 textureCount() const;
226 #ifndef ATHENA_USE_QT
227  void setTextures(std::vector<STexture*> textures);
228 #else
229  void setTextures(QList<STexture*> textures);
230 #endif
231 
232  void addSprite(Sprite* sprite);
233 
234 #ifndef ATHENA_USE_QT
235  void removeSprite(const std::string& name);
236 #else
237  void removeSprite(const QString& name);
238 #endif
239  void removeSprite(Sprite* sprite);
240 
241 #ifndef ATHENA_USE_QT
242  void setSprites(std::unordered_map<std::string, Sprite*> sprites);
243 #else
244  void setSprites(QMap<QString, Sprite*> sprites);
245 #endif
246 #ifndef ATHENA_USE_QT
247  Sprite* sprite(const std::string& name);
248  std::unordered_map<std::string, Sprite*> sprites() const;
249 #else
250  Sprite* sprite(const QString& name);
251  QMap<QString, Sprite*> sprites() const;
252 #endif
253 
254  atUint32 spriteCount() const;
255 
256 #ifdef ATHENA_USE_QT
257 signals:
258  void originChanged(QPoint);
259  void sizeChanged(QSize);
260 #endif
261 private:
262 #ifndef ATHENA_USE_QT
263  std::vector<STexture*> m_textures;
264  Vector2Di m_size;
265  Vector2Df m_origin;
266  std::unordered_map<std::string, Sprite*> m_sprites;
267 #else
268  QList<STexture*> m_textures;
269  QSize m_size;
270  QPoint m_origin;
271  QMap<QString, Sprite*> m_sprites;
272 #endif
273 };
274 } // Sakura
275 } // Zelda
276 
277 #ifdef ATHENA_USE_QT
278 Q_DECLARE_METATYPE(Athena::Sakura::SpriteFile*)
279 Q_DECLARE_METATYPE(Athena::Sakura::STexture*)
280 #endif
281 #endif // SSPRITE_HPP
282 
283 #endif // ATHENA_NO_SAKURA
284 
void setSize(atUint32 width, atUint32 height)
setSize
float originY() const
originY
bool addTexture(STexture *texture)
addTexture
static const atUint32 Revision
Revision.
Definition: SpriteFile.hpp:67
void setTextures(std::vector< STexture * > textures)
setTextures
static const atUint32 Major
Major.
Definition: SpriteFile.hpp:57
Vector2Df origin() const
origin
float originX() const
originX
void removeTexture(int id)
removeTexture
static const atUint32 Magic
Magic.
Definition: SpriteFile.hpp:82
Vector2Di size() const
size
static const atUint32 Build
Patch.
Definition: SpriteFile.hpp:72
static const atUint32 Minor
Minor.
Definition: SpriteFile.hpp:62
static const atUint32 Version
Version.
Definition: SpriteFile.hpp:77
atUint32 width() const
width
void setOrigin(const float x, const float y)
setOrigin
STexture * texture(atUint32 id)
texture
atUint32 height() const
height