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.
11 #ifndef ANIMATIONFACTORY_H
12 #define ANIMATIONFACTORY_H
14 #include "animation.h"
22 class AnimationSettings
;
27 * AnimationType distinguishes between those animations which honor settings
28 * and those that are instantaneous regardless of user preferences.
31 Normal
, /// Honor user settings.
32 Instant
/// Instantaneous animation.
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
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
{
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
;
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
);
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
);
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
);
103 * Implicitly convert the object to an AnimationGroup shared pointer,
104 * using the group() member function.
106 operator AnimationGroupPtr() const;
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
{
124 const NamedSprite
& m_sprite
;
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
;
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
;
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
;
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
;
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.
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
;
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
;
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
;
214 disappear(const NamedSprite
& sprite
);
215 virtual AnimationPtr
run(const AnimationSettings
& s
, const IndexConverter
*, AnimationType type
) const;
223 #endif // ANIMATIONFACTORY_H