-
Notifications
You must be signed in to change notification settings - Fork 4
/
buttonClass.py
31 lines (25 loc) · 1.05 KB
/
buttonClass.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import pygame, os
from mainConst import screen, pixel_font
from abs_path import abs_path
pygame.init()
class Button:
def __init__(self, x, y, width, height, path, text=None):
self.x = x
self.y = y
self.width = width
self.height = height
self.text = text
self.image = pygame.transform.scale(pygame.image.load(path), (self.width, self.height))
self.normal_image = self.image
self.rect = self.image.get_rect(center=(self.x, self.y))
self.btn_text = pixel_font.render(self.text, True, (255, 255, 255))
self.btn_text_rect = self.btn_text.get_rect()
self.btn_text_rect.center = self.rect.center
def blit_btn(self):
screen.blit(self.image, self.rect)
screen.blit(self.btn_text, self.btn_text_rect)
def hover(self, x, y):
if self.rect.collidepoint((x, y)):
self.image = pygame.transform.scale(pygame.image.load(abs_path('images/sprites/buttonLong_blue.png')), (self.width, self.height))
else:
self.image = self.normal_image