added a circle button for the loop stations and the beat player
This commit is contained in:
21
circle_button.py
Normal file
21
circle_button.py
Normal file
@ -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)
|
||||||
24
main.py
24
main.py
@ -4,6 +4,8 @@ from fonts import *
|
|||||||
from knobs import Knobs
|
from knobs import Knobs
|
||||||
from lozenge_button import LozengeButton
|
from lozenge_button import LozengeButton
|
||||||
from binary_button import BinaryButton
|
from binary_button import BinaryButton
|
||||||
|
from circle_button import CircleButton
|
||||||
|
from functools import partial
|
||||||
|
|
||||||
class GuiMain:
|
class GuiMain:
|
||||||
|
|
||||||
@ -43,12 +45,24 @@ class GuiMain:
|
|||||||
|
|
||||||
self.set_fx_mode(self.fx_mode_labels[self.fx_mode])
|
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.clock = pygame.time.Clock()
|
||||||
self.running = True
|
self.running = True
|
||||||
self.run()
|
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):
|
def set_fx_mode(self, mode):
|
||||||
self.fx_mode = self.fx_mode_labels.index(mode)
|
self.fx_mode = self.fx_mode_labels.index(mode)
|
||||||
self.knobs[self.fx_mode].set_focused(None)
|
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].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].x - self.fx_mode_buttons[i].radius_x * 1.5,
|
||||||
self.fx_mode_buttons[i].y))
|
self.fx_mode_buttons[i].y))
|
||||||
pygame.draw.circle(self.screen, color_primary,
|
self.beat_button.display()
|
||||||
(40, self.fx_mode_buttons[i].y), 20)
|
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)])
|
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
|
# flip() the display to put your work on screen
|
||||||
@ -98,6 +113,9 @@ class GuiMain:
|
|||||||
if event.type == pygame.MOUSEBUTTONDOWN:
|
if event.type == pygame.MOUSEBUTTONDOWN:
|
||||||
if event.button == 1:
|
if event.button == 1:
|
||||||
self.mute_button.check_click(pygame.mouse.get_pos())
|
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()
|
pygame.quit()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user