#include #include #include "animate.h" #include "state.h" #include "log.h" double quadratic_bezier(double x, double a, double b, double c) { g_assert(x >= 0 && x <= 1); g_assert(a >= 0 && a <= 1); g_assert(b >= 0 && b <= 1); g_assert(c >= 0 && c <= 1); const double t = 1 - x; return a * t * t + 2 * b * t * x + c * x * x; } double cubic_bezier(double x, double a, double b, double c, double d) { g_assert(x >= 0 && x <= 1); g_assert(a >= 0 && a <= 1); g_assert(b >= 0 && b <= 1); g_assert(c >= 0 && c <= 1); g_assert(d >= 0 && d <= 1); const double t = 1 - x; return a * (t * t * t) + 3 * b * (t * t * x) + 3 * c * (t * x * x) + d * (x * x * x); } typedef struct { Animation anim; gint64 start; gint64 duration; double x; } AnimationShine; bool shine_paint(AnimationShine *anim, cairo_t *cr, const Layout *layout) { gint64 now = g_get_monotonic_time(); if (anim->start == 0) anim->start = now; gint64 end = anim->start + anim->duration; anim->x = 1.0; if (now <= end) { double t = (double)(now - anim->start) / (end - anim->start); anim->x = cubic_bezier(t, 0.19, 1.0, 0.22, 1.0); } // Draw at x on the surface... return false; } Animation *animation_shine_create(gint64 duration) { // Note the 0 initialization AnimationShine *anim = g_malloc0(sizeof(AnimationShine)); anim->anim.type = ANIM_SHINE; anim->anim.paint = (DrawFunc)shine_paint; anim->duration = duration; return (gpointer)anim; } void animation_destroy(Animation *anim) { //XXX g_free(anim); } // vim: ts=4 sw=4 et