From 7f88db5f34c37c804a7bb69fccb2c7dee86dfe98 Mon Sep 17 00:00:00 2001 From: Federico Angelilli Date: Fri, 15 Mar 2024 21:05:52 +0100 Subject: Fix button border drawing --- src/comet.c | 11 ++++++++--- src/draw.c | 22 ++++++++++++++++++++-- 2 files changed, 28 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/comet.c b/src/comet.c index 617fcb5..5bcd9ac 100644 --- a/src/comet.c +++ b/src/comet.c @@ -220,12 +220,13 @@ static void menu_action(Button *btn) state_request_redraw(menu_ctx->state, true); } -static void register_buttons(State *state, Color color, Color text_color) +static void register_buttons(State *state, Color color, Color text_color, Color line_color, int line_w) { // Cpu usage button Button *cpu_btn = button_simple_create(PANGO_ALIGN_RIGHT, color); button_simple_set_text(cpu_btn, g_strdup(" 0%"), text_color); button_simple_set_action(cpu_btn, show_action, state); + button_set_line(cpu_btn, line_color, line_w); state_add_button(state, cpu_btn); cpu_update(cpu_btn); @@ -235,6 +236,7 @@ static void register_buttons(State *state, Color color, Color text_color) Button *temp_btn = button_simple_create(PANGO_ALIGN_RIGHT, color); button_simple_set_text(temp_btn, g_strdup("temp"), text_color); button_simple_set_action(temp_btn, show_action, state); + button_set_line(temp_btn, line_color, line_w); state_add_button(state, temp_btn); temp_update(temp_btn); @@ -244,6 +246,7 @@ static void register_buttons(State *state, Color color, Color text_color) Button *ram_btn = button_simple_create(PANGO_ALIGN_RIGHT, color); button_simple_set_text(ram_btn, g_strdup("ram"), text_color); button_simple_set_action(ram_btn, show_action, state); + button_set_line(ram_btn, line_color, line_w); state_add_button(state, ram_btn); ram_update(ram_btn); @@ -253,6 +256,7 @@ static void register_buttons(State *state, Color color, Color text_color) Button *disk_btn = button_simple_create(PANGO_ALIGN_RIGHT, color); button_simple_set_text(disk_btn, g_strdup("disk"), text_color); button_simple_set_action(disk_btn, show_action, state); + button_set_line(disk_btn, line_color, line_w); state_add_button(state, disk_btn); disk_update(disk_btn); @@ -287,14 +291,15 @@ int main(int argc, char **argv) Color color = { 0.4, 0.4, 0.4, 1 }; Color purple = { 0.502, 0.168, 0.886, 1 }; - //Color line_color = { 0.8, 0.8, 0.8, 1 }; + Color line_color = { 0.8, 0.8, 0.8, 1 }; Color text_color = { 0.9, 0.9, 0.9, 1 }; // Dwm tags DwmIpc *dwm = dwm_create(state, "/tmp/dwm.sock"); dwm_register_tags(dwm, color, purple, text_color); - register_buttons(state, color, text_color); + int line_w = 0; + register_buttons(state, color, text_color, line_color, line_w); // Buttons with special handling diff --git a/src/draw.c b/src/draw.c index b9b140c..26b0cb0 100644 --- a/src/draw.c +++ b/src/draw.c @@ -51,9 +51,26 @@ static void paint_button(cairo_t *cr, const Layout *layout) { double degree = M_PI / 180.0; int radius = (layout->height - 2 * layout->y_pad) / 2; + int line_radius = radius - layout->line_w / 2; + + //// Layout size + //cairo_set_source_rgb(cr, 0, 0, 0); + //cairo_move_to(cr, layout->x, layout->y); + //cairo_line_to(cr, layout->x, layout->y + layout->height); + //cairo_stroke(cr); + + //cairo_move_to(cr, layout->x + layout->width, layout->y); + //cairo_line_to(cr, layout->x + layout->width, layout->y + layout->height); + //cairo_stroke(cr); + + //// Layout padding + //cairo_set_source_rgb(cr, 0.5, 0.1, 0.1); + //cairo_rectangle(cr, layout->x + layout->x_pad, layout->y + layout->y_pad, layout->width - 2 * layout->x_pad, layout->height - 2 * layout->y_pad); + //cairo_stroke(cr); cairo_set_line_width(cr, layout->line_w); + // Button background Color color = layout->btn->color; cairo_set_source_rgba(cr, color.r, color.g, color.b, color.a); cairo_new_sub_path(cr); @@ -62,11 +79,12 @@ static void paint_button(cairo_t *cr, const Layout *layout) cairo_close_path(cr); cairo_fill(cr); + // Button border color = layout->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 + layout->x_pad + radius, layout->y + layout->y_pad + radius, radius - layout->line_w, 90 * degree, 270 * degree); - cairo_arc(cr, layout->x + layout->width - layout->x_pad - radius, layout->y + layout->y_pad + radius, radius - layout->line_w, 270 * degree, 450 * degree); + cairo_arc(cr, layout->x + layout->x_pad + radius, layout->y + layout->y_pad + radius, line_radius, 90 * degree, 270 * degree); + cairo_arc(cr, layout->x + layout->width - layout->x_pad - radius, layout->y + layout->y_pad + radius, line_radius, 270 * degree, 450 * degree); cairo_close_path(cr); cairo_stroke(cr); } -- cgit v1.2.3