Fix debian/rules to build in BUILD/ dir.
[tagua/yd.git] / src / animationfactory.h
blobc38fa8e3286db9a3fccfd4a15531102722385a5a
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 IndexConverter;
21 class GraphicalAPI;
22 class AnimationSettings;
24 namespace Animate {
26 /**
27 * AnimationType distinguishes between those animations which honor settings
28 * and those that are instantaneous regardless of user preferences.
30 enum AnimationType {
31 Normal, /// Honor user settings.
32 Instant /// Instantaneous animation.
35 /**
36 * @brief A scheme of animations.
38 * Animation schemes are descriptions of an animation, i.e. what the animation
39 * should suggest to the user. The actual Animation class implementing the scheme
40 * depends of various factors, such as the AnimationType that the animator imposes
41 * and user settings.
43 class Scheme {
44 public:
45 virtual ~Scheme();
47 /**
48 * Convert the scheme into an actual animation which can be enqueued in the
49 * animation system, or grouped into an AnimationGroup.
51 virtual AnimationPtr run(const AnimationSettings& s, const PointConverter*, AnimationType) const = 0;
56 struct AnimationSettings {
57 bool enabled;
59 int maxSequence;
60 bool movement;
61 bool explode;
62 bool fading;
63 bool transform;
65 AnimationSettings();
66 void reload();
69 /**
70 * @brief A convenience wrapper around an AnimationGroup, useful for Animators.
72 * An AnimationFactory is a wrapper around AnimationGroup that accepts shemes instead
73 * of Animations in its addPreAnimation() and addPostAnimation() methods.
74 * It offers a convenient syntax to an animator when composing animations into groups.
76 class AnimationFactory {
77 AnimationGroupPtr m_group;
78 GraphicalAPI* m_api;
79 public:
80 AnimationFactory(GraphicalAPI* api);
82 /** \return The wrapped animation group. */
83 AnimationGroupPtr group() const;
85 /** Change the wrapped animation group. */
86 void setGroup(const AnimationGroupPtr& group);
88 /**
89 * Add a pre-animation to the group.
90 * \param scheme The scheme producing the animation to be added.
91 * \param type The AnimationType to be used when creating the animation.
93 void addPreAnimation(const Animate::Scheme& scheme, Animate::AnimationType type = Animate::Normal);
95 /**
96 * Add a post-animation to the group.
97 * \param scheme The scheme producing the animation to be added.
98 * \param type The AnimationType to be used when creating the animation.
100 void addPostAnimation(const Animate::Scheme& scheme, Animate::AnimationType type = Animate::Normal);
102 /**
103 * Implicitly convert the object to an AnimationGroup shared pointer,
104 * using the group() member function.
106 operator AnimationGroupPtr() const;
109 namespace Animate {
112 * @brief A movement animation scheme.
114 * Used to animate the movement of a piece on the board to a destination square.
116 class move : public Scheme {
117 public:
118 enum MovementType {
119 Straight = 0x00,
120 Rotating = 0x01,
121 LShaped = 0x02
123 private:
124 const NamedSprite& m_sprite;
125 Point m_to;
126 int m_type;
127 public:
128 move(const NamedSprite& sprite, const Point& to, int type = Straight);
129 virtual AnimationPtr run(const AnimationSettings& s, const PointConverter* converter, AnimationType type) const;
133 * @brief Appear animation scheme.
135 * The appear scheme visualizes a new piece coming into existence. It is
136 * used, for example, when retracting a capture in chess, to restore the captured
137 * piece on the chessboard.
139 class appear : public Scheme {
140 const NamedSprite& m_sprite;
141 public:
142 appear(const NamedSprite& sprite);
143 virtual AnimationPtr run(const AnimationSettings& s, const PointConverter* converter, AnimationType type) const;
147 * @brief Disappear animation scheme.
149 * The disappear scheme visualizes a piece being removed from the board.
151 class disappear : public Scheme {
152 const NamedSprite& m_sprite;
153 public:
154 disappear(const NamedSprite& sprite);
155 virtual AnimationPtr run(const AnimationSettings& s, const PointConverter* converter, AnimationType type) const;
159 * @brief Animation scheme destroying a piece.
161 * This animation scheme is used to destroy a piece, removing it from the
162 * board. It is similar to the disappear scheme, but can provide an additional
163 * effect like an explosion.
165 class destroy : public Scheme {
166 const NamedSprite& m_sprite;
167 public:
168 destroy(const NamedSprite& sprite);
169 virtual AnimationPtr run(const AnimationSettings& s, const PointConverter* converter, AnimationType type) const;
173 * @brief Animation scheme for changing a piece into another.
175 * The morph animation scheme is used when a piece changes, like in chess promotions.
177 class morph : public Scheme {
178 const NamedSprite& m_sprite;
179 const NamedSprite& m_new_sprite;
180 public:
181 morph(const NamedSprite& sprite, const NamedSprite& new_sprite);
182 virtual AnimationPtr run(const AnimationSettings& s, const PointConverter* converter, AnimationType type) const;
186 * Animations of the pool.
188 namespace Pool {
190 class Scheme {
191 public:
192 virtual ~Scheme() { }
193 virtual AnimationPtr run(const AnimationSettings& s, const IndexConverter* converter, AnimationType) const = 0;
196 class move : public Scheme {
197 const NamedSprite& m_sprite;
198 int m_to;
199 public:
200 move(const NamedSprite& sprite, int to);
201 virtual AnimationPtr run(const AnimationSettings& s, const IndexConverter*, AnimationType type) const;
204 class appear : public Scheme {
205 const NamedSprite& m_sprite;
206 public:
207 appear(const NamedSprite& sprite);
208 virtual AnimationPtr run(const AnimationSettings& s, const IndexConverter*, AnimationType type) const;
211 class disappear : public Scheme {
212 const NamedSprite& m_sprite;
213 public:
214 disappear(const NamedSprite& sprite);
215 virtual AnimationPtr run(const AnimationSettings& s, const IndexConverter*, AnimationType type) const;
223 #endif // ANIMATIONFACTORY_H