Implement draw.py to draw rounded rectangles

This commit is contained in:
XANTRONIX 2025-03-31 18:08:21 -04:00
parent 0d1489d641
commit 0c841ec4e9

29
lib/xmet/draw.py Normal file
View file

@ -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)