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)