Moved global.* to mastersettings.*, and converted many error messages to use the...
[tagua/yd.git] / src / animationfactory.h
blobbbf0a7a939f2b882e21c1e1a1a27f9c6d3494eb9
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 /** Change the wrapped animation group. */
71 void setGroup(const AnimationGroupPtr& group);
73 /**
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);
80 /**
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);
87 /**
88 * Implicitly convert the object to an AnimationGroup shared pointer,
89 * using the group() member function.
91 operator AnimationGroupPtr() const;
95 namespace Animate {
97 /**
98 * @brief A movement animation scheme.
100 * Used to animate the movement of a piece to a destination square.
102 class move : public Scheme {
103 public:
104 enum MovementType {
105 Straight = 0x00,
106 Rotating = 0x01,
107 LShaped = 0x02
109 private:
110 const NamedSprite& m_sprite;
111 Point m_to;
112 int m_type;
113 public:
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;
127 public:
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;
139 public:
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;
153 public:
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;
166 public:
167 morph(const NamedSprite& sprite, const NamedSprite& new_sprite);
168 virtual AnimationPtr run(const PointConverter* converter, AnimationType type) const;
175 #endif // ANIMATIONFACTORY_H