From 134d9aa8e453e0aac91927721b2e07f5fe9a26d7 Mon Sep 17 00:00:00 2001 From: SallarShayegan Date: Fri, 28 Feb 2025 19:53:20 +0100 Subject: [PATCH] added a circle button for the loop stations and the beat player --- circle_button.py | 21 +++++++++++++++++++++ main.py | 26 ++++++++++++++++++++++---- 2 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 circle_button.py diff --git a/circle_button.py b/circle_button.py new file mode 100644 index 0000000..b093031 --- /dev/null +++ b/circle_button.py @@ -0,0 +1,21 @@ +import pygame +from colors import * +import math + +class CircleButton: + + def __init__(self, gui, x, y, radius): + self.screen = gui.screen + self.x = x + self.y = y + self.radius = radius + self.color = color_primary + + def check_click(self, pos, action): + if math.sqrt(math.pow(pos[0] - self.x, 2) + + math.pow(pos[1] - self.y, 2)) < self.radius: + action() + + def display(self): + pygame.draw.circle(self.screen, self.color, + (self.x, self.y), self.radius) \ No newline at end of file diff --git a/main.py b/main.py index 28f10dd..de0f0fc 100644 --- a/main.py +++ b/main.py @@ -4,6 +4,8 @@ from fonts import * from knobs import Knobs from lozenge_button import LozengeButton from binary_button import BinaryButton +from circle_button import CircleButton +from functools import partial class GuiMain: @@ -43,12 +45,24 @@ class GuiMain: 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.mute_button = BinaryButton( + self.screen, + (20, self.fx_mode_buttons[0].y-20), + (40, 40), 'M', + False) + self.beat_button = CircleButton(self, 40, self.fx_mode_buttons[1].y, 20) + self.rloop_button = CircleButton(self, 40, self.fx_mode_buttons[2].y, 20) + self.lloop_button = CircleButton(self, 40, self.fx_mode_buttons[3].y, 20) + self.clock = pygame.time.Clock() self.running = True self.run() + def change_color(self, component): + if component.color == color_primary: + component.color = color_primary_dark + else: component.color = color_primary + def set_fx_mode(self, mode): self.fx_mode = self.fx_mode_labels.index(mode) self.knobs[self.fx_mode].set_focused(None) @@ -80,8 +94,9 @@ class GuiMain: (self.fx_mode_buttons[i].radius_x*0.5 + 60, self.fx_mode_buttons[i].y), (self.fx_mode_buttons[i].x - self.fx_mode_buttons[i].radius_x * 1.5, self.fx_mode_buttons[i].y)) - pygame.draw.circle(self.screen, color_primary, - (40, self.fx_mode_buttons[i].y), 20) + self.beat_button.display() + self.lloop_button.display() + self.rloop_button.display() 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 @@ -98,6 +113,9 @@ class GuiMain: if event.type == pygame.MOUSEBUTTONDOWN: if event.button == 1: self.mute_button.check_click(pygame.mouse.get_pos()) + self.beat_button.check_click(pygame.mouse.get_pos(), partial(self.change_color, self.beat_button)) + self.lloop_button.check_click(pygame.mouse.get_pos(), partial(self.change_color, self.lloop_button)) + self.rloop_button.check_click(pygame.mouse.get_pos(), partial(self.change_color, self.rloop_button)) pygame.quit()