From 90e2b03662847fda9843d2ed73369653a3bcbea6 Mon Sep 17 00:00:00 2001 From: James Magahern Date: Sun, 27 Jan 2019 22:39:30 -0800 Subject: Some code cleanup --- src/animation.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) (limited to 'src/animation.c') diff --git a/src/animation.c b/src/animation.c index 15093d3..ecefb97 100644 --- a/src/animation.c +++ b/src/animation.c @@ -7,15 +7,6 @@ #include "animation.h" #include -anim_time_interval_t anim_now() -{ - struct timespec ts; - clock_gettime(CLOCK_MONOTONIC_RAW, &ts); - - long ms = (ts.tv_sec * 1000) + (ts.tv_nsec / 1000000); - return (ms / 1000.0); -} - /* * Easing functions */ @@ -31,4 +22,29 @@ double anim_quad_ease_out(double p) return -(p * (p - 2.0)); } +/* + * Convenience calculation functions + */ + +anim_time_interval_t anim_now() +{ + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC_RAW, &ts); + + long ms = (ts.tv_sec * 1000) + (ts.tv_nsec / 1000000); + return (ms / 1000.0); +} + +double anim_progress(animation_t *anim, const double duration) +{ + const anim_time_interval_t now = anim_now(); + double progress = (now - anim->start_time) / duration; + return (anim->direction == IN) ? progress : (1.0 - progress); +} + +bool anim_complete(animation_t *anim, const double progress) +{ + return (anim->direction == IN) ? progress >= 1.0 : progress <= 0.0; +} + -- cgit v1.2.3-54-g00ecf