/
animation.h
173 lines (141 loc) · 4.46 KB
/
animation.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/** @file animation.h Animation function.
*
* @authors Copyright © 2013 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
*/
#ifndef LIBDENG2_ANIMATION_H
#define LIBDENG2_ANIMATION_H
#include "../String"
#include "../Time"
#include "../Clock"
#include "../ISerializable"
namespace de {
/**
* Animates a value with a transition function.
*
* @note Calling Animation::setFrameTime() is mandatory in the beginning of
* each frame. This will update the time that all animation instances will use
* during the frame.
*
* @ingroup math
*/
class Animation : public ISerializable
{
public:
enum Style {
Linear,
EaseIn,
EaseOut,
EaseBoth,
Bounce,
FixedBounce
};
/// Animation has no defined time source. @ingroup errors
DENG2_ERROR(ClockMissingError);
public:
Animation(float value = 0, Style style = EaseIn);
virtual ~Animation();
void setStyle(Style s);
void setStyle(Style style, float bounce);
Style style() const;
float bounce() const;
/**
* Starts a new transition.
*
* @param toValue Target value.
* @param transitionSpan Number of seconds that the entire transition will take.
* This includes @a startDelay.
* @param startDelay Number of seconds to wait before starting the transition.
*/
void setValue(float toValue, TimeDelta transitionSpan = 0, TimeDelta startDelay = 0);
void setValue(int toValue, TimeDelta transitionSpan = 0, TimeDelta startDelay = 0);
/**
* Starts a new transition.
*
* @param fromValue Value to start from.
* @param toValue Target value.
* @param transitionSpan Number of seconds that the entire transition will take.
* This includes @a startDelay.
* @param startDelay Number of seconds to wait before starting the transition.
*/
void setValueFrom(float fromValue, float toValue, TimeDelta transitionSpan = 0, TimeDelta startDelay = 0);
/**
* Current value.
*/
float value() const;
/**
* Determines whether the transition has been completed.
*/
bool done() const;
/**
* Current target value.
*/
float target() const;
/**
* Changes the target value without modifying any other parameters.
*
* @param newTarget Target value.
*/
void adjustTarget(float newTarget);
/**
* Number of seconds remaining in the ongoing transition.
*/
TimeDelta remainingTime() const;
/**
* Move the current value and the target value by @a valueDelta.
* Does not influence an ongoing transition.
*/
void shift(float valueDelta);
/**
* Complete the ongoing transition immediately.
*/
void finish();
/**
* Regular assignment simply changes the value of immediately.
*
* @param value New value for the Animation, set without a transition.
*/
inline Animation &operator = (float value) {
setValue(v);
return *this;
}
/**
* Implicit conversion to float (current value).
*/
inline operator float() const { return value(); }
String asText() const;
/**
* Returns the clock used for this animation.
*/
Clock const &clock();
// Implements ISerializable.
void operator >> (Writer &to) const;
void operator << (Reader &from);
public:
/**
* The clock that controls time of all animation instances.
* This must be called before any animations are instantiated.
*
* @param clock Clock.
*/
static void setClock(Clock const *clock);
static Time currentTime();
private:
struct Instance;
Instance *d;
static Clock const *_clock;
};
} // namespace de
#endif // LIBDENG2_ANIMATION_H