MCPcopy Create free account
hub / github.com/YPAndrew0907/Animal-Simulation-game / button

Function button

gui.py:16–40  ·  view source on GitHub ↗
(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)

Source from the content-addressed store, hash-verified

14
15is_mouse_just_clicked = False
16def 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)

Callers

nothing calls this directly

Calls 1

draw_textFunction · 0.85

Tested by

no test coverage detected