From 7a69d60a9d5702eec30d80f9a4ef7acf615dbec9 Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Fri, 19 Jan 2024 20:47:07 -0500 Subject: [PATCH] This MIGHT work? We'll see --- src/anim.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/anim.c b/src/anim.c index 08cd7af..e4158d3 100644 --- a/src/anim.c +++ b/src/anim.c @@ -30,22 +30,38 @@ static inline size_t stop_index(hexagram_anim *anim, double offset) { int hexagram_anim_step(hexagram_anim *anim, cairo_t *bg, cairo_t *fg) { struct timeval tv; - double offset, interval; + double offset = 0.0, interval, progress; size_t i; - if (anim->current >= anim->count) { - goto done; - } - gettimeofday(&anim->now, NULL); timersub(&anim->now, &anim->start, &tv); + /* Determine the interval between initialisation and now */ interval = tv_seconds(&tv); -done: - return 0; + /* Determine current animation stop index and time offset */ + for (i=0; icount; i++) { + double duration = anim->stops[i].duration; + + if (duration <= 0) { + continue; + } + + if (interval < offset + duration) { + break; + } + + offset += duration; + } + + if (i == anim->count) { + /* We are apparently at the end. */ + return 0; + } + + /* Determine current progress through current stop */ + progress = (interval - offset) / anim->stops[i].duration; -next: return 1; }