(surface, text, x, y, font=BIG_FONT, width=160, height=60, color=LIGHT_WHITE, highlight_color=WHITE, text_color=BLACK, text_shadow=False, elevation=6, button_shadow=BLACK)
| 14 | |
| 15 | is_mouse_just_clicked = False |
| 16 | def button(surface, text, x, y, font=BIG_FONT, width=160, height=60, color=LIGHT_WHITE, |
| 17 | highlight_color=WHITE, text_color=BLACK, text_shadow=False, elevation=6, button_shadow=BLACK): |
| 18 | global is_mouse_just_clicked |
| 19 | rect = pygame.Rect(x-width//2, y-height//2, width, height) |
| 20 | mouse_pos = pygame.mouse.get_pos() |
| 21 | mouse_clicked = pygame.mouse.get_pressed()[0] |
| 22 | if mouse_clicked == False: |
| 23 | is_mouse_just_clicked = False |
| 24 | draw_shadow = True |
| 25 | if rect.collidepoint(mouse_pos): |
| 26 | color = highlight_color |
| 27 | if mouse_clicked and is_mouse_just_clicked == False: |
| 28 | is_mouse_just_clicked = True |
| 29 | return True |
| 30 | if mouse_clicked: |
| 31 | rect.x -= elevation |
| 32 | rect.y -= elevation |
| 33 | x -= elevation |
| 34 | y -= elevation |
| 35 | draw_shadow = False |
| 36 | if draw_shadow: |
| 37 | pygame.draw.rect(surface, button_shadow, (rect.x-elevation, rect.y-elevation, rect.w, rect.h), border_radius=16) |
| 38 | |
| 39 | pygame.draw.rect(surface, color, rect, border_radius=16) |
| 40 | draw_text(surface, text, x, y, font, text_color, text_shadow) |
nothing calls this directly
no test coverage detected