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;
70 /** Change the wrapped animation group. */
71 void setGroup(const AnimationGroupPtr
& group
);
74 * Add a pre-animation to the group.
75 * \param scheme The scheme producing the animation to be added.
76 * \param type The AnimationType to be used when creating the animation.
78 void addPreAnimation(const Animate::Scheme
& scheme
, Animate::AnimationType type
= Animate::Normal
);
81 * Add a post-animation to the group.
82 * \param scheme The scheme producing the animation to be added.
83 * \param type The AnimationType to be used when creating the animation.
85 void addPostAnimation(const Animate::Scheme
& scheme
, Animate::AnimationType type
= Animate::Normal
);
88 * Implicitly convert the object to an AnimationGroup shared pointer,
89 * using the group() member function.
91 operator AnimationGroupPtr() const;
98 * @brief A movement animation scheme.
100 * Used to animate the movement of a piece to a destination square.
102 class move
: public Scheme
{
110 const NamedSprite
& m_sprite
;
114 move(const NamedSprite
& sprite
, const Point
& to
, int type
= Straight
);
115 virtual AnimationPtr
run(const PointConverter
* converter
, AnimationType type
) const;
119 * @brief Appear animation scheme.
121 * The appear scheme visualizes a new piece coming into existence. It is
122 * used, for example, when retracting a capture in chess, to restore the captured
123 * piece on the chessboard.
125 class appear
: public Scheme
{
126 const NamedSprite
& m_sprite
;
128 appear(const NamedSprite
& sprite
);
129 virtual AnimationPtr
run(const PointConverter
* converter
, AnimationType type
) const;
133 * @brief Disappear animation scheme.
135 * The disappear scheme visualizes a piece being removed from the board.
137 class disappear
: public Scheme
{
138 const NamedSprite
& m_sprite
;
140 disappear(const NamedSprite
& sprite
);
141 virtual AnimationPtr
run(const PointConverter
* converter
, AnimationType type
) const;
145 * @brief Animation scheme destroying a piece.
147 * This animation scheme is used to destroy a piece, removing it from the
148 * board. It is similar to the disappear scheme, but can provide an additional
149 * effect like an explosion.
151 class destroy
: public Scheme
{
152 const NamedSprite
& m_sprite
;
154 destroy(const NamedSprite
& sprite
);
155 virtual AnimationPtr
run(const PointConverter
* converter
, AnimationType type
) const;
159 * @brief Animation scheme for changing a piece into another.
161 * The morph animation scheme is used when a piece changes, like in chess promotions.
163 class morph
: public Scheme
{
164 const NamedSprite
& m_sprite
;
165 const NamedSprite
& m_new_sprite
;
167 morph(const NamedSprite
& sprite
, const NamedSprite
& new_sprite
);
168 virtual AnimationPtr
run(const PointConverter
* converter
, AnimationType type
) const;
175 #endif // ANIMATIONFACTORY_H