soui 5.0.0.1
Soui5 Doc
 
Loading...
Searching...
No Matches
SInterpolatorImpl.h
1#ifndef __SINTERPOLATORIMPL__H__
2#define __SINTERPOLATORIMPL__H__
3
4#include <interface/sinterpolator-i.h>
5#include <helper/obj-ref-impl.hpp>
6#include <sobject/Sobject.hpp>
7
8SNSBEGIN
9
10typedef TObjRefImpl<SObjectImpl<IInterpolator>> SInterpolatorBase;
11
12/**
13 * @class SLinearInterpolator
14 * @brief An interpolator where the rate of change is constant.
15 */
16class SOUI_EXP SLinearInterpolator : public SInterpolatorBase {
17 DEF_SOBJECT(SInterpolatorBase, L"Linear")
18
19 public:
20 /**
21 * @brief Gets the interpolated value for the given input.
22 * @param input The input value between 0 and 1.
23 * @return The interpolated value.
24 */
25 STDMETHOD_(float, getInterpolation)(THIS_ float input) SCONST OVERRIDE;
26};
27
28/**
29 * @class SAccelerateInterpolator
30 * @brief An interpolator where the rate of change starts slow and accelerates.
31 */
32class SOUI_EXP SAccelerateInterpolator : public SInterpolatorBase {
33 DEF_SOBJECT(SInterpolatorBase, L"Accelerate")
34
35 private:
36 float mFactor; ///< Degree to which the animation should be eased.
37 double mDoubleFactor; ///< Double value of the factor for calculations.
38
39 public:
40 /**
41 * @brief Constructor for SAccelerateInterpolator.
42 * @param factor Degree to which the animation should be eased. Setting factor to 1.0f produces a y=x^2 parabola.
43 * Increasing factor above 1.0f exaggerates the ease-in effect (i.e., it starts even slower and ends even faster).
44 */
45 SAccelerateInterpolator(float factor = 1.0f);
46
47 /**
48 * @brief Gets the interpolated value for the given input.
49 * @param input The input value between 0 and 1.
50 * @return The interpolated value.
51 */
52 STDMETHOD_(float, getInterpolation)(THIS_ float input) SCONST OVERRIDE;
53
54 /**
55 * @brief Attributes for SAccelerateInterpolator
56 */
57 SOUI_ATTRS_BEGIN()
58 ATTR_FLOAT(L"factor", mFactor, FALSE) ///< Degree to which the animation should be eased.
59 SOUI_ATTRS_END()
60};
61
62/**
63 * @class SDecelerateInterpolator
64 * @brief An interpolator where the rate of change starts fast and decelerates.
65 */
66class SOUI_EXP SDecelerateInterpolator : public SInterpolatorBase {
67 DEF_SOBJECT(SInterpolatorBase, L"Decelerate")
68
69 private:
70 float mFactor; ///< Degree to which the animation should be eased.
71
72 public:
73 /**
74 * @brief Constructor for SDecelerateInterpolator.
75 * @param factor Degree to which the animation should be eased. Setting factor to 1.0f produces an upside-down y=x^2 parabola.
76 * Increasing factor above 1.0f exaggerates the ease-out effect (i.e., it starts even faster and ends even slower).
77 */
78 SDecelerateInterpolator(float factor = 1.0f);
79
80 /**
81 * @brief Gets the interpolated value for the given input.
82 * @param input The input value between 0 and 1.
83 * @return The interpolated value.
84 */
85 STDMETHOD_(float, getInterpolation)(THIS_ float input) SCONST OVERRIDE;
86
87 /**
88 * @brief Attributes for SDecelerateInterpolator
89 */
90 SOUI_ATTRS_BEGIN()
91 ATTR_FLOAT(L"factor", mFactor, FALSE) ///< Degree to which the animation should be eased.
92 SOUI_ATTRS_END()
93};
94
95/**
96 * @class SAccelerateDecelerateInterpolator
97 * @brief An interpolator where the rate of change starts and ends slowly, accelerating in the middle.
98 */
99class SOUI_EXP SAccelerateDecelerateInterpolator : public SInterpolatorBase {
100 DEF_SOBJECT(SInterpolatorBase, L"AccelerateDecelerate")
101
102 public:
103 /**
104 * @brief Gets the interpolated value for the given input.
105 * @param input The input value between 0 and 1.
106 * @return The interpolated value.
107 */
108 STDMETHOD_(float, getInterpolation)(THIS_ float input) SCONST OVERRIDE;
109};
110
111/**
112 * @class SAnticipateInterpolator
113 * @brief An interpolator where the change starts backward before moving forward.
114 */
115class SOUI_EXP SAnticipateInterpolator : public SInterpolatorBase {
116 DEF_SOBJECT(SInterpolatorBase, L"Anticipate")
117
118 private:
119 float mTension; ///< Amount of anticipation.
120
121 public:
122 /**
123 * @brief Default constructor for SAnticipateInterpolator.
124 */
126
127 /**
128 * @brief Constructor for SAnticipateInterpolator.
129 * @param tension Amount of anticipation. When tension equals 0.0f, there is no anticipation and the interpolator becomes a simple acceleration interpolator.
130 */
131 SAnticipateInterpolator(float tension);
132
133 /**
134 * @brief Gets the interpolated value for the given input.
135 * @param input The input value between 0 and 1.
136 * @return The interpolated value.
137 */
138 STDMETHOD_(float, getInterpolation)(THIS_ float input) SCONST OVERRIDE;
139
140 /**
141 * @brief Attributes for SAnticipateInterpolator
142 */
143 SOUI_ATTRS_BEGIN()
144 ATTR_FLOAT(L"tension", mTension, FALSE) ///< Amount of anticipation.
145 SOUI_ATTRS_END()
146};
147
148/**
149 * @class SAnticipateOvershootInterpolator
150 * @brief An interpolator where the change starts backward before moving forward and overshoots the target.
151 */
152class SOUI_EXP SAnticipateOvershootInterpolator : public SInterpolatorBase {
153 DEF_SOBJECT(SInterpolatorBase, L"AnticipateOvershoot")
154
155 private:
156 float mTension; ///< Amount of anticipation/overshoot.
157 float mExtraTension; ///< Extra amount by which to multiply the tension.
158
159 /**
160 * @brief Helper function for anticipation.
161 * @param t Input value.
162 * @param s Tension value.
163 * @return Calculated anticipation value.
164 */
165 static float a(float t, float s);
166
167 /**
168 * @brief Helper function for overshoot.
169 * @param t Input value.
170 * @param s Tension value.
171 * @return Calculated overshoot value.
172 */
173 static float o(float t, float s);
174
175 /**
176 * @brief Gets the tension multiplier.
177 * @return The tension multiplier.
178 */
179 float getTensionMulti() const
180 {
181 return mTension * mExtraTension;
182 }
183
184 public:
185 /**
186 * @brief Constructor for SAnticipateOvershootInterpolator.
187 * @param tension Amount of anticipation/overshoot. When tension equals 0.0f, there is no anticipation/overshoot and the interpolator becomes a simple acceleration/deceleration interpolator.
188 * @param extraTension Extra amount by which to multiply the tension. For instance, to get the same overshoot as an OvershootInterpolator with a tension of 2.0f, you would use an extraTension of 1.5f.
189 */
190 SAnticipateOvershootInterpolator(float tension = 2.0f, float extraTension = 1.5f);
191
192 /**
193 * @brief Gets the interpolated value for the given input.
194 * @param input The input value between 0 and 1.
195 * @return The interpolated value.
196 */
197 STDMETHOD_(float, getInterpolation)(THIS_ float input) SCONST OVERRIDE;
198
199 /**
200 * @brief Attributes for SAnticipateOvershootInterpolator
201 */
202 SOUI_ATTRS_BEGIN()
203 ATTR_FLOAT(L"tension", mTension, FALSE) ///< Amount of anticipation/overshoot.
204 ATTR_FLOAT(L"extraTension", mExtraTension, FALSE) ///< Extra amount by which to multiply the tension.
205 SOUI_ATTRS_END()
206};
207
208/**
209 * @class SBounceInterpolator
210 * @brief An interpolator where the change bounces at the end.
211 */
212class SOUI_EXP SBounceInterpolator : public SInterpolatorBase {
213 DEF_SOBJECT(SInterpolatorBase, L"Bounce")
214
215 private:
216 /**
217 * @brief Helper function for bounce effect.
218 * @param t Input value.
219 * @return Calculated bounce value.
220 */
221 static float bounce(float t);
222
223 public:
224 /**
225 * @brief Gets the interpolated value for the given input.
226 * @param input The input value between 0 and 1.
227 * @return The interpolated value.
228 */
229 STDMETHOD_(float, getInterpolation)(THIS_ float input) SCONST OVERRIDE;
230};
231
232/**
233 * @class SCycleInterpolator
234 * @brief An interpolator where the change repeats a specified number of cycles.
235 */
236class SOUI_EXP SCycleInterpolator : public SInterpolatorBase {
237 DEF_SOBJECT(SInterpolatorBase, L"Cycle")
238
239 private:
240 float mCycles; ///< Number of cycles to repeat.
241
242 public:
243 /**
244 * @brief Constructor for SCycleInterpolator.
245 * @param cycles Number of cycles to repeat.
246 */
247 SCycleInterpolator(float cycles = 1.0f);
248
249 /**
250 * @brief Gets the interpolated value for the given input.
251 * @param input The input value between 0 and 1.
252 * @return The interpolated value.
253 */
254 STDMETHOD_(float, getInterpolation)(THIS_ float input) SCONST OVERRIDE;
255
256 /**
257 * @brief Attributes for SCycleInterpolator
258 */
259 SOUI_ATTRS_BEGIN()
260 ATTR_FLOAT(L"cycles", mCycles, FALSE) ///< Number of cycles to repeat.
261 SOUI_ATTRS_END()
262};
263
264/**
265 * @class SOvershootInterpolator
266 * @brief An interpolator where the change overshoots the target and then comes back.
267 */
268class SOUI_EXP SOvershootInterpolator : public SInterpolatorBase {
269 DEF_SOBJECT(SInterpolatorBase, L"Overshoot")
270
271 private:
272 float mTension; ///< Amount of overshoot.
273
274 public:
275 /**
276 * @brief Constructor for SOvershootInterpolator.
277 * @param tension Amount of overshoot. When tension equals 0.0f, there is no overshoot and the interpolator becomes a simple deceleration interpolator.
278 */
279 SOvershootInterpolator(float tension = 2.0f);
280
281 /**
282 * @brief Gets the interpolated value for the given input.
283 * @param input The input value between 0 and 1.
284 * @return The interpolated value.
285 */
286 STDMETHOD_(float, getInterpolation)(THIS_ float input) SCONST OVERRIDE;
287
288 /**
289 * @brief Attributes for SOvershootInterpolator
290 */
291 SOUI_ATTRS_BEGIN()
292 ATTR_FLOAT(L"tension", mTension, FALSE) ///< Amount of overshoot.
293 SOUI_ATTRS_END()
294};
295
296SNSEND
297#endif // __SINTERPOLATORIMPL__H__
An interpolator where the rate of change starts and ends slowly, accelerating in the middle.
float getInterpolation(float input) SCONST OVERRIDE
Gets the interpolated value for the given input.
float getInterpolation(float input) SCONST OVERRIDE
Gets the interpolated value for the given input.
SAccelerateInterpolator(float factor=1.0f)
Constructor for SAccelerateInterpolator.
float getInterpolation(float input) SCONST OVERRIDE
Gets the interpolated value for the given input.
SAnticipateInterpolator()
Default constructor for SAnticipateInterpolator.
float getInterpolation(float input) SCONST OVERRIDE
Gets the interpolated value for the given input.
SAnticipateOvershootInterpolator(float tension=2.0f, float extraTension=1.5f)
Constructor for SAnticipateOvershootInterpolator.
An interpolator where the change bounces at the end.
float getInterpolation(float input) SCONST OVERRIDE
Gets the interpolated value for the given input.
SCycleInterpolator(float cycles=1.0f)
Constructor for SCycleInterpolator.
float getInterpolation(float input) SCONST OVERRIDE
Gets the interpolated value for the given input.
float getInterpolation(float input) SCONST OVERRIDE
Gets the interpolated value for the given input.
SDecelerateInterpolator(float factor=1.0f)
Constructor for SDecelerateInterpolator.
An interpolator where the rate of change is constant.
float getInterpolation(float input) SCONST OVERRIDE
Gets the interpolated value for the given input.
SOvershootInterpolator(float tension=2.0f)
Constructor for SOvershootInterpolator.
float getInterpolation(float input) SCONST OVERRIDE
Gets the interpolated value for the given input.
Template class implementing the IObjRef interface.