/src/wt/src/Wt/WAnimation.h
Line | Count | Source (jump to first uncovered line) |
1 | | // This may look like C code, but it's really -*- C++ -*- |
2 | | /* |
3 | | * Copyright (C) 2011 Emweb bv, Herent, Belgium. |
4 | | * |
5 | | * See the LICENSE file for terms of use. |
6 | | */ |
7 | | #ifndef WANIMATION_H_ |
8 | | #define WANIMATION_H_ |
9 | | |
10 | | #include <Wt/WGlobal.h> |
11 | | |
12 | | namespace Wt { |
13 | | |
14 | | /*! \brief An enumeration describing an animation effect |
15 | | * |
16 | | * An animation effect can be the combination of a motion and an optional |
17 | | * fade effect, e.g: |
18 | | * \code |
19 | | * AnimationEffect::SlideInFromRight |
20 | | * AnimationEffect::SlideInFromTop | AnimationEffect::Fade |
21 | | * \endcode |
22 | | * |
23 | | * You can specify only one motion effect. |
24 | | * |
25 | | * \sa setEffects() |
26 | | */ |
27 | | enum class AnimationEffect { |
28 | | SlideInFromLeft = 0x1, //!< Slides right to show, left to hide |
29 | | SlideInFromRight = 0x2, //!< Slides left to show, right to hide |
30 | | SlideInFromBottom = 0x3, //!< Slides up to show, down to hide |
31 | | SlideInFromTop = 0x4, //!< Slides down to show, up to hide |
32 | | Pop = 0x5, //!< Pops up to show, pops away to hide |
33 | | Fade = 0x100 //!< Fade effect |
34 | | }; |
35 | | |
36 | | /*! \brief A timing function |
37 | | * |
38 | | * The timing function defines how the animation effects are animated |
39 | | * during the total duration of the animation. |
40 | | */ |
41 | | enum class TimingFunction { |
42 | | Ease, //!< Slow start and slow finish |
43 | | Linear, //!< Linear throughout |
44 | | EaseIn, //!< Slow start |
45 | | EaseOut, //!< Slow finish |
46 | | EaseInOut, //!< Slow start and even slower finish |
47 | | CubicBezier //!< (Currently unsupported) |
48 | | }; |
49 | | |
50 | | /*! \class WAnimation Wt/WAnimation.h Wt/WAnimation.h |
51 | | * \brief A value class that defines a transition effect. |
52 | | * |
53 | | * This class defines an animation used as a transition to show or |
54 | | * hide a widget. |
55 | | * |
56 | | * The animation can be defined as a motion effect (e.g. sliding in or |
57 | | * out), optionally combined with a fade effect. A timing function |
58 | | * defines how the effects(s) are animated during the total duration of |
59 | | * the animation. |
60 | | * |
61 | | * \sa WWidget::animateShow(), WWidget::animateHide(), WWidget::setHidden() |
62 | | */ |
63 | | class WT_API WAnimation |
64 | | { |
65 | | public: |
66 | | /*! \brief Typedef for enum Wt::AnimationEffect */ |
67 | | typedef AnimationEffect Effect; |
68 | | |
69 | | /*! \brief Default constructor. |
70 | | * |
71 | | * Creates an animation that actually represent <i>no</i> animation. |
72 | | * (effects() == 0). |
73 | | */ |
74 | | WAnimation(); |
75 | | |
76 | | /*! \brief Creates an animation. |
77 | | * |
78 | | * An animation is created with given effects, timing and duration. |
79 | | */ |
80 | | WAnimation(WFlags<AnimationEffect> effects, |
81 | | TimingFunction timing = TimingFunction::Linear, |
82 | | int duration = 250); |
83 | | |
84 | | #ifdef WT_TARGET_JAVA |
85 | | /*! \brief Creates an animation. |
86 | | * |
87 | | * An animation is created with one effect, timing and duration. |
88 | | */ |
89 | | WAnimation(AnimationEffect effect, |
90 | | TimingFunction timing = TimingFunction::Linear, |
91 | | int duration = 250); |
92 | | |
93 | | /*! \brief Creates an animation. |
94 | | * |
95 | | * An animation is created with two effects (a motion and Fade). |
96 | | */ |
97 | | WAnimation(AnimationEffect effect1, AnimationEffect effect2, |
98 | | TimingFunction timing = TimingFunction::Linear, |
99 | | int duration = 250); |
100 | | |
101 | | /*! \brief Clone method. |
102 | | * |
103 | | * Clones this animation object. |
104 | | */ |
105 | | WAnimation clone() const; |
106 | | #endif |
107 | | |
108 | | /*! \brief Sets the animation effects. |
109 | | * |
110 | | * A motion effect (\link AnimationEffect::SlideInFromLeft |
111 | | * SlideInFromLeft\endlink, \link AnimationEffect::SlideInFromRight |
112 | | * SlideInFromRight\endlink, \link AnimationEffect::SlideInFromBottom |
113 | | * SlideInFromBottom\endlink, \link AnimationEffect::SlideInFromTop |
114 | | * SlideInFromTop\endlink or \link AnimationEffect::Pop Pop\endlink) can be combined |
115 | | * with a fade effect (\link AnimationEffect::Fade Fade\endlink). |
116 | | * |
117 | | * When effects are 0, the animation does not actually specify an |
118 | | * animation, but instead an instant transition. |
119 | | */ |
120 | | void setEffects(WFlags<AnimationEffect> effects); |
121 | | |
122 | | /*! \brief Returns animation effects. |
123 | | * |
124 | | * \sa setEffects() |
125 | | */ |
126 | 0 | WFlags<AnimationEffect> effects() const { return effects_; } |
127 | | |
128 | | /*! \brief Comparison operator. |
129 | | * |
130 | | * Returns \c true if the transitions are exactly the same. |
131 | | */ |
132 | | bool operator==(const WAnimation& other) const; |
133 | | |
134 | | /*! \brief Comparison operator. |
135 | | * |
136 | | * Returns \c true if the transitions are different. |
137 | | */ |
138 | | bool operator!=(const WAnimation& other) const; |
139 | | |
140 | | /*! \brief Sets the duration. |
141 | | * |
142 | | * The default animation duration is 250 ms. |
143 | | * |
144 | | * \sa duration() |
145 | | */ |
146 | | void setDuration(int msecs); |
147 | | |
148 | | /*! \brief Returns the duration. |
149 | | * |
150 | | * \sa setDuration() |
151 | | */ |
152 | 0 | int duration() const { return duration_; } |
153 | | |
154 | | /*! \brief Sets a timing function. |
155 | | * |
156 | | * The default timinig function is TimingFunction::Linear. |
157 | | */ |
158 | | void setTimingFunction(TimingFunction function); |
159 | | |
160 | | /*! \brief Returns the timing function. |
161 | | * |
162 | | * \sa setTimingFunction() |
163 | | */ |
164 | 0 | TimingFunction timingFunction() const { return timing_; } |
165 | | |
166 | | /* |
167 | | void setTimingFunction(double x1, double y1, double x2, double y2); |
168 | | const double[] timingFunction(); |
169 | | */ |
170 | | |
171 | | /*! \brief Returns whether the animation is empty. |
172 | | * |
173 | | * An animation is empty (meaning the transition is instant), if the |
174 | | * duration is 0, or if no effects are defined. |
175 | | */ |
176 | | bool empty() const; |
177 | | |
178 | | private: |
179 | | WFlags<AnimationEffect> effects_; |
180 | | TimingFunction timing_; |
181 | | int duration_; |
182 | | }; |
183 | | |
184 | | W_DECLARE_OPERATORS_FOR_FLAGS(AnimationEffect) |
185 | | |
186 | | } |
187 | | |
188 | | #endif // WANIMATION_H_ |