Athena IO Library
SpritePart.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 SSPRITEPART_HPP
18 #define SSPRITEPART_HPP
19 
20 #include "Athena/Global.hpp"
21 #ifndef ATHENA_USE_QT
22 # include <vector>
23 #else
24 # include <QObject>
25 # include <QPoint>
26 # include <QSize>
27 # include <QString>
28 #endif
29 
30 #include <string>
31 
32 namespace Athena
33 {
34 namespace Sakura
35 {
36 class SpriteFrame;
37 
38 #ifndef ATHENA_USE_QT
40 {
41 #else
42 class SpritePart : public QObject
43 {
44  Q_OBJECT
45  Q_PROPERTY(QString name READ name WRITE setName)
46  Q_PROPERTY(bool hasCollision READ hasCollision WRITE setCollision)
48  Q_PROPERTY(bool flippedVertically READ flippedVertically WRITE setFlippedVertically)
49  Q_PROPERTY(QPoint offset READ offset WRITE setOffset)
50  Q_PROPERTY(QPoint textureOffset READ textureOffset WRITE setTextureOffset)
51  Q_PROPERTY(QSize size READ size WRITE setSize)
52 #endif
53 public:
54  SpritePart(SpriteFrame* root);
55  SpritePart(SpriteFrame* root, const std::string& name, bool hasCollision = false);
56  virtual ~SpritePart();
57 
58 
59 #ifndef ATHENA_USE_QT
60  void setName(const std::string& name);
61  std::string name() const;
62 #else
63  void setName(const QString& name);
64  QString name() const;
65 #endif
66 
67  void setCollision(bool col);
68  bool hasCollision() const;
69 
75  void setOffset(float x, float y);
76 
81 #ifndef ATHENA_USE_QT
82  void setOffset(const Vector2Df& offset);
83 #else
84  void setOffset(const QPoint& offset);
85 #endif
86 
91 #ifndef ATHENA_USE_QT
92  Vector2Df offset() const;
93 #else
94  QPoint offset() const;
95 #endif
96 
102  void setTextureOffset(float x, float y);
103 
108 #ifndef ATHENA_USE_QT
109  void setTextureOffset(const Vector2Df& offset);
110 #else
111  void setTextureOffset(const QPoint& offset);
112 #endif
113 
118 #ifndef ATHENA_USE_QT
119  Vector2Df textureOffset() const;
120 #else
121  QPoint textureOffset() const;
122 #endif
123 
129  void setSize(atUint32 width, atUint32 height);
130 
135 #ifndef ATHENA_USE_QT
136  void setSize(const Vector2Di& size);
137 #else
138  void setSize(const QSize& size);
139 #endif
140 
145 #ifndef ATHENA_USE_QT
146  Vector2Di size() const;
147 #else
148  QSize size() const;
149 #endif
150 
155  void setFlippedHorizontally(const bool val);
156 
161  bool flippedHorizontally() const;
162 
167  void setFlippedVertically(const bool val);
168 
173  bool flippedVertically() const;
174 
175  void setRoot(SpriteFrame* root);
176  SpriteFrame* root() const;
177 
178 #ifdef ATHENA_USE_QT
179 signals:
180  void nameChanged(QString);
181  void orientationChanged(bool, bool);
182  void offsetChanged(QPoint);
183  void textureOffsetChanged(QPoint);
184  void sizeChanged(QSize);
185  void collisionChanged(bool);
186 #endif
187 
188 private:
189  SpriteFrame* m_root;
190 #ifndef ATHENA_USE_QT
191  std::string m_name;
192 #else
193  QString m_name;
194 #endif
195  bool m_hasCollision;
196 #ifndef ATHENA_USE_QT
197  Vector2Df m_offset;
198  Vector2Df m_textureOffset;
199  Vector2Di m_size;
200 #else
201  QPoint m_offset;
202  QPoint m_textureOffset;
203  QSize m_size;
204 #endif
205  bool m_flippedH;
206  bool m_flippedV;
207  atUint32 m_frameIndex;
208 };
209 
210 }
211 }
212 #ifdef ATHENA_USE_QT
213 Q_DECLARE_METATYPE(Athena::Sakura::SpritePart*)
214 #endif
215 
216 #endif // SSPRITEPART_HPP
217 #endif // ATHENA_NO_SAKURA
void setFlippedHorizontally(const bool val)
setFlippedHorizontally
void setTextureOffset(float x, float y)
setTextureOffset
Vector2Df textureOffset() const
textureOffset
void setOffset(float x, float y)
setOffset
void setSize(atUint32 width, atUint32 height)
setSize
Vector2Df offset() const
offset
bool flippedHorizontally() const
flippedHorizontally
void setFlippedVertically(const bool val)
setFlippedVertically
bool flippedVertically() const
flippedVertically
Vector2Di size() const
size