diff --git a/src/button.py b/src/button.py index 4de3478..fc2ef96 100644 --- a/src/button.py +++ b/src/button.py @@ -22,6 +22,29 @@ class Button: def draw(self, screen): action = False - # todo + # get current mous position + mouse_pos = pygame.mouse.get_pos() + + # check if mouse is over button + if self.rect.collidepoint(mouse_pos): + current_color = self.hover + + # check if left mouse button is pressed + if pygame.mouse.get_pressed()[0] == 0 and self.clicked: + self.clicked = False + action = True + else: + current_color = self.color + self.clicked = False + + # draw buttton + pygame.draw.rect(screen, current_color, self.rect, border_radius = 12) + + # render button text + text_surface = self.font.render(self.text, True, (255, 255, 255)) + + # place text in the middle of the button + text_rect = text_surface.get_rect(center=self.rect.center) + screen.blit(text_surface, text_rect) return action \ No newline at end of file