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