Add center x and y properties to button class
This commit is contained in:
parent
fbf4ea2cc4
commit
f4e1184d5a
|
@ -34,6 +34,8 @@ class Button:
|
||||||
is_number: bool = False
|
is_number: bool = False
|
||||||
flashing: bool = False
|
flashing: bool = False
|
||||||
unflash_on: float = 0.0
|
unflash_on: float = 0.0
|
||||||
|
center_x: int = 0
|
||||||
|
center_y: int = 0
|
||||||
|
|
||||||
keypad_map = {
|
keypad_map = {
|
||||||
str(pygame.K_KP_0): pygame.K_0,
|
str(pygame.K_KP_0): pygame.K_0,
|
||||||
|
@ -125,13 +127,13 @@ def flash_button(b):
|
||||||
def draw_buttons():
|
def draw_buttons():
|
||||||
|
|
||||||
for key, b in buttons.items():
|
for key, b in buttons.items():
|
||||||
center_x = button_origin_x + (b.column * button_spacing)
|
b.center_x = button_origin_x + (b.column * button_spacing)
|
||||||
center_y = button_origin_y + (b.row * button_spacing)
|
b.center_y = button_origin_y + (b.row * button_spacing)
|
||||||
center = (center_x, center_y)
|
center = (b.center_x, b.center_y)
|
||||||
pygame.draw.circle(screen, yellow, center, 50, 2)
|
pygame.draw.circle(screen, yellow, center, 50, 2)
|
||||||
b_text = cheesy_font.render(b.label, True, white)
|
b_text = cheesy_font.render(b.label, True, white)
|
||||||
text_x = center_x - (b_text.get_width() // 2)
|
text_x = b.center_x - (b_text.get_width() // 2)
|
||||||
text_y = center_y - (b_text.get_height() // 2)
|
text_y = b.center_y - (b_text.get_height() // 2)
|
||||||
if b.label == "*":
|
if b.label == "*":
|
||||||
text_y += 15
|
text_y += 15
|
||||||
screen.blit(b_text, (text_x, text_y))
|
screen.blit(b_text, (text_x, text_y))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user