2024-02-23 19:35:20 +01:00
|
|
|
import pygame
|
|
|
|
|
|
|
|
class Button():
|
2024-02-24 21:59:53 +01:00
|
|
|
def __init__(self, screen, color, pos, width, height, text) -> None:
|
|
|
|
self.pos = pos
|
2024-02-23 19:35:20 +01:00
|
|
|
self.größe = width,height
|
|
|
|
self.color = color
|
|
|
|
self.screen = screen
|
|
|
|
self.text = text
|
|
|
|
def draw(self):
|
|
|
|
pygame.draw.rect(self.screen,
|
|
|
|
self.color,
|
|
|
|
(self.pos[0]-self.größe[0]//2,
|
|
|
|
self.pos[1]-self.größe[1]//2,
|
|
|
|
self.größe[0],
|
|
|
|
self.größe[1])
|
|
|
|
)
|
2024-02-24 21:59:53 +01:00
|
|
|
pygame.draw.rect(self.screen,
|
|
|
|
(0,150,0),
|
|
|
|
(self.pos[0]-self.größe[0]//2,
|
|
|
|
self.pos[1]-self.größe[1]//2,
|
|
|
|
self.größe[0],
|
|
|
|
self.größe[1]),
|
|
|
|
2
|
|
|
|
)
|
2024-02-23 19:35:20 +01:00
|
|
|
|
2024-02-24 21:59:53 +01:00
|
|
|
font = pygame.font.Font(None, 30)
|
2024-02-23 19:35:20 +01:00
|
|
|
text_surface = font.render(self.text, True, (0,0,0))
|
|
|
|
text_rect = text_surface.get_rect()
|
|
|
|
text_rect.center = (self.pos[0],
|
|
|
|
self.pos[1])
|
|
|
|
self.screen.blit(text_surface, text_rect)
|
2024-02-25 11:35:01 +01:00
|
|
|
def check_hovered(self, mouse):
|
2024-02-23 19:35:20 +01:00
|
|
|
if (self.pos[0] - self.größe[0]//2 <= mouse[0] <= self.pos[0] + self.größe[0]//2 and
|
|
|
|
self.pos[1] - self.größe[1]//2 <= mouse[1] <= self.pos[1] + self.größe[1]//2):
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|