3 #include "clutter-easing.h"
8 clutter_linear (double t,
15 clutter_ease_in_quad (double t,
24 clutter_ease_out_quad (double t,
29 return -1.0 * p * (p - 2);
33 clutter_ease_in_out_quad (double t,
36 double p = t / (d / 2);
43 return -0.5 * (p * (p - 2) - 1);
47 clutter_ease_in_cubic (double t,
56 clutter_ease_out_cubic (double t,
65 clutter_ease_in_out_cubic (double t,
68 double p = t / (d / 2);
71 return 0.5 * p * p * p;
75 return 0.5 * (p * p * p + 2);
79 clutter_ease_in_quart (double t,
88 clutter_ease_out_quart (double t,
93 return -1.0 * (p * p * p * p - 1);
97 clutter_ease_in_out_quart (double t,
100 double p = t / (d / 2);
103 return 0.5 * p * p * p * p;
107 return -0.5 * (p * p * p * p - 2);
111 clutter_ease_in_quint (double t,
116 return p * p * p * p * p;
120 clutter_ease_out_quint (double t,
123 double p = t / d - 1;
125 return p * p * p * p * p + 1;
129 clutter_ease_in_out_quint (double t,
132 double p = t / (d / 2);
135 return 0.5 * p * p * p * p * p;
139 return 0.5 * (p * p * p * p * p + 2);
143 clutter_ease_in_sine (double t,
146 return -1.0 * cos (t / d * G_PI_2) + 1.0;
150 clutter_ease_out_sine (double t,
153 return sin (t / d * G_PI_2);
157 clutter_ease_in_out_sine (double t,
160 return -0.5 * (cos (G_PI * t / d) - 1);
164 clutter_ease_in_expo (double t,
167 return (t == 0) ? 0.0 : pow (2, 10 * (t / d - 1));
171 clutter_ease_out_expo (double t,
174 return (t == d) ? 1.0 : -pow (2, -10 * t / d) + 1;
178 clutter_ease_in_out_expo (double t,
192 return 0.5 * pow (2, 10 * (p - 1));
196 return 0.5 * (-pow (2, -10 * p) + 2);
200 clutter_ease_in_circ (double t,
205 return -1.0 * (sqrt (1 - p * p) - 1);
209 clutter_ease_out_circ (double t,
212 double p = t / d - 1;
214 return sqrt (1 - p * p);
218 clutter_ease_in_out_circ (double t,
221 double p = t / (d / 2);
224 return -0.5 * (sqrt (1 - p * p) - 1);
228 return 0.5 * (sqrt (1 - p * p) + 1);
232 clutter_ease_in_elastic (double t,
244 return -(pow (2, 10 * q) * sin ((q * d - s) * (2 * G_PI) / p));
248 clutter_ease_out_elastic (double t,
258 return pow (2, -10 * q) * sin ((q * d - s) * (2 * G_PI) / p) + 1.0;
262 clutter_ease_in_out_elastic (double t,
265 double p = d * (.3 * 1.5);
267 double q = t / (d / 2);
276 return -.5 * (pow (2, 10 * q) * sin ((q * d - s) * (2 * G_PI) / p));
282 return pow (2, -10 * q)
283 * sin ((q * d - s) * (2 * G_PI) / p)
289 clutter_ease_in_back (double t,
294 return p * p * ((1.70158 + 1) * p - 1.70158);
298 clutter_ease_out_back (double t,
301 double p = t / d - 1;
303 return p * p * ((1.70158 + 1) * p + 1.70158) + 1;
307 clutter_ease_in_out_back (double t,
310 double p = t / (d / 2);
311 double s = 1.70158 * 1.525;
314 return 0.5 * (p * p * ((s + 1) * p - s));
318 return 0.5 * (p * p * ((s + 1) * p + s) + 2);
322 ease_out_bounce_internal (double t,
329 return 7.5625 * p * p;
331 else if (p < (2 / 2.75))
335 return 7.5625 * p * p + .75;
337 else if (p < (2.5 / 2.75))
341 return 7.5625 * p * p + .9375;
347 return 7.5625 * p * p + .984375;
352 ease_in_bounce_internal (double t,
355 return 1.0 - ease_out_bounce_internal (d - t, d);
359 clutter_ease_in_bounce (double t,
362 return ease_in_bounce_internal (t, d);
366 clutter_ease_out_bounce (double t,
369 return ease_out_bounce_internal (t, d);
373 clutter_ease_in_out_bounce (double t,
377 return ease_in_bounce_internal (t * 2, d) * 0.5;
379 return ease_out_bounce_internal (t * 2 - d, d) * 0.5 + 1.0 * 0.5;
383 * _clutter_animation_modes:
385 * A mapping of animation modes and easing functions.
387 static const struct {
388 ClutterAnimationMode mode;
389 ClutterEasingFunc func;
391 } _clutter_animation_modes[] = {
392 { CLUTTER_CUSTOM_MODE, NULL, "custom" },
394 { CLUTTER_LINEAR, clutter_linear, "linear" },
395 { CLUTTER_EASE_IN_QUAD, clutter_ease_in_quad, "easeInQuad" },
396 { CLUTTER_EASE_OUT_QUAD, clutter_ease_out_quad, "easeOutQuad" },
397 { CLUTTER_EASE_IN_OUT_QUAD, clutter_ease_in_out_quad, "easeInOutQuad" },
398 { CLUTTER_EASE_IN_CUBIC, clutter_ease_in_cubic, "easeInCubic" },
399 { CLUTTER_EASE_OUT_CUBIC, clutter_ease_out_cubic, "easeOutCubic" },
400 { CLUTTER_EASE_IN_OUT_CUBIC, clutter_ease_in_out_cubic, "easeInOutCubic" },
401 { CLUTTER_EASE_IN_QUART, clutter_ease_in_quart, "easeInQuart" },
402 { CLUTTER_EASE_OUT_QUART, clutter_ease_out_quart, "easeOutQuart" },
403 { CLUTTER_EASE_IN_OUT_QUART, clutter_ease_in_out_quart, "easeInOutQuart" },
404 { CLUTTER_EASE_IN_QUINT, clutter_ease_in_quint, "easeInQuint" },
405 { CLUTTER_EASE_OUT_QUINT, clutter_ease_out_quint, "easeOutQuint" },
406 { CLUTTER_EASE_IN_OUT_QUINT, clutter_ease_in_out_quint, "easeInOutQuint" },
407 { CLUTTER_EASE_IN_SINE, clutter_ease_in_sine, "easeInSine" },
408 { CLUTTER_EASE_OUT_SINE, clutter_ease_out_sine, "easeOutSine" },
409 { CLUTTER_EASE_IN_OUT_SINE, clutter_ease_in_out_sine, "easeInOutSine" },
410 { CLUTTER_EASE_IN_EXPO, clutter_ease_in_expo, "easeInExpo" },
411 { CLUTTER_EASE_OUT_EXPO, clutter_ease_out_expo, "easeOutExpo" },
412 { CLUTTER_EASE_IN_OUT_EXPO, clutter_ease_in_out_expo, "easeInOutExpo" },
413 { CLUTTER_EASE_IN_CIRC, clutter_ease_in_circ, "easeInCirc" },
414 { CLUTTER_EASE_OUT_CIRC, clutter_ease_out_circ, "easeOutCirc" },
415 { CLUTTER_EASE_IN_OUT_CIRC, clutter_ease_in_out_circ, "easeInOutCirc" },
416 { CLUTTER_EASE_IN_ELASTIC, clutter_ease_in_elastic, "easeInElastic" },
417 { CLUTTER_EASE_OUT_ELASTIC, clutter_ease_out_elastic, "easeOutElastic" },
418 { CLUTTER_EASE_IN_OUT_ELASTIC, clutter_ease_in_out_elastic, "easeInOutElastic" },
419 { CLUTTER_EASE_IN_BACK, clutter_ease_in_back, "easeInBack" },
420 { CLUTTER_EASE_OUT_BACK, clutter_ease_out_back, "easeOutBack" },
421 { CLUTTER_EASE_IN_OUT_BACK, clutter_ease_in_out_back, "easeInOutBack" },
422 { CLUTTER_EASE_IN_BOUNCE, clutter_ease_in_bounce, "easeInBounce" },
423 { CLUTTER_EASE_OUT_BOUNCE, clutter_ease_out_bounce, "easeOutBounce" },
424 { CLUTTER_EASE_IN_OUT_BOUNCE, clutter_ease_in_out_bounce, "easeInOutBounce" },
426 { CLUTTER_ANIMATION_LAST, NULL, "sentinel" },
430 clutter_get_easing_func_for_mode (ClutterAnimationMode mode)
432 g_assert (_clutter_animation_modes[mode].mode == mode);
433 g_assert (_clutter_animation_modes[mode].func != NULL);
435 return _clutter_animation_modes[mode].func;
439 clutter_get_easing_name_for_mode (ClutterAnimationMode mode)
441 g_assert (_clutter_animation_modes[mode].mode == mode);
442 g_assert (_clutter_animation_modes[mode].func != NULL);
444 return _clutter_animation_modes[mode].name;
448 clutter_easing_for_mode (ClutterAnimationMode mode,
452 g_assert (_clutter_animation_modes[mode].mode == mode);
453 g_assert (_clutter_animation_modes[mode].func != NULL);
455 return _clutter_animation_modes[mode].func (t, d);