Add center x and y properties to button class

This commit is contained in:
Junior 2024-06-05 15:27:07 -04:00
parent fbf4ea2cc4
commit f4e1184d5a

View File

@ -34,6 +34,8 @@ class Button:
is_number: bool = False
flashing: bool = False
unflash_on: float = 0.0
center_x: int = 0
center_y: int = 0
keypad_map = {
str(pygame.K_KP_0): pygame.K_0,
@ -125,13 +127,13 @@ def flash_button(b):
def draw_buttons():
for key, b in buttons.items():
center_x = button_origin_x + (b.column * button_spacing)
center_y = button_origin_y + (b.row * button_spacing)
center = (center_x, center_y)
b.center_x = button_origin_x + (b.column * button_spacing)
b.center_y = button_origin_y + (b.row * button_spacing)
center = (b.center_x, b.center_y)
pygame.draw.circle(screen, yellow, center, 50, 2)
b_text = cheesy_font.render(b.label, True, white)
text_x = center_x - (b_text.get_width() // 2)
text_y = center_y - (b_text.get_height() // 2)
text_x = b.center_x - (b_text.get_width() // 2)
text_y = b.center_y - (b_text.get_height() // 2)
if b.label == "*":
text_y += 15
screen.blit(b_text, (text_x, text_y))