File indexing completed on 2022-10-04 14:29:25

0001 /*
0002     SPDX-FileCopyrightText: 2007 Paolo Capriotti <p.capriotti@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef ANIMATION_H
0008 #define ANIMATION_H
0009 
0010 #include <QPointF>
0011 #include <QList>
0012 #include <QQueue>
0013 #include <QObject>
0014 #include "spritefwd.h"
0015 
0016 class Animation : public QObject
0017 {
0018 Q_OBJECT
0019 public:
0020     ~Animation() override;
0021     
0022     virtual void start(int t) = 0;
0023     virtual bool step(int t) = 0;
0024 public Q_SLOTS:
0025     virtual void stop() = 0;
0026 Q_SIGNALS:
0027     void over();
0028 };
0029 
0030 class PauseAnimation : public Animation
0031 {
0032 Q_OBJECT
0033     int m_time;
0034     int m_start;
0035 public:
0036     explicit PauseAnimation(int time);
0037     
0038     void start(int t) override;
0039     bool step(int t) override;
0040     void stop() override { }
0041 };
0042 
0043 class FadeAnimation : public Animation
0044 {
0045 Q_OBJECT
0046     SpritePtr m_sprite;
0047     double m_from;
0048     double m_to;
0049     int m_time;
0050     int m_start;
0051     
0052     bool m_stopped;
0053 public:
0054     FadeAnimation(const SpritePtr& sprite, double from, double to, int time);
0055     
0056     void start(int t) override;
0057     bool step(int t) override;
0058     void stop() override;
0059 };
0060 
0061 class MovementAnimation : public Animation
0062 {
0063 Q_OBJECT
0064     SpritePtr m_sprite;
0065     QPointF m_from;
0066     QPointF m_velocity;
0067     int m_time;
0068     int m_last;
0069 public:
0070     MovementAnimation(const SpritePtr& sprite, const QPointF& from, 
0071                       const QPointF& velocity, int time);
0072     
0073     void start(int t) override;
0074     bool step(int t) override;
0075     void stop() override;
0076 };
0077 
0078 
0079 class AnimationGroup : public Animation
0080 {
0081 Q_OBJECT
0082     typedef QList<Animation*> List;
0083     List m_animations;
0084     int m_last;
0085 public:
0086     AnimationGroup();
0087     
0088     void add(Animation* animation);
0089     
0090     void start(int t) override;
0091     bool step(int t) override;
0092     void stop() override;
0093 };
0094 
0095 class AnimationSequence : public Animation
0096 {
0097 Q_OBJECT
0098     QQueue<Animation*> m_animations;
0099     int m_last;
0100 public:
0101     AnimationSequence();
0102     
0103     void add(Animation* animation);
0104     
0105     void start(int t) override;
0106     bool step(int t) override;
0107     void stop() override;
0108 };
0109 
0110 #endif // ANIMATION_H
0111