diff options
| author | Federico Angelilli <code@fedang.net> | 2024-03-14 16:39:32 +0100 |
|---|---|---|
| committer | Federico Angelilli <code@fedang.net> | 2024-03-14 16:39:32 +0100 |
| commit | 3be41d4351edf3dd4e9d9ac8fcadb38b5d580ef7 (patch) | |
| tree | d41d9ea4d6e948fdbc542440cf028844ae6528f2 | |
| parent | c7a8b75933b3bd963e19f1a9d85f3b610a08e669 (diff) | |
Implement shine animation
| -rw-r--r-- | src/animate.c | 17 | ||||
| -rw-r--r-- | src/connect.c | 2 |
2 files changed, 13 insertions, 6 deletions
diff --git a/src/animate.c b/src/animate.c index 874dece..ca5cbfe 100644 --- a/src/animate.c +++ b/src/animate.c @@ -32,7 +32,6 @@ typedef struct { Animation anim; gint64 start; gint64 duration; - double x; } AnimationShine; bool shine_paint(AnimationShine *anim, cairo_t *cr, const Layout *layout) @@ -42,15 +41,23 @@ bool shine_paint(AnimationShine *anim, cairo_t *cr, const Layout *layout) anim->start = now; gint64 end = anim->start + anim->duration; - anim->x = 1.0; + double pos = 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); + pos = cubic_bezier(t, 0.19, 1.0, 0.22, 1.0); } - // Draw at x on the surface... - return false; + int w = 10; + int x = layout->x + pos * layout->width - w; + int y = layout->y; + + cairo_set_operator(cr, CAIRO_OPERATOR_OVER); + cairo_set_source_rgba(cr, 1, 1, 1, 0.1); + cairo_rectangle(cr, x, y, w, layout->height); + cairo_fill(cr); + + return pos < 1.0; } Animation *animation_shine_create(gint64 duration) diff --git a/src/connect.c b/src/connect.c index 1a21be3..ae9f295 100644 --- a/src/connect.c +++ b/src/connect.c @@ -97,7 +97,7 @@ static void button_action(State *state, const char *event, int x, int y) ButtonAction action = button_simple_get_action(layout->btn); if (action != NULL) { - Animation *shine = animation_shine_create(500 * G_TIME_SPAN_MILLISECOND); + Animation *shine = animation_shine_create(200 * G_TIME_SPAN_MILLISECOND); if (button_set_animation(layout->btn, shine)) state_request_animation(state); |
