-
Notifications
You must be signed in to change notification settings - Fork 0
/
buttons.py
28 lines (24 loc) · 1.08 KB
/
buttons.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
from settings import *
class Buttons():
def __init__(self, app, colour, x, y, width, height, text=''):
self.app = app
self.colour = colour
self.x = x
self.y = y
self.width = width
self.height = height
self.text = text
def draw_button(self, outline = None):
if outline:
pygame.draw.rect(self.app.screen, outline, (self.x-2, self.y-2, self.width+4, self.height+4), 0)
pygame.draw.rect(self.app.screen, self.colour, (self.x, self.y, self.width, self.height), 0)
if self.text != '':
font = pygame.font.SysFont(FONT, 28)
text = font.render(self.text, 1, (0, 0, 0))
self.app.screen.blit(text, (self.x + (self.width / 2 - text.get_width() / 2), self.y + (self.height / 2 - text.get_height() / 2)))
def isOver(self, pos):
# Pos is the mouse position or a tuple of (x,y) coordinates
if pos[0] > self.x and pos[0] < self.x + self.width:
if pos[1] > self.y and pos[1] < self.y + self.height:
return True
return False