forked from mattboan/Galtron
-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathbutton.py
61 lines (45 loc) · 1.79 KB
/
button.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import pygame.font
import utilityFunctions
buttons = []
getInvertedRGB = utilityFunctions.getInvertedRGB
class Button():
"""Button Class"""
def __init__(self, setting, screen, msg, yCord):
"""initialize button attributes"""
self.screen = screen
self.screenRect = screen.get_rect()
# Set the dimensions and properties of the button"""
self.width, self.height = 100, 30
self.buttonColor = (255, 255, 255)
self.textColor = (0, 0, 0)
self.font = pygame.font.Font('Fonts/Square.ttf', 28)
# Buid the button rect object and center it.
self.rect = pygame.Rect(0, 0, self.width, self.height)
self.rect.centerx = self.screenRect.centerx
self.rect.y = yCord
# Set the default state color switch of the button being selected to False
self.switched = False
self.msg = msg
self.prepMsg(msg)
buttons.append(self)
def __del__(self):
if self in buttons:
buttons.remove(self)
def invertColorAll():
for btn in buttons:
btn.invertColor()
def invertColor(self):
self.buttonColor = getInvertedRGB(self.buttonColor)
self.textColor = getInvertedRGB(self.textColor)
self.prepMsg(self.msg)
def prepMsg(self, msg):
"""Turn msg insto a rendered image and center text on the button"""
self.msgImage = self.font.render(msg, True, self.textColor, self.buttonColor)
self.msgImageRect = self.msgImage.get_rect()
self.msgImageRect.center = self.rect.center
def updateBtn(self, selected):
pass
def drawBtn(self):
# Draw blank button and then draw message
self.screen.fill(self.buttonColor, self.rect)
self.screen.blit(self.msgImage, self.msgImageRect)