diff options
| author | Federico Angelilli <code@fedang.net> | 2024-03-16 16:03:21 +0100 |
|---|---|---|
| committer | Federico Angelilli <code@fedang.net> | 2024-03-16 16:03:21 +0100 |
| commit | 115a2b5d2fb0b8b4950c6daa897fbe012b9204b2 (patch) | |
| tree | 2d9c7bb94dd006b750805fe742365e20a271016b /src/draw.c | |
| parent | 40ca9598d269c9b6f162e80b5293f83ec37bb75d (diff) | |
Split animation paint_func
Diffstat (limited to 'src/draw.c')
| -rw-r--r-- | src/draw.c | 41 |
1 files changed, 21 insertions, 20 deletions
@@ -8,6 +8,19 @@ #include "button.h" #include "log.h" +#define ANIMATION(btn, which, ...) \ + do { \ + if ((btn)->anim != NULL && (btn)->anim->which##_func != NULL) { \ + if ((btn)->anim->start == 0) { \ + (btn)->anim->start = g_get_monotonic_time(); \ + log_debug("Starting animation [type=%d, func=%s, start=%ld, duration=%ld, button=%p]", \ + (btn)->anim->type, #which, (btn)->anim->start, (btn)->anim->duration, (btn)); \ + } \ + if (!(btn)->anim->which##_func((btn)->anim, __VA_ARGS__)) \ + (btn)->anim->which##_func = NULL; \ + } \ + } while (false) + Drawer *draw_create(const char *font, int height, int left_pad, int right_pad, int top_pad) { Drawer *draw = g_malloc0(sizeof(Drawer)); @@ -99,6 +112,10 @@ static void paint_button_list(cairo_t *cr, GList *layouts) Button *btn = layout->btn; cairo_push_group(cr); + + // Apply before_func on the layout and cairo context + ANIMATION(btn, before, layout, cr); + paint_button(cr, layout); if (btn->simple) { @@ -109,16 +126,8 @@ static void paint_button_list(cairo_t *cr, GList *layouts) paint_button_list(cr, layout->children); } - if (btn->anim != NULL && btn->anim->paint_func != NULL) { - if (btn->anim->start == 0) { - btn->anim->start = g_get_monotonic_time(); - log_debug("Starting animation [type=%d, start=%ld, duration=%ld, button=%p]", - btn->anim->type, btn->anim->start, btn->anim->duration, btn); - } - - if (!btn->anim->paint_func(btn->anim, cr, layout)) - btn->anim->paint_func = NULL; - } + // Apply after_func on the layout and cairo context + ANIMATION(btn, after, layout, cr); cairo_pop_group_to_source(cr); cairo_paint(cr); @@ -240,16 +249,8 @@ retry: // NOTE: We add half a line width on both sides layout->width += layout->line_w; - if (btn->anim != NULL && btn->anim->layout_func != NULL) { - if (btn->anim->start == 0) { - btn->anim->start = g_get_monotonic_time(); - log_debug("Starting animation [type=%d, start=%ld, duration=%ld, button=%p]", - btn->anim->type, btn->anim->start, btn->anim->duration, btn); - } - - if (!btn->anim->layout_func(btn->anim, layout)) - btn->anim->layout_func = NULL; - } + // Apply layout_func on the layout + ANIMATION(btn, layout, layout); bx += layout->width; if (root) { |
