Allow non-linear progress functions

This commit is contained in:
XANTRONIX Development 2024-01-20 00:39:07 -05:00
parent 2c87a95a81
commit d24b7aca62
2 changed files with 10 additions and 3 deletions

View file

@ -43,9 +43,11 @@ typedef struct _hexagram_anim {
struct timeval start, now;
} hexagram_anim;
typedef double (hexagram_anim_progress_fn)(hexagram_anim_stop *, double);
void hexagram_anim_init(hexagram_anim *anim);
int hexagram_anim_step(hexagram_anim *anim);
int hexagram_anim_step(hexagram_anim *anim, hexagram_anim_progress_fn *fn);
double hexagram_anim_duration(hexagram_anim *anim);

View file

@ -22,7 +22,7 @@ static inline double stop_offset(hexagram_anim *anim, size_t index) {
return offset;
}
int hexagram_anim_step(hexagram_anim *anim) {
int hexagram_anim_step(hexagram_anim *anim, hexagram_anim_progress_fn *fn) {
struct timeval tv;
double offset = 0.0, interval, progress;
size_t i, a;
@ -55,7 +55,12 @@ int hexagram_anim_step(hexagram_anim *anim) {
}
/* Determine current progress through current stop */
if (fn) {
progress = fn(&anim->stops[i],
(interval - offset) / anim->stops[i].duration);
} else {
progress = (interval - offset) / anim->stops[i].duration;
}
for (a=0; a<anim->stops[i].actionc; a++) {
hexagram_anim_action *action = &anim->stops[i].actions[a];