added a binary_button module for the mute function
This commit is contained in:
30
binary_button.py
Normal file
30
binary_button.py
Normal file
@ -0,0 +1,30 @@
|
||||
import pygame
|
||||
from fonts import *
|
||||
from colors import *
|
||||
|
||||
class BinaryButton:
|
||||
|
||||
def __init__(self, screen, position, size, label, state):
|
||||
self.screen = screen
|
||||
self.position = position
|
||||
self.size = size
|
||||
self.label = label
|
||||
self.state = state
|
||||
|
||||
def check_click(self, pos):
|
||||
if pos[0] >= self.position[0] and pos[1] >= self.position[1] and pos[0] <= self.position[0] + self.size[0] and pos[1] <= self.position[1] + self.size[1]:
|
||||
self.state = not self.state
|
||||
|
||||
def display(self):
|
||||
if self.state:
|
||||
w = 0
|
||||
text_color = "black"
|
||||
else:
|
||||
w = 2
|
||||
text_color = color_primary
|
||||
|
||||
pygame.draw.rect(self.screen, color_primary, (self.position, self.size), w)
|
||||
|
||||
label = font_helvetica16.render(self.label, False, text_color)
|
||||
self.screen.blit(label, (self.position[0] + (self.size[0] - label.get_width())/2,
|
||||
self.position[1] + (self.size[1] - label.get_height())/2))
|
||||
Reference in New Issue
Block a user