-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwidgets.py
54 lines (41 loc) · 1.29 KB
/
widgets.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
import pygame
class Button:
def __init__(self, w, h, x, y):
self.w = w
self.h = h
self.x = x
self.y = y
self.def_image = None
self.image = self.def_image
self.func = self.do_nothing
def do_nothing(self):
pass
def connect(self, func):
self.func = func
def draw(self, screen):
screen.blit(self.image, (self.x, self.y))
class CheckButton(Button):
def __init__(self, w, h, x, y):
super().__init__(w, h, x, y)
self.check_image = None
self.checked = False
def click_check(self):
mouse = pygame.mouse.get_pos()
if (self.x < mouse[0] < self.x + self.w) and (self.y < mouse[1] < self.y + self.h):
self.checked = not self.checked
self.func()
self.update()
def update(self):
if self.checked:
self.image = self.check_image
else:
self.image = self.def_image
def set_checked(self, a: bool):
self.checked = a
class PushButton(Button):
def __init__(self, w, h, x, y):
super().__init__(w, h, x, y)
def update(self):
mouse = pygame.mouse.get_pos()
if (self.x < mouse[0] < self.x + self.w) and (self.y < mouse[1] < self.y + self.h):
self.func()