diff --git a/include/hexagram/anim.h b/include/hexagram/anim.h index dbb3ceb..b30e8dc 100644 --- a/include/hexagram/anim.h +++ b/include/hexagram/anim.h @@ -34,7 +34,7 @@ typedef struct _hexagram_anim_action { typedef struct _hexagram_anim_stop { hexagram_anim_action *actions; size_t actionc; - double duration_s; + double duration; } hexagram_anim_stop; typedef struct _hexagram_anim { diff --git a/src/anim.c b/src/anim.c index b453fd1..08cd7af 100644 --- a/src/anim.c +++ b/src/anim.c @@ -1,4 +1,5 @@ #include +#include #include @@ -8,6 +9,43 @@ void hexagram_anim_init(hexagram_anim *anim) { gettimeofday(&anim->start, NULL); } -int hexagram_anim_step(hexagram_anim *anim, cairo_t *bg, cairo_t *fg) { - +static inline double tv_seconds(struct timeval *tv) { + return (double)tv->tv_sec + (double)tv->tv_usec / 1000000.0; +} + +static inline double stop_offset(hexagram_anim *anim, size_t index) { + double offset = 0.0; + size_t i; + + for (i=0; istops[i].duration; + } + + return offset; +} + +static inline size_t stop_index(hexagram_anim *anim, double offset) { + return 0; +} + +int hexagram_anim_step(hexagram_anim *anim, cairo_t *bg, cairo_t *fg) { + struct timeval tv; + double offset, interval; + size_t i; + + if (anim->current >= anim->count) { + goto done; + } + + gettimeofday(&anim->now, NULL); + + timersub(&anim->now, &anim->start, &tv); + + interval = tv_seconds(&tv); + +done: + return 0; + +next: + return 1; }