diff options
| author | Federico Angelilli <code@fedang.net> | 2024-03-14 00:58:05 +0100 |
|---|---|---|
| committer | Federico Angelilli <code@fedang.net> | 2024-03-14 00:58:05 +0100 |
| commit | 398fdbaa5c02bbd138c59004053d2e8ad0082ead (patch) | |
| tree | d846ed2d4e811ffeddde9dc77a5549fe38edbd34 /src/button.c | |
| parent | cbe94d7c42422856275ad41332cbc980054d6bee (diff) | |
Add animation scaffolding
Diffstat (limited to 'src/button.c')
| -rw-r--r-- | src/button.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/button.c b/src/button.c index 7bee576..01d4e36 100644 --- a/src/button.c +++ b/src/button.c @@ -1,6 +1,7 @@ #include <glib.h> #include "button.h" +#include "log.h" Button *button_simple_create(PangoAlignment align, Color color, Color line_color) { @@ -63,8 +64,41 @@ void button_set_padding(Button *btn, int padding) btn->padding = padding; } +bool button_set_animation(Button *btn, Animation *anim) +{ + if (btn->anim) return false; + btn->anim = anim; + return true; +} + +// Wrapper for animation sources +static gboolean anim_handler(gpointer data) +{ + Button *btn = data; + if (btn->anim->handler(btn->anim)) + return G_SOURCE_CONTINUE; + + g_free(btn->anim); + btn->anim = NULL; + return G_SOURCE_REMOVE; +} + +void button_start_animation(Button *btn) +{ + // Maybe error out + if (btn->anim == NULL) { + log_warning("Button animation was not set"); + return; + } + + const int fps = 60; + if (btn->anim->handler(btn->anim)) + g_timeout_add(1000 / 60, anim_handler, btn); +} + void button_destroy(Button *btn) { if (btn->simple) g_free(CAST(btn, ButtonSimple)->text); + animation_destroy(btn->anim); g_free(btn); } |
