-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButton.py
More file actions
50 lines (44 loc) · 1.67 KB
/
Button.py
File metadata and controls
50 lines (44 loc) · 1.67 KB
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
import pygame
class Button:
backImage = None
text = None
textObj = None
allButtonsVector = []
#
pygame.font.init()
font = pygame.font.Font(None, 26)
whiteColor = (255, 255, 255)
grayColor = (40,40,40)
lightGrayColor = (120,120,120)
def __init__(self,posX,posY,text):
self.text = text
self.posX = posX
self.posY = posY
#
self.textObj = Button.font.render(self.text, True, Button.whiteColor)
sizeX, sizeY = self.textObj.get_size()
# BackImage
self.backImage = pygame.Surface((sizeX+10,sizeY+10))
self.backImage.set_alpha(128)
self.backImage.fill(Button.grayColor)
#
self.rect = pygame.Rect(self.posX, self.posY, sizeX+10, sizeY+10)
Button.allButtonsVector.append(self)
@staticmethod
def DrawButton(screen,button):
screen.blit(button.backImage,(button.posX,button.posY))
screen.blit(button.textObj,(button.posX+5, button.posY+5))
@staticmethod
def CheckGlowOnHold(mouseX,mouseY):
for button in Button.allButtonsVector:
if button.rect.collidepoint(mouseX, mouseY):
button.backImage.set_alpha(200)
button.backImage.fill(Button.lightGrayColor)
else:
button.backImage.set_alpha(200)
button.backImage.fill(Button.grayColor)
def SetPosition(self,newX,newY):
self.posX = newX
self.posY = newY
self.rect.x = newX
self.rect.y = newY