Keep track of animation state
This commit is contained in:
parent
0d6bcc7db2
commit
68b9ade03e
2 changed files with 12 additions and 0 deletions
|
@ -13,6 +13,11 @@ typedef enum {
|
|||
HEXAGRAM_ANIM_RADIUS = 1 << 2
|
||||
} hexagram_anim_flags;
|
||||
|
||||
typedef enum {
|
||||
HEXAGRAM_ANIM_STOPPED,
|
||||
HEXAGRAM_ANIM_PLAYING
|
||||
} hexagram_anim_state;
|
||||
|
||||
typedef struct _hexagram_anim_stop hexagram_anim_stop;
|
||||
|
||||
typedef double (hexagram_anim_progress_fn)(hexagram_anim_stop *, double);
|
||||
|
@ -45,6 +50,7 @@ struct _hexagram_anim_stop {
|
|||
typedef struct _hexagram_anim {
|
||||
hexagram_anim_stop *stops;
|
||||
size_t count;
|
||||
hexagram_anim_state state;
|
||||
struct timeval start, now;
|
||||
} hexagram_anim;
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <hexagram/anim.h>
|
||||
|
||||
void hexagram_anim_init(hexagram_anim *anim) {
|
||||
anim->state = HEXAGRAM_ANIM_PLAYING;
|
||||
gettimeofday(&anim->start, NULL);
|
||||
}
|
||||
|
||||
|
@ -27,6 +28,10 @@ int hexagram_anim_step(hexagram_anim *anim) {
|
|||
double offset = 0.0, interval, progress;
|
||||
size_t i, a;
|
||||
|
||||
if (anim->state == HEXAGRAM_ANIM_STOPPED) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
gettimeofday(&anim->now, NULL);
|
||||
|
||||
timersub(&anim->now, &anim->start, &tv);
|
||||
|
@ -53,6 +58,7 @@ int hexagram_anim_step(hexagram_anim *anim) {
|
|||
if (i == anim->count) {
|
||||
i--;
|
||||
progress = 1.0;
|
||||
anim->state = HEXAGRAM_ANIM_STOPPED;
|
||||
} else if (anim->stops[i].fn) {
|
||||
progress = anim->stops[i].fn(&anim->stops[i],
|
||||
(interval - offset) / anim->stops[i].duration);
|
||||
|
|
Loading…
Add table
Reference in a new issue