aboutsummaryrefslogtreecommitdiff
path: root/src/animation.c
diff options
context:
space:
mode:
authorJames Magahern <james@magahern.com>2019-01-27 22:39:30 -0800
committerJames Magahern <james@magahern.com>2019-01-27 22:39:30 -0800
commit90e2b03662847fda9843d2ed73369653a3bcbea6 (patch)
tree159d16e27b6417d1282aac83a6637442f9908229 /src/animation.c
parentSpinner animation and tweaks to memory management (diff)
Some code cleanup
Diffstat (limited to 'src/animation.c')
-rw-r--r--src/animation.c34
1 files changed, 25 insertions, 9 deletions
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 <stdlib.h>
-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;
+}
+