From 813f8d3a355928234140367b3647f33bf9051510 Mon Sep 17 00:00:00 2001 From: SallarShayegan Date: Fri, 28 Feb 2025 16:51:32 +0100 Subject: [PATCH] added a binary_button module for the mute function --- binary_button.py | 30 ++++++++++++++++++++++++++++++ main.py | 21 ++++++++++++++------- 2 files changed, 44 insertions(+), 7 deletions(-) create mode 100644 binary_button.py diff --git a/binary_button.py b/binary_button.py new file mode 100644 index 0000000..e2033fc --- /dev/null +++ b/binary_button.py @@ -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)) \ No newline at end of file diff --git a/main.py b/main.py index 3784d2e..28f10dd 100644 --- a/main.py +++ b/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()