-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbutton.py
32 lines (27 loc) · 1.24 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
class Button():
def __init__(self,image,pos,textInput,font,baseColor,hoveringColor):
self.image=image
self.x_pos=pos[0]
self.y_pos=pos[1]
self.font=font
self.baseColor=baseColor
self.hoveringColor=hoveringColor
self.textInput=textInput
self.text=self.font.render(self.textInput,True,self.baseColor)
if self.image is None:
self.image=self.text
self.rect=self.image.get_rect(center=(self.x_pos,self.y_pos))
self.textRect=self.text.get_rect(center=(self.x_pos,self.y_pos))
def update(self,ekran):
if self.image is not None:
ekran.blit(self.image,self.rect)
ekran.blit(self.text,self.textRect)
def checkMouse(self,position):
if position[0] in range(self.rect.left,self.rect.right) and position[1] in range(self.rect.top,self.rect.bottom):
return True
return False
def hoverColor(self,position):
if position[0] in range(self.rect.left,self.rect.right) and position[1] in range(self.rect.top,self.rect.bottom):
self.text=self.font.render(self.textInput,True,self.hoveringColor)
else:
self.text=self.font.render(self.textInput,True,self.baseColor)