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))
|
||||
21
main.py
21
main.py
@ -3,12 +3,14 @@ from colors import *
|
||||
from fonts import *
|
||||
from knobs import Knobs
|
||||
from lozenge_button import LozengeButton
|
||||
from binary_button import BinaryButton
|
||||
|
||||
class GuiMain:
|
||||
|
||||
def __init__(self):
|
||||
# pygame setup
|
||||
pygame.init()
|
||||
pygame.display.set_caption("SantoscopeUI")
|
||||
self.screen = pygame.display.set_mode((800, 480))
|
||||
#self.screen = pygame.display.set_mode((0,0), pygame.FULLSCREEN)
|
||||
self.screenH = self.screen.get_height()
|
||||
@ -40,7 +42,9 @@ class GuiMain:
|
||||
self.knobs.append(Knobs(self))
|
||||
|
||||
self.set_fx_mode(self.fx_mode_labels[self.fx_mode])
|
||||
|
||||
|
||||
self.mute_button = BinaryButton(self.screen, (20, self.fx_mode_buttons[0].y-20), (40, 40), 'M', False)
|
||||
|
||||
self.clock = pygame.time.Clock()
|
||||
self.running = True
|
||||
self.run()
|
||||
@ -69,6 +73,8 @@ class GuiMain:
|
||||
for button in self.fx_mode_buttons:
|
||||
button.display()
|
||||
|
||||
self.mute_button.display()
|
||||
|
||||
for i in range(1,4):
|
||||
pygame.draw.line(self.screen, color_primary_dark,
|
||||
(self.fx_mode_buttons[i].radius_x*0.5 + 60, self.fx_mode_buttons[i].y),
|
||||
@ -76,8 +82,6 @@ class GuiMain:
|
||||
self.fx_mode_buttons[i].y))
|
||||
pygame.draw.circle(self.screen, color_primary,
|
||||
(40, self.fx_mode_buttons[i].y), 20)
|
||||
pygame.draw.rect(self.screen, color_primary,
|
||||
((20, self.fx_mode_buttons[0].y-20),(40, 40)))
|
||||
|
||||
pygame.draw.polygon(self.screen, "white", [(0, self.screenH/2), (self.screenW*3 / 19, self.screenH), (0, self.screenH)])
|
||||
# flip() the display to put your work on screen
|
||||
@ -87,10 +91,13 @@ class GuiMain:
|
||||
|
||||
# exit when esc is pressed
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.KEYDOWN:
|
||||
if event.key == pygame.K_ESCAPE:
|
||||
pygame.quit()
|
||||
return
|
||||
if event.type == pygame.KEYDOWN:
|
||||
if event.key == pygame.K_ESCAPE:
|
||||
pygame.quit()
|
||||
return
|
||||
if event.type == pygame.MOUSEBUTTONDOWN:
|
||||
if event.button == 1:
|
||||
self.mute_button.check_click(pygame.mouse.get_pos())
|
||||
|
||||
pygame.quit()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user