diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/draw.c | 39 | ||||
| -rw-r--r-- | src/state.c | 26 |
2 files changed, 35 insertions, 30 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); diff --git a/src/state.c b/src/state.c index f35faa2..d9ecaeb 100644 --- a/src/state.c +++ b/src/state.c @@ -67,16 +67,29 @@ void state_request_redraw(State *state, bool relayout) static gboolean anim_handler(State *state) { - bool anim = false; + bool done = true; for (GList *it = state->btns; it != NULL; it = it->next) { Button *btn = it->data; + if (btn->anim != NULL) { - anim = true; - state->relayout |= btn->anim->layout_func != NULL; + bool draw = btn->anim->paint_func != NULL; + bool layout = btn->anim->layout_func != NULL; + + // Remove animation if both paint_func and layout_func finished + if (!draw && !layout) { + log_debug("Removing animation [type=%d, end=%ld, button=%p]", + btn->anim->type, btn->anim->start + btn->anim->duration, btn); + + animation_destroy(btn->anim); + btn->anim = NULL; + } else { + done = false; + state->relayout |= layout; + } } } - log_debug("Animating [relayout=%d]", state->relayout); + log_debug("Redrawing animation [relayout=%d, done=%d]", state->relayout, done); if (state->relayout) { draw_compute_layout(state->draw, state->win, state->btns); @@ -84,10 +97,9 @@ static gboolean anim_handler(State *state) } draw_paint(state->draw, state->win); - if (anim) return G_SOURCE_CONTINUE; - state->anim_id = 0; - return G_SOURCE_REMOVE; + if (done) state->anim_id = 0; + return !done; } void state_request_animation(State *state) |
