aboutsummaryrefslogtreecommitdiff
path: root/src/draw.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/draw.c')
-rw-r--r--src/draw.c41
1 files changed, 21 insertions, 20 deletions
diff --git a/src/draw.c b/src/draw.c
index 244a472..c6c18a2 100644
--- a/src/draw.c
+++ b/src/draw.c
@@ -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) {