diff options
| author | Federico Angelilli <code@fedang.net> | 2024-03-15 00:35:34 +0100 |
|---|---|---|
| committer | Federico Angelilli <code@fedang.net> | 2024-03-15 00:35:34 +0100 |
| commit | 74a29b60cdcff2906db89707c1059ee1cc840e49 (patch) | |
| tree | 402e7989d41205e2e7c3dda3928b1d193fc72367 /src/draw.c | |
| parent | 430def6e39315b6cee807aba3e4126134b93b164 (diff) | |
Move animation removal to handler
Diffstat (limited to 'src/draw.c')
| -rw-r--r-- | src/draw.c | 39 |
1 files changed, 16 insertions, 23 deletions
@@ -67,12 +67,13 @@ void draw_paint(Drawer *draw, Window *win) for (GList *it = draw->layouts; it; it = it->next) { Layout *layout = it->data; - - int radius = layout->height / 2; + Button *btn = layout->btn; cairo_push_group(cr); - Color color = layout->btn->color; + int radius = layout->height / 2; + + Color color = btn->color; cairo_set_source_rgba(cr, color.r, color.g, color.b, color.a); cairo_new_sub_path(cr); cairo_arc(cr, layout->x + radius, layout->y + radius, radius, 90 * degree, 270 * degree); @@ -80,7 +81,7 @@ void draw_paint(Drawer *draw, Window *win) cairo_close_path(cr); cairo_fill(cr); - color = layout->btn->line_color; + color = btn->line_color; cairo_set_source_rgba(cr, color.r, color.g, color.b, color.a); cairo_new_sub_path(cr); cairo_arc(cr, layout->x + radius, layout->y + radius, radius - line_w , 90 * degree, 270 * degree); @@ -88,37 +89,29 @@ void draw_paint(Drawer *draw, Window *win) cairo_close_path(cr); cairo_stroke(cr); - if (layout->btn->simple) { + if (btn->simple) { int text_x = layout->x + (layout->width / 2) - (layout->text_w / 2); int text_y = layout->y + (layout->height / 2) - (layout->text_h / 2); - color = CAST(layout->btn, ButtonSimple)->text_color; + color = CAST(btn, ButtonSimple)->text_color; cairo_set_source_rgba(cr, color.r, color.g, color.b, color.a); cairo_move_to(cr, text_x, text_y); // NOTE: This works only if the text didn't change in size after the layouting - pango_layout_set_text(layout->pl, CAST(layout->btn, ButtonSimple)->text, -1); + pango_layout_set_text(layout->pl, CAST(btn, ButtonSimple)->text, -1); pango_cairo_update_layout(cr, layout->pl); pango_cairo_show_layout(cr, layout->pl); } - if (layout->btn->anim != NULL) { - if (layout->btn->anim->paint_func != NULL) { - if (layout->btn->anim->start == 0) { - layout->btn->anim->start = g_get_monotonic_time(); - log_debug("Starting animation [start=%ld, duration=%ld, button=%p]", - layout->btn->anim->start, layout->btn->anim->duration, layout->btn); - } - - if (!layout->btn->anim->paint_func(layout->btn->anim, cr, layout)) - layout->btn->anim->paint_func = NULL; - - } else if (layout->btn->anim->layout_func == NULL) { - // Remove animation if both paint_func and layout_func finished - animation_destroy(layout->btn->anim); - layout->btn->anim = NULL; - log_debug("Removing animation [button=%p]", layout->btn); + 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; } cairo_pop_group_to_source(cr); |
