aboutsummaryrefslogtreecommitdiff
path: root/src/animate.c
diff options
context:
space:
mode:
authorFederico Angelilli <code@fedang.net>2024-03-14 15:44:41 +0100
committerFederico Angelilli <code@fedang.net>2024-03-14 15:44:41 +0100
commitc7a8b75933b3bd963e19f1a9d85f3b610a08e669 (patch)
tree91de053f1caaf655eaeb1bbd3458c49362b22e2a /src/animate.c
parent93c4dc6893e733f563e70c315537922d55adfab2 (diff)
Change animation code and refactor state
Diffstat (limited to 'src/animate.c')
-rw-r--r--src/animate.c24
1 files changed, 11 insertions, 13 deletions
diff --git a/src/animate.c b/src/animate.c
index 33b4e8f..874dece 100644
--- a/src/animate.c
+++ b/src/animate.c
@@ -30,37 +30,35 @@ double cubic_bezier(double x, double a, double b, double c, double d)
typedef struct {
Animation anim;
- State *state;
gint64 start;
gint64 duration;
double x;
} AnimationShine;
-static gboolean shine_handler(AnimationShine *anim)
+bool shine_paint(AnimationShine *anim, cairo_t *cr, const Layout *layout)
{
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;
+ anim->x = 1.0;
+
+ if (now <= end) {
+ double t = (double)(now - anim->start) / (end - anim->start);
+ anim->x = cubic_bezier(t, 0.19, 1.0, 0.22, 1.0);
}
- 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;
+ // Draw at x on the surface...
+ return false;
}
-Animation *animation_shine_create(State *state, gint64 duration)
+Animation *animation_shine_create(gint64 duration)
{
+ // Note the 0 initialization
AnimationShine *anim = g_malloc0(sizeof(AnimationShine));
anim->anim.type = ANIM_SHINE;
- anim->anim.handler = G_SOURCE_FUNC(shine_handler);
- anim->state = state;
+ anim->anim.paint = (DrawFunc)shine_paint;
anim->duration = duration;
return (gpointer)anim;
}