From c7a8b75933b3bd963e19f1a9d85f3b610a08e669 Mon Sep 17 00:00:00 2001 From: Federico Angelilli Date: Thu, 14 Mar 2024 15:44:41 +0100 Subject: Change animation code and refactor state --- src/animate.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'src/animate.c') diff --git a/src/animate.c b/src/animate.c index 33b4e8f..874dece 100644 --- a/src/animate.c +++ b/src/animate.c @@ -30,37 +30,35 @@ double cubic_bezier(double x, double a, double b, double c, double d) typedef struct { Animation anim; - State *state; gint64 start; gint64 duration; double x; } AnimationShine; -static gboolean shine_handler(AnimationShine *anim) +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; - if (now > end) { - anim->x = 1.0; - state_redraw(anim->state, false); - return G_SOURCE_REMOVE; + 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); } - double t = (double)(now - anim->start) / (end - anim->start); - anim->x = cubic_bezier(t, 0.19, 1.0, 0.22, 1.0); - state_redraw(anim->state, false); - return G_SOURCE_CONTINUE; + // Draw at x on the surface... + return false; } -Animation *animation_shine_create(State *state, gint64 duration) +Animation *animation_shine_create(gint64 duration) { + // Note the 0 initialization AnimationShine *anim = g_malloc0(sizeof(AnimationShine)); anim->anim.type = ANIM_SHINE; - anim->anim.handler = G_SOURCE_FUNC(shine_handler); - anim->state = state; + anim->anim.paint = (DrawFunc)shine_paint; anim->duration = duration; return (gpointer)anim; } -- cgit v1.2.3