Skip to content

Commit 69c1f11

Browse files
authored
Updated on mouse click
Updated on mouse click handling, passes in eventlist
1 parent 5ccca01 commit 69c1f11

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

Gui.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,20 @@ def __init__(self, text, width, height, pos, win, font):
1414
self.text_surface = self.font.render(text,True,"#FFFFFF")
1515
self.text_rect = self.text_surface.get_rect(center = self.top_rect.center)
1616

17-
def draw(self):
18-
pygame.draw.rect(self.win, self.top_color, self.top_rect, border_radius = 12)
17+
def draw(self, event_list):
18+
pygame.draw.rect(self.win, self.top_color, self.top_rect, border_radius = 6)
1919
self.win.blit(self.text_surface, self.text_rect)
20-
self.is_clicked()
20+
self.is_clicked(event_list)
2121

22-
def is_clicked(self):
22+
def is_clicked(self, event_list):
2323
mouse_pos = pygame.mouse.get_pos()
24+
self.pressed = False
2425
if self.top_rect.collidepoint(mouse_pos):
2526
self.top_color = "#D74B4B"
26-
if pygame.mouse.get_pressed()[0]:
27-
self.pressed = True
28-
else:
29-
if self.pressed == True:
30-
self.pressed = False
27+
for event in event_list:
28+
if event.type == pygame.MOUSEBUTTONDOWN:
29+
if pygame.mouse.get_pressed()[0]:
30+
self.pressed = True
3131
else:
3232
self.top_color = "#475F77"
3333

@@ -57,13 +57,13 @@ def __init__(self,text, width, height, pos, win, font, offset, checked):
5757
self.text_checkbox = self.font.render(self.text,True, (0,0,0))
5858
self.cross_rect = pygame.Rect((self.cb_x+(offset/2), self.cb_y+(offset/2)), (width-offset, height-offset))
5959

60-
def draw(self):
60+
def draw(self, event_list):
6161
self.win.fill((255,255,255), ((self.cb_x, self.pos[1]), (self.width, self.height))) #clear the text
6262
pygame.draw.rect(self.win, self.top_color, self.top_rect)
6363
if self.is_checked():
6464
pygame.draw.rect(self.win, (150, 150, 150), self.cross_rect)
6565
self.win.blit(self.text_checkbox, (self.pos))
66-
self.is_clicked()
66+
self.is_clicked(event_list)
6767

6868
def change_state(self):
6969
if self.pressed:
@@ -75,15 +75,16 @@ def change_state(self):
7575
def is_checked(self):
7676
return self.checked
7777

78-
def is_clicked(self):
78+
def is_clicked(self, event_list):
7979
mouse_pos = pygame.mouse.get_pos()
80+
self.pressed = False
8081
if self.top_rect.collidepoint(mouse_pos):
81-
if pygame.mouse.get_pressed()[0]:
82-
self.pressed = True
83-
else:
84-
if self.pressed:
85-
self.change_state()
86-
self.pressed = False
82+
for event in event_list:
83+
if event.type == pygame.MOUSEBUTTONDOWN:
84+
if pygame.mouse.get_pressed()[0]:
85+
self.pressed = True
86+
87+
self.change_state()
8788

8889
class DropDown():
8990

@@ -134,4 +135,4 @@ def update(self, event_list):
134135
elif self.draw_menu and self.active_option >= 0:
135136
self.draw_menu = False
136137
return self.active_option
137-
return -1
138+
return -1

0 commit comments

Comments
 (0)