1 /*
2     This file is part of the KDE games kwin4 program
3     SPDX-FileCopyrightText: 2006 Martin Heni <kde@heni-online.de>
4 
5     SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 
8 #ifndef PIECE_SPRITE_H
9 #define PIECE_SPRITE_H
10 
11 // own
12 #include "thememanager.h"
13 #include "pixmapsprite.h"
14 #include "spritenotify.h"
15 // Qt
16 #include <QGraphicsPixmapItem>
17 #include <QPointF>
18 
19 
20 /** The sprite for a pixmap piece on the canvas. The pixmap can be
21   * animated and moving.
22  */
23 class PieceSprite : public PixmapSprite
24 {
25 
26   public:
27     /** Constructor for the sprite.
28      */
29     PieceSprite(const QString &id, ThemeManager* theme, int no, QGraphicsScene* canvas);
30 
31     /** Destructor
32      */
33     ~PieceSprite() override;
34 
35     /** Possible animation states of the sprite
36     */
37     enum MovementState {Idle, LinearMove};
38 
39     /** Standard QGI advance function.
40      *  @param phase The advance phase
41      */
42     void advance(int phase) override;
43 
44     /** Retrieve the type of QGI. This item is UserType+2
45      *  @return The type of item.
46      */
type()47     int type() const override {return QGraphicsItem::UserType+2;}
48 
49     /** Standard Themeable function. It is called when the theme item
50       * needs to completely refresh itself.
51       */
52     void changeTheme() override;
53 
54     /** Retrieve the sprite notification object. This object indicates the
55       * end of a movement.
56       * @return The notification object.
57       */
notify()58     SpriteNotify* notify() {return mNotify;}
59 
60     /** Start a linear movement from the current position to the given
61       * end position with the given velocity.
62       * @param end      The end position in relative coordinates [rel 0..1, rel 0..1]
63       * @param velocity The velocity of the move in [relative units/sec.]
64       */
65     void startLinear(QPointF end, double velocity);
66 
67     /** Start a linear movement from the start point to the given
68       * end position with the given velocity.
69       * @param start    The start position in relative coordinates [rel 0..1, rel 0..1]
70       * @param end      The end position in relative coordinates [rel 0..1, rel 0..1]
71       * @param velocity The velocity of the move in [relative units/sec.]
72       */
73     void startLinear(QPointF start, QPointF end, double velocity);
74 
75 
76 
77   private:
78 
79     /// The duration of the movement
80     double mDuration;
81 
82     /// The state of the movement
83     MovementState mMovementState;
84 
85     /// The end points of the movement [rel]
86     QPointF mEnd;
87 
88     /// The movement sprite notifier
89     SpriteNotify* mNotify;
90 
91 };
92 
93 #endif
94