diff --git a/include/hexagram/anim.h b/include/hexagram/anim.h index f081263..910b010 100644 --- a/include/hexagram/anim.h +++ b/include/hexagram/anim.h @@ -13,6 +13,10 @@ typedef enum { HEXAGRAM_ANIM_RADIUS = 1 << 2 } hexagram_anim_flags; +typedef struct _hexagram_anim_stop hexagram_anim_stop; + +typedef double (hexagram_anim_progress_fn)(hexagram_anim_stop *, double); + typedef struct _hexagram_anim_action { int flags; @@ -31,11 +35,12 @@ typedef struct _hexagram_anim_action { } from, to; } hexagram_anim_action; -typedef struct _hexagram_anim_stop { +struct _hexagram_anim_stop { hexagram_anim_action *actions; size_t count; double duration; -} hexagram_anim_stop; + hexagram_anim_progress_fn *fn; +}; typedef struct _hexagram_anim { hexagram_anim_stop *stops; @@ -43,11 +48,9 @@ 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, hexagram_anim_progress_fn *fn); +int hexagram_anim_step(hexagram_anim *anim); double hexagram_anim_duration(hexagram_anim *anim); diff --git a/src/anim.c b/src/anim.c index 408fd62..978cbb7 100644 --- a/src/anim.c +++ b/src/anim.c @@ -22,7 +22,7 @@ static inline double stop_offset(hexagram_anim *anim, size_t index) { return offset; } -int hexagram_anim_step(hexagram_anim *anim, hexagram_anim_progress_fn *fn) { +int hexagram_anim_step(hexagram_anim *anim) { struct timeval tv; double offset = 0.0, interval, progress; size_t i, a; @@ -53,8 +53,8 @@ int hexagram_anim_step(hexagram_anim *anim, hexagram_anim_progress_fn *fn) { if (i == anim->count) { i--; progress = 1.0; - } else if (fn) { - progress = fn(&anim->stops[i], + } else if (anim->stops[i].fn) { + progress = anim->stops[i].fn(&anim->stops[i], (interval - offset) / anim->stops[i].duration); } else { progress = (interval - offset) / anim->stops[i].duration;