forked from deter0/xborder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
draw.py
56 lines (51 loc) · 1.57 KB
/
draw.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import math
import typing
def draw_rectangle(
ctx,
x: int,
y: int,
width: int,
height: int,
border_radius: int,
border_size: int,
color: list[int],
border_color: list[int],
) -> None:
ctx.set_source_rgba(color[0] / 255, color[1] / 255, color[2] / 255, color[3])
if border_radius > 0:
corner_radius = border_radius
radius = corner_radius
degrees = math.pi / 180.0
ctx.new_sub_path()
ctx.arc(x + width - radius, y + radius, radius, -90 * degrees, 0 * degrees)
ctx.arc(
x + width - radius, y + height - radius, radius, 0 * degrees, 90 * degrees
)
ctx.arc(x + radius, y + height - radius, radius, 90 * degrees, 180 * degrees)
ctx.arc(x + radius, y + radius, radius, 180 * degrees, 270 * degrees)
ctx.close_path()
ctx.fill_preserve()
if border_size != 0:
ctx.set_source_rgba(
border_color[0] / 255,
border_color[1] / 255,
border_color[2] / 255,
border_color[3],
)
ctx.set_line_width(border_size)
ctx.stroke()
else:
ctx.rectangle(x, y, width, height)
if border_size != 0:
ctx.fill_preserve()
ctx.set_source_rgba(
border_color[0] / 255,
border_color[1] / 255,
border_color[2] / 255,
border_color[3],
)
ctx.set_line_width(border_size)
ctx.stroke()
else:
ctx.fill()
return None