-
Notifications
You must be signed in to change notification settings - Fork 0
/
Button.py
100 lines (75 loc) · 2.93 KB
/
Button.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
from pygame import Surface, Rect
import pygame
from typing import Union, Optional
class Button():
"""
ABSTRACT
Buttons that have a function when clicked
"""
color: Union[tuple[int, int, int, int], pygame.Color]
rect: Rect
def __init__(self, rect: Rect, color: Union[tuple[int, int, int, int], pygame.Color]) -> None:
self.color = color
self.rect = rect
def __repr__(self) -> str:
return str(type(self))
def get_rect(self) -> Rect:
return self.rect
def onClick(self) -> int:
raise NotImplementedError
def display(self, surface: Surface) -> None:
pygame.draw.rect(surface, self.color, self.rect)
class IconButton(Button):
"""
ABSTRACT
"""
icon: Surface
def __init__(self, rect: Rect, color: Union[tuple[int, int, int, int], pygame.Color], icon: Surface) -> None:
super().__init__(rect, color)
self.icon = pygame.transform.scale(icon, (self.rect.w, self.rect.h))
def onClick(self) -> int:
raise NotImplementedError
def display(self, surface: Surface) -> None:
super().display(surface)
surface.blit(self.icon, self.rect)
class PenButton(IconButton):
icon: Surface
def __init__(self, rect: Rect, color: Union[tuple[int, int, int, int], pygame.Color], icon: Surface) -> None:
super().__init__(rect, color, icon)
def onClick(self) -> int:
print("drawing")
return 1
class EraserButton(IconButton):
def __init__(self, rect: Rect, color: Union[tuple[int, int, int, int], pygame.Color], icon: Surface) -> None:
super().__init__(rect, color, icon)
def onClick(self) -> int:
print("eraser")
return 2
class MovementButton(IconButton):
def __init__(self, rect: Rect, color: Union[tuple[int, int, int, int], pygame.Color], icon: Surface) -> None:
super().__init__(rect, color, icon)
def onClick(self) -> int:
print("movement")
return 3
class ClearButton(IconButton):
def __init__(self, rect: Rect, color: Union[tuple[int, int, int, int], pygame.Color], icon: Surface) -> None:
super().__init__(rect, color, icon)
def onClick(self) -> int:
print("clearing board")
return 4
class TextButton(IconButton):
def __init__(self, rect: Rect, color: Union[tuple[int, int, int, int], pygame.Color], icon: Surface) -> None:
super().__init__(rect, color, icon)
def onClick(self) -> int:
print("text")
return 5
class TextColorButton(Button):
def __init__(self, rect: Rect, color: Union[tuple[int, int, int, int], pygame.Color]) -> None:
super().__init__(rect, color)
def onClick(self) -> int:
return 6
class TextApplyButton(IconButton):
def __init__(self, rect: Rect, color: Union[tuple[int, int, int, int], pygame.Color], icon: Surface) -> None:
super().__init__(rect, color, icon)
def onClick(self) -> int:
return 7