-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDraw.py
More file actions
71 lines (62 loc) · 2.06 KB
/
Draw.py
File metadata and controls
71 lines (62 loc) · 2.06 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
class DrawText:
def __init__(self, x1, y1, text, font, color):
self.x1 = x1
self.y1 = y1 + font.metrics("linespace")
self.text = text
self.font = font
self.color = color
self.rect = Rect(x1, y1, x1 + font.measure(text), y1 + font.metrics("linespace"))
def execute(self, scroll, canvas):
canvas.create_text(
self.x1,
self.y1 - scroll - self.font.metrics("linespace"),
text = self.text,
font = self.font,
fill = self.color,
anchor = 'nw',
)
class Rect:
def __init__(self, left, top, right, bottom):
self.left = left
self.top = top
self.right = right
self.bottom = bottom
def contains_point(self, x, y):
return x >= self.left and x < self.right \
and y >= self.top and y < self.bottom
class DrawRectangle:
def __init__(self, rect, colour):
self.rect = rect
self.colour = colour
def execute(self, scroll, canvas):
canvas.create_rectangle(
self.rect.left,
self.rect.top - scroll,
self.rect.right,
self.rect.bottom - scroll,
width=0,
fill=self.colour
)
class DrawOutline:
def __init__(self, rect, colour, thickness):
self.rect = rect
self.colour = colour
self.thickness = thickness
def execute(self, scroll, canvas):
canvas.create_rectangle(
self.rect.left, self.rect.top - scroll,
self.rect.right, self.rect.bottom - scroll,
width=self.thickness,
outline=self.colour
)
class DrawLine:
def __init__(self, x1, y1, x2, y2, color, thickness):
self.rect = Rect(x1, y1, x2, y2)
self.color = color
self.thickness = thickness
def execute(self, scroll, canvas):
canvas.create_line(
self.rect.left, self.rect.top - scroll,
self.rect.right, self.rect.bottom - scroll,
fill=self.color, width=self.thickness
)