From 3be41d4351edf3dd4e9d9ac8fcadb38b5d580ef7 Mon Sep 17 00:00:00 2001 From: Federico Angelilli Date: Thu, 14 Mar 2024 16:39:32 +0100 Subject: Implement shine animation --- src/animate.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src/animate.c') diff --git a/src/animate.c b/src/animate.c index 874dece..ca5cbfe 100644 --- a/src/animate.c +++ b/src/animate.c @@ -32,7 +32,6 @@ typedef struct { Animation anim; gint64 start; gint64 duration; - double x; } AnimationShine; bool shine_paint(AnimationShine *anim, cairo_t *cr, const Layout *layout) @@ -42,15 +41,23 @@ bool shine_paint(AnimationShine *anim, cairo_t *cr, const Layout *layout) anim->start = now; gint64 end = anim->start + anim->duration; - anim->x = 1.0; + double pos = 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); + pos = cubic_bezier(t, 0.19, 1.0, 0.22, 1.0); } - // Draw at x on the surface... - return false; + int w = 10; + int x = layout->x + pos * layout->width - w; + int y = layout->y; + + cairo_set_operator(cr, CAIRO_OPERATOR_OVER); + cairo_set_source_rgba(cr, 1, 1, 1, 0.1); + cairo_rectangle(cr, x, y, w, layout->height); + cairo_fill(cr); + + return pos < 1.0; } Animation *animation_shine_create(gint64 duration) -- cgit v1.2.3