From 0581b5d5a3f892586e78f61f1398b811d589c501 Mon Sep 17 00:00:00 2001 From: Federico Angelilli Date: Mon, 13 Nov 2023 21:45:24 +0100 Subject: Add 'circular' corners in draw --- draw.c | 48 +++++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/draw.c b/draw.c index 3d5d48d..0eac18a 100644 --- a/draw.c +++ b/draw.c @@ -1,4 +1,3 @@ -#include #include #include @@ -14,8 +13,8 @@ void draw(Window *win) int screen_width, screen_height; window_get_screen_size(win, &screen_width, &screen_height); - int width = EVEN(round(screen_width * 0.98 * scale)); - int height = EVEN(round(screen_height * 0.02 * scale)); + int width = EVEN(round(screen_width * 0.9875 * scale)); + int height = EVEN(round(screen_height * 0.0225 * scale)); cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height); @@ -23,37 +22,44 @@ void draw(Window *win) cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD); cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); - cairo_set_source_rgb(cr, 0.3, 0.3, 0.3); - cairo_rectangle(cr, 0, 0, width, height); - cairo_fill(cr); + int radius = height / 2; + double degree = M_PI / 180.0; - for (int i = 0; i < 9; i++) - { - cairo_set_source_rgb(cr, 0.7, 0.7, 0.7); - cairo_rectangle(cr, height * i, 0, height, height); - cairo_fill(cr); + cairo_set_source_rgb(cr, 0.3, 0.3, 0.3); + cairo_arc(cr, radius, radius, radius, 90.0 * degree, 270 * degree); + cairo_arc(cr, width - radius, radius, radius, 270 * degree, 450 * degree); + cairo_fill(cr); - cairo_set_source_rgb(cr, 0.4, 0.4, 0.4); - cairo_set_line_width(cr, 1 * scale); - cairo_rectangle(cr, height * i, 0, height, height); - cairo_stroke(cr); + cairo_set_line_width(cr, 1 * scale); - cairo_select_font_face(cr, "monospace", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD); - cairo_set_source_rgb(cr, 0.3, 0.3, 0.3); + for (int i = 0; i < 9; i++) { + + int x = (height + cairo_get_line_width(cr) * scale * 2) * i; + + // purple + cairo_set_source_rgb(cr, 0.502, 0.168, 0.886); + cairo_arc(cr, x + radius, radius, radius, 0 * degree, 360 * degree); + cairo_fill(cr); + + cairo_set_source_rgb(cr, 0.8, 0.8, 0.8); + cairo_arc(cr, x + radius, radius, radius - 1, 0 * degree, 360 * degree); + cairo_stroke(cr); + + cairo_select_font_face(cr, "Hack", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); + cairo_set_source_rgb(cr, 1, 1, 1); cairo_set_font_size(cr, 20.0); - char btn[] = { '0' + i, '\0' }; + char btn[] = { '1' + i, '\0' }; cairo_text_extents_t te; cairo_text_extents(cr, btn, &te); - cairo_move_to(cr, (height * i) + (height / 2) - te.x_bearing - te.width / 2, + cairo_move_to(cr, x + (height / 2) - te.x_bearing - te.width / 2, (height / 2) - te.y_bearing - te.height / 2); cairo_show_text(cr, btn); } - - cairo_destroy(cr); + cairo_destroy(cr); int x = EVEN((screen_width - width) / 2.0); int y = EVEN(screen_height * 0.005); -- cgit v1.2.3