Created SimpleAnimator stub.
[tagua/yd.git] / src / animationfactory.h
blob59b305841e32a75636137e955acd56e161a6a62b
1 /*
2 Copyright (c) 2007 Paolo Capriotti <p.capriotti@gmail.com>
3 (c) 2007 Maurizio Monge <maurizio.monge@kdemail.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 */
11 #ifndef ANIMATIONFACTORY_H
12 #define ANIMATIONFACTORY_H
14 #include "animation.h"
15 #include "fwd.h"
16 #include "point.h"
18 class NamedSprite;
19 class PointConverter;
20 class GraphicalAPI;
22 namespace Animate {
24 /**
25 * AnimationType distinguishes between those animations which honor settings
26 * and those that are instantaneous regardless of user preferences.
28 enum AnimationType {
29 Normal, /// Honor user settings.
30 Instant /// Instantaneous animation.
33 /**
34 * @brief A scheme of animations.
36 * Animation schemes are descriptions of an animation, i.e. what the animation
37 * should suggest to the user. The actual Animation class implementing the scheme
38 * depends of various factors, such as the AnimationType that the animator imposes
39 * and user settings.
41 class Scheme {
42 public:
43 virtual ~Scheme();
45 /**
46 * Convert the scheme into an actual animation which can be enqueued in the
47 * animation system, or grouped into an AnimationGroup.
49 virtual AnimationPtr run(const PointConverter*, AnimationType) const = 0;
54 /**
55 * @brief A convenience wrapper around an AnimationGroup, useful for Animators.
57 * An AnimationFactory is a wrapper around AnimationGroup that accepts shemes instead
58 * of Animations in its addPreAnimation() and addPostAnimation() methods.
59 * It offers a convenient syntax to an animator when composing animations into groups.
61 class AnimationFactory {
62 AnimationGroupPtr m_group;
63 GraphicalAPI* m_api;
64 public:
65 AnimationFactory(GraphicalAPI* api);
67 /** \return The wrapped animation group. */
68 AnimationGroupPtr group() const;
70 /**
71 * Add a pre-animation to the group.
72 * \param scheme The scheme producing the animation to be added.
73 * \param type The AnimationType to be used when creating the animation.
75 void addPreAnimation(const Animate::Scheme& scheme, Animate::AnimationType type = Animate::Normal);
77 /**
78 * Add a post-animation to the group.
79 * \param scheme The scheme producing the animation to be added.
80 * \param type The AnimationType to be used when creating the animation.
82 void addPostAnimation(const Animate::Scheme& scheme, Animate::AnimationType type = Animate::Normal);
84 /**
85 * Implicitly convert the object to an AnimationGroup shared pointer,
86 * using the group() member function.
88 operator AnimationGroupPtr() const;
92 namespace Animate {
94 /**
95 * @brief A movement animation scheme.
97 * Used to animate the movement of a piece to a destination square.
99 class move : public Scheme {
100 public:
101 enum MovementType {
102 Straight = 0x00,
103 Rotating = 0x01,
104 LShaped = 0x02
106 private:
107 const NamedSprite& m_sprite;
108 Point m_to;
109 int m_type;
110 public:
111 move(const NamedSprite& sprite, const Point& to, int type = Straight);
112 virtual AnimationPtr run(const PointConverter* converter, AnimationType type) const;
116 * @brief Appear animation scheme.
118 * The appear scheme visualizes a new piece coming into existence. It is
119 * used, for example, when retracting a capture in chess, to restore the captured
120 * piece on the chessboard.
122 class appear : public Scheme {
123 const NamedSprite& m_sprite;
124 public:
125 appear(const NamedSprite& sprite);
126 virtual AnimationPtr run(const PointConverter* converter, AnimationType type) const;
130 * @brief Disappear animation scheme.
132 * The disappear scheme visualizes a piece being removed from the board.
134 class disappear : public Scheme {
135 const NamedSprite& m_sprite;
136 public:
137 disappear(const NamedSprite& sprite);
138 virtual AnimationPtr run(const PointConverter* converter, AnimationType type) const;
142 * @brief Animation scheme destroying a piece.
144 * This animation scheme is used to destroy a piece, removing it from the
145 * board. It is similar to the disappear scheme, but can provide an additional
146 * effect like an explosion.
148 class destroy : public Scheme {
149 const NamedSprite& m_sprite;
150 public:
151 destroy(const NamedSprite& sprite);
152 virtual AnimationPtr run(const PointConverter* converter, AnimationType type) const;
156 * @brief Animation scheme for changing a piece into another.
158 * The morph animation scheme is used when a piece changes, like in chess promotions.
160 class morph : public Scheme {
161 const NamedSprite& m_sprite;
162 const NamedSprite& m_new_sprite;
163 public:
164 morph(const NamedSprite& sprite, const NamedSprite& new_sprite);
165 virtual AnimationPtr run(const PointConverter* converter, AnimationType type) const;
172 #endif // ANIMATIONFACTORY_H