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"
25 * AnimationType distinguishes between those animations which honor settings
26 * and those that are instantaneous regardless of user preferences.
29 Normal
, /// Honor user settings.
30 Instant
/// Instantaneous animation.
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
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;
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
;
65 AnimationFactory(GraphicalAPI
* api
);
67 /** \return The wrapped animation group. */
68 AnimationGroupPtr
group() const;
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
);
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
);
85 * Implicitly convert the object to an AnimationGroup shared pointer,
86 * using the group() member function.
88 operator AnimationGroupPtr() const;
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 const NamedSprite
& m_sprite
;
103 move(const NamedSprite
& sprite
, const Point
& to
);
104 virtual AnimationPtr
run(const PointConverter
* converter
, AnimationType type
) const;
108 * @brief Appear animation scheme.
110 * The appear scheme visualizes a new piece coming into existence. It is
111 * used, for example, when retracting a capture in chess, to restore the captured
112 * piece on the chessboard.
114 class appear
: public Scheme
{
115 const NamedSprite
& m_sprite
;
117 appear(const NamedSprite
& sprite
);
118 virtual AnimationPtr
run(const PointConverter
* converter
, AnimationType type
) const;
122 * @brief Disappear animation scheme.
124 * The disappear scheme visualizes a piece being removed from the board.
126 class disappear
: public Scheme
{
127 const NamedSprite
& m_sprite
;
129 disappear(const NamedSprite
& sprite
);
130 virtual AnimationPtr
run(const PointConverter
* converter
, AnimationType type
) const;
134 * @brief Animation scheme destroying a piece.
136 * This animation scheme is used to destroy a piece, removing it from the
137 * board. It is similar to the disappear scheme, but can provide an additional
138 * effect like an explosion.
140 class destroy
: public Scheme
{
141 const NamedSprite
& m_sprite
;
143 destroy(const NamedSprite
& sprite
);
144 virtual AnimationPtr
run(const PointConverter
* converter
, AnimationType type
) const;
148 * @brief Animation scheme for changing a piece into another.
150 * The morph animation scheme is used when a piece changes, like in chess promotions.
152 class morph
: public Scheme
{
153 const NamedSprite
& m_sprite
;
154 const NamedSprite
& m_new_sprite
;
156 morph(const NamedSprite
& sprite
, const NamedSprite
& new_sprite
);
157 virtual AnimationPtr
run(const PointConverter
* converter
, AnimationType type
) const;
164 #endif // ANIMATIONFACTORY_H