aboutsummaryrefslogtreecommitdiff
path: root/src/animate.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/animate.c')
-rw-r--r--src/animate.c42
1 files changed, 38 insertions, 4 deletions
diff --git a/src/animate.c b/src/animate.c
index 7b95e9c..33b4e8f 100644
--- a/src/animate.c
+++ b/src/animate.c
@@ -1,6 +1,9 @@
#include <glib.h>
+#include <stdbool.h>
#include "animate.h"
+#include "state.h"
+#include "log.h"
double quadratic_bezier(double x, double a, double b, double c)
{
@@ -25,15 +28,46 @@ double cubic_bezier(double x, double a, double b, double c, double d)
return a * (t * t * t) + 3 * b * (t * t * x) + 3 * c * (t * x * x) + d * (x * x * x);
}
-Animation *animation_create()
+typedef struct {
+ Animation anim;
+ State *state;
+ gint64 start;
+ gint64 duration;
+ double x;
+} AnimationShine;
+
+static gboolean shine_handler(AnimationShine *anim)
+{
+ gint64 now = g_get_monotonic_time();
+ if (anim->start == 0)
+ anim->start = now;
+
+ gint64 end = anim->start + anim->duration;
+ if (now > end) {
+ anim->x = 1.0;
+ state_redraw(anim->state, false);
+ return G_SOURCE_REMOVE;
+ }
+
+ double t = (double)(now - anim->start) / (end - anim->start);
+ anim->x = cubic_bezier(t, 0.19, 1.0, 0.22, 1.0);
+ state_redraw(anim->state, false);
+ return G_SOURCE_CONTINUE;
+}
+
+Animation *animation_shine_create(State *state, gint64 duration)
{
- Animation *anim = g_malloc0(sizeof(Animation));
- // TODO
- return anim;
+ AnimationShine *anim = g_malloc0(sizeof(AnimationShine));
+ anim->anim.type = ANIM_SHINE;
+ anim->anim.handler = G_SOURCE_FUNC(shine_handler);
+ anim->state = state;
+ anim->duration = duration;
+ return (gpointer)anim;
}
void animation_destroy(Animation *anim)
{
+ //XXX
g_free(anim);
}