This MIGHT work? We'll see
This commit is contained in:
parent
4610211f4e
commit
7a69d60a9d
1 changed files with 24 additions and 8 deletions
32
src/anim.c
32
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; i<anim->count; 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;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue