Implement draw.py to draw rounded rectangles
This commit is contained in:
parent
0d1489d641
commit
0c841ec4e9
1 changed files with 29 additions and 0 deletions
29
lib/xmet/draw.py
Normal file
29
lib/xmet/draw.py
Normal 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)
|
Loading…
Add table
Reference in a new issue