From 0c841ec4e9a05fb0229830ecfeb12ef4e2d56d76 Mon Sep 17 00:00:00 2001 From: XANTRONIX Industrial Date: Mon, 31 Mar 2025 18:08:21 -0400 Subject: [PATCH] Implement draw.py to draw rounded rectangles --- lib/xmet/draw.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 lib/xmet/draw.py diff --git a/lib/xmet/draw.py b/lib/xmet/draw.py new file mode 100644 index 0000000..a13d15c --- /dev/null +++ b/lib/xmet/draw.py @@ -0,0 +1,29 @@ +import math +import cairo + +def draw_rounded_rect(cr: cairo.Context, + x: float, + y: float, + width: float, + height: float, + radius: float): + rect_width = width - 2 * radius + rect_height = height - 2 * radius + + # Upper right + cr.arc(x + radius + rect_width, y + radius, radius, + -math.pi / 2, 0) + + # Lower right + cr.arc(x + radius + rect_width, y + radius + rect_height, radius, + 0, math.pi / 2) + + # Lower left + cr.arc(x + radius, y + radius + rect_height, radius, + math.pi / 2, math.pi) + + # Upper right + cr.arc(x + radius, y + radius, radius, + math.pi, math.pi * 1.5) + + cr.line_to(x + radius + rect_width, y)