2014-01-26 04:56:04 +00:00
|
|
|
#ifndef SSPRITE_HPP
|
|
|
|
#define SSPRITE_HPP
|
|
|
|
|
2014-04-20 10:28:28 +00:00
|
|
|
#ifndef ATHENA_USE_QT
|
2014-01-26 04:56:04 +00:00
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
2014-02-27 05:47:39 +00:00
|
|
|
#else
|
|
|
|
#include <QObject>
|
|
|
|
#include <QPoint>
|
|
|
|
#include <QString>
|
|
|
|
#include <QList>
|
|
|
|
#endif
|
2016-03-04 23:00:12 +00:00
|
|
|
#include "athena/SakuraGlobal.hpp"
|
2014-01-26 04:56:04 +00:00
|
|
|
|
2016-03-04 23:00:12 +00:00
|
|
|
namespace athena
|
2014-01-26 04:56:04 +00:00
|
|
|
{
|
|
|
|
namespace Sakura
|
|
|
|
{
|
|
|
|
class SpriteFile;
|
2014-02-27 05:47:39 +00:00
|
|
|
class SpriteFrame;
|
2014-01-26 04:56:04 +00:00
|
|
|
|
2014-04-20 10:28:28 +00:00
|
|
|
#ifndef ATHENA_USE_QT
|
2014-01-26 04:56:04 +00:00
|
|
|
class Sprite
|
|
|
|
{
|
2014-02-27 05:47:39 +00:00
|
|
|
#else
|
|
|
|
class Sprite : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
Q_PROPERTY(QString name READ name WRITE setName)
|
|
|
|
Q_PROPERTY(qreal currentState READ currentState WRITE setCurrentState)
|
|
|
|
Q_PROPERTY(qreal stateCount READ stateCount CONSTANT)
|
|
|
|
#endif
|
|
|
|
|
2014-01-26 04:56:04 +00:00
|
|
|
public:
|
|
|
|
Sprite(SpriteFile* root);
|
|
|
|
Sprite(SpriteFile* root, const std::string& name);
|
|
|
|
virtual ~Sprite();
|
|
|
|
|
|
|
|
virtual void setPosition(const float x, const float y);
|
2014-04-20 10:28:28 +00:00
|
|
|
#ifndef ATHENA_USE_QT
|
2014-01-26 04:56:04 +00:00
|
|
|
virtual void setPosition(const Vector2Df& pos);
|
2014-02-27 05:47:39 +00:00
|
|
|
virtual Vector2Df position() const;
|
2014-01-26 04:56:04 +00:00
|
|
|
void setName(const std::string& name);
|
|
|
|
std::string name() const;
|
2014-02-27 05:47:39 +00:00
|
|
|
#else
|
|
|
|
virtual void setPosition(const QPoint& pos);
|
|
|
|
virtual QPoint position() const;
|
|
|
|
void setName(const QString& name);
|
|
|
|
QString name() const;
|
|
|
|
#endif
|
2014-01-26 04:56:04 +00:00
|
|
|
|
|
|
|
void addStateId(int id);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Returns the texture id of a given state
|
|
|
|
* \param index The index of the id.
|
|
|
|
* \return return the state id if it exists, -1 otherwise
|
|
|
|
*/
|
|
|
|
int stateId(int index) const;
|
|
|
|
void setStateIds(std::vector<int> ids);
|
2014-04-20 10:28:28 +00:00
|
|
|
#ifndef ATHENA_USE_QT
|
2014-01-26 04:56:04 +00:00
|
|
|
std::vector<int> stateIds() const;
|
2014-02-27 05:47:39 +00:00
|
|
|
#else
|
|
|
|
QList<int> stateIds() const;
|
|
|
|
#endif
|
2014-06-18 04:51:18 +00:00
|
|
|
atUint32 stateCount() const;
|
|
|
|
void setCurrentState(atUint32 id);
|
|
|
|
atUint32 currentState() const;
|
2014-01-26 04:56:04 +00:00
|
|
|
|
2014-02-27 05:47:39 +00:00
|
|
|
bool addFrame(SpriteFrame* Frame);
|
|
|
|
bool removeFrame(SpriteFrame* Frame);
|
2014-06-18 04:51:18 +00:00
|
|
|
SpriteFrame* Frame(atUint32 id);
|
|
|
|
void setFrame(atUint32 id);
|
2014-04-20 10:28:28 +00:00
|
|
|
#ifndef ATHENA_USE_QT
|
2014-02-27 05:47:39 +00:00
|
|
|
void setFrames(std::vector<SpriteFrame*> frames);
|
|
|
|
#else
|
|
|
|
void setFrames(QList<SpriteFrame*> frames);
|
|
|
|
#endif
|
2014-06-18 04:51:18 +00:00
|
|
|
atUint32 frameCount() const;
|
2014-01-26 04:56:04 +00:00
|
|
|
|
2014-04-20 10:28:28 +00:00
|
|
|
#ifndef ATHENA_USE_QT
|
2014-02-27 05:47:39 +00:00
|
|
|
std::vector<SpriteFrame*> frames() const;
|
|
|
|
#else
|
|
|
|
QList<SpriteFrame*> frames() const;
|
|
|
|
#endif
|
2014-01-26 04:56:04 +00:00
|
|
|
|
|
|
|
SpriteFile* container() const;
|
|
|
|
|
2014-02-27 05:47:39 +00:00
|
|
|
void setCurrentFrame(SpriteFrame* frame);
|
2014-06-18 04:51:18 +00:00
|
|
|
void setCurrentFrame(atUint32 id);
|
2014-02-27 05:47:39 +00:00
|
|
|
SpriteFrame* currentFrame() const;
|
|
|
|
|
|
|
|
void advanceFrame();
|
|
|
|
void retreatFrame();
|
|
|
|
|
|
|
|
void setRoot(SpriteFile* root);
|
|
|
|
SpriteFile* root() const;
|
2014-04-20 10:28:28 +00:00
|
|
|
#ifdef ATHENA_USE_QT
|
2014-02-27 05:47:39 +00:00
|
|
|
signals:
|
|
|
|
void frameChanged(SpriteFrame* frame);
|
|
|
|
void nameChanged(QString);
|
|
|
|
void stateChanged(quint32);
|
|
|
|
#endif
|
|
|
|
private:
|
|
|
|
SpriteFile* m_root;
|
2014-04-20 10:28:28 +00:00
|
|
|
#ifndef ATHENA_USE_QT
|
2014-02-27 05:47:39 +00:00
|
|
|
std::string m_name;
|
|
|
|
Vector2Df m_position;
|
|
|
|
std::vector<int> m_stateIds; //!< Stores the texture id's for each state.
|
|
|
|
std::vector<SpriteFrame*> m_frames;
|
|
|
|
#else
|
|
|
|
QString m_name;
|
|
|
|
QPoint m_position;
|
|
|
|
QList<int> m_stateIds;
|
|
|
|
QList<SpriteFrame*> m_frames;
|
|
|
|
#endif
|
2014-06-18 04:51:18 +00:00
|
|
|
atUint32 m_currentState;
|
|
|
|
atUint32 m_currentFrame;
|
2014-01-26 04:56:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // Sakura
|
|
|
|
} // zelda
|
|
|
|
|
2014-04-20 10:28:28 +00:00
|
|
|
#ifdef ATHENA_USE_QT
|
2014-02-27 05:47:39 +00:00
|
|
|
Q_DECLARE_METATYPE(Uint32)
|
2016-03-04 23:00:12 +00:00
|
|
|
Q_DECLARE_METATYPE(athena::Sakura::Sprite*)
|
2014-02-27 05:47:39 +00:00
|
|
|
#endif
|
|
|
|
|
2014-01-26 04:56:04 +00:00
|
|
|
#endif // SSPRITE_HPP
|