Move progress callback to hexagram_anim_stop
This commit is contained in:
parent
9d8a5d303a
commit
0d6bcc7db2
2 changed files with 11 additions and 8 deletions
|
@ -13,6 +13,10 @@ typedef enum {
|
||||||
HEXAGRAM_ANIM_RADIUS = 1 << 2
|
HEXAGRAM_ANIM_RADIUS = 1 << 2
|
||||||
} hexagram_anim_flags;
|
} 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 {
|
typedef struct _hexagram_anim_action {
|
||||||
int flags;
|
int flags;
|
||||||
|
|
||||||
|
@ -31,11 +35,12 @@ typedef struct _hexagram_anim_action {
|
||||||
} from, to;
|
} from, to;
|
||||||
} hexagram_anim_action;
|
} hexagram_anim_action;
|
||||||
|
|
||||||
typedef struct _hexagram_anim_stop {
|
struct _hexagram_anim_stop {
|
||||||
hexagram_anim_action *actions;
|
hexagram_anim_action *actions;
|
||||||
size_t count;
|
size_t count;
|
||||||
double duration;
|
double duration;
|
||||||
} hexagram_anim_stop;
|
hexagram_anim_progress_fn *fn;
|
||||||
|
};
|
||||||
|
|
||||||
typedef struct _hexagram_anim {
|
typedef struct _hexagram_anim {
|
||||||
hexagram_anim_stop *stops;
|
hexagram_anim_stop *stops;
|
||||||
|
@ -43,11 +48,9 @@ typedef struct _hexagram_anim {
|
||||||
struct timeval start, now;
|
struct timeval start, now;
|
||||||
} hexagram_anim;
|
} hexagram_anim;
|
||||||
|
|
||||||
typedef double (hexagram_anim_progress_fn)(hexagram_anim_stop *, double);
|
|
||||||
|
|
||||||
void hexagram_anim_init(hexagram_anim *anim);
|
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);
|
double hexagram_anim_duration(hexagram_anim *anim);
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ static inline double stop_offset(hexagram_anim *anim, size_t index) {
|
||||||
return offset;
|
return offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
int hexagram_anim_step(hexagram_anim *anim, hexagram_anim_progress_fn *fn) {
|
int hexagram_anim_step(hexagram_anim *anim) {
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
double offset = 0.0, interval, progress;
|
double offset = 0.0, interval, progress;
|
||||||
size_t i, a;
|
size_t i, a;
|
||||||
|
@ -53,8 +53,8 @@ int hexagram_anim_step(hexagram_anim *anim, hexagram_anim_progress_fn *fn) {
|
||||||
if (i == anim->count) {
|
if (i == anim->count) {
|
||||||
i--;
|
i--;
|
||||||
progress = 1.0;
|
progress = 1.0;
|
||||||
} else if (fn) {
|
} else if (anim->stops[i].fn) {
|
||||||
progress = fn(&anim->stops[i],
|
progress = anim->stops[i].fn(&anim->stops[i],
|
||||||
(interval - offset) / anim->stops[i].duration);
|
(interval - offset) / anim->stops[i].duration);
|
||||||
} else {
|
} else {
|
||||||
progress = (interval - offset) / anim->stops[i].duration;
|
progress = (interval - offset) / anim->stops[i].duration;
|
||||||
|
|
Loading…
Add table
Reference in a new issue