forked from anurag3301/Github-Calendar-Designer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.py
31 lines (25 loc) · 1.08 KB
/
utils.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
class button:
def __init__(self, color, text_color, x, y, width, height, text):
self.color = color
self.x = x
self.y = y
self.width = width
self.height = height
self.text = text
self.text_color = text_color
self.font_size = 27
def draw(self, win, outline=None):
if outline:
pygame.draw.rect(win, outline, (self.x - 2, self.y - 2, self.width + 4, self.height + 4), 0)
pygame.draw.rect(win, self.color, (self.x, self.y, self.width, self.height), 0)
if self.text != '':
font = pygame.font.Font("freesansbold.ttf", self.font_size)
text = font.render(self.text, True, self.text_color)
win.blit(text, (self.x + (self.width // 2 - text.get_width() // 2),
self.y + 3 + ((self.height // 2 - text.get_height() // 2) - 5)))
def isOver(self, pos):
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