Athena IO Library
Sprite.hpp
1 #ifndef SSPRITE_HPP
2 #define SSPRITE_HPP
3 
4 #ifndef ATHENA_USE_QT
5 #include <vector>
6 #include <string>
7 #else
8 #include <QObject>
9 #include <QPoint>
10 #include <QString>
11 #include <QList>
12 #endif
13 #include "athena/SakuraGlobal.hpp"
14 
15 namespace athena
16 {
17 namespace Sakura
18 {
19 class SpriteFile;
20 class SpriteFrame;
21 
22 #ifndef ATHENA_USE_QT
23 class Sprite
24 {
25 #else
26 class Sprite : public QObject
27 {
28  Q_OBJECT
29  Q_PROPERTY(QString name READ name WRITE setName)
30  Q_PROPERTY(qreal currentState READ currentState WRITE setCurrentState)
31  Q_PROPERTY(qreal stateCount READ stateCount CONSTANT)
32 #endif
33 
34 public:
35  Sprite(SpriteFile* root);
36  Sprite(SpriteFile* root, const std::string& name);
37  virtual ~Sprite();
38 
39  virtual void setPosition(const float x, const float y);
40 #ifndef ATHENA_USE_QT
41  virtual void setPosition(const Vector2Df& pos);
42  virtual Vector2Df position() const;
43  void setName(const std::string& name);
44  std::string name() const;
45 #else
46  virtual void setPosition(const QPoint& pos);
47  virtual QPoint position() const;
48  void setName(const QString& name);
49  QString name() const;
50 #endif
51 
52  void addStateId(int id);
53 
59  int stateId(int index) const;
60  void setStateIds(std::vector<int> ids);
61 #ifndef ATHENA_USE_QT
62  std::vector<int> stateIds() const;
63 #else
64  QList<int> stateIds() const;
65 #endif
66  atUint32 stateCount() const;
67  void setCurrentState(atUint32 id);
68  atUint32 currentState() const;
69 
70  bool addFrame(SpriteFrame* Frame);
71  bool removeFrame(SpriteFrame* Frame);
72  SpriteFrame* Frame(atUint32 id);
73  void setFrame(atUint32 id);
74 #ifndef ATHENA_USE_QT
75  void setFrames(std::vector<SpriteFrame*> frames);
76 #else
77  void setFrames(QList<SpriteFrame*> frames);
78 #endif
79  atUint32 frameCount() const;
80 
81 #ifndef ATHENA_USE_QT
82  std::vector<SpriteFrame*> frames() const;
83 #else
84  QList<SpriteFrame*> frames() const;
85 #endif
86 
87  SpriteFile* container() const;
88 
89  void setCurrentFrame(SpriteFrame* frame);
90  void setCurrentFrame(atUint32 id);
91  SpriteFrame* currentFrame() const;
92 
93  void advanceFrame();
94  void retreatFrame();
95 
96  void setRoot(SpriteFile* root);
97  SpriteFile* root() const;
98 #ifdef ATHENA_USE_QT
99 signals:
100  void frameChanged(SpriteFrame* frame);
101  void nameChanged(QString);
102  void stateChanged(quint32);
103 #endif
104 private:
105  SpriteFile* m_root;
106 #ifndef ATHENA_USE_QT
107  std::string m_name;
108  Vector2Df m_position;
109  std::vector<int> m_stateIds;
110  std::vector<SpriteFrame*> m_frames;
111 #else
112  QString m_name;
113  QPoint m_position;
114  QList<int> m_stateIds;
115  QList<SpriteFrame*> m_frames;
116 #endif
117  atUint32 m_currentState;
118  atUint32 m_currentFrame;
119 };
120 
121 
122 } // Sakura
123 } // zelda
124 
125 #ifdef ATHENA_USE_QT
126 Q_DECLARE_METATYPE(Uint32)
127 Q_DECLARE_METATYPE(athena::Sakura::Sprite*)
128 #endif
129 
130 #endif // SSPRITE_HPP
int stateId(int index) const
Returns the texture id of a given state.