Files
SantoscopeUI/circle_button.py
SallarShayegan 6dc72353d7 unknown commit
2025-08-03 13:04:12 +02:00

65 lines
1.9 KiB
Python

import pygame
from .colors import *
import math
class CircleButton:
def __init__(self, gui, position, radius):
self.surface = gui.screen
self.position = position
self.radius = radius
self.color = color_primary
def check_click(self, pos):
if math.sqrt(math.pow(pos[0] - self.position[0], 2) +
math.pow(pos[1] - self.position[1], 2)) < self.radius:
self.on_click()
def on_click(self):
pass
def draw(self):
pass
def display(self):
pygame.draw.circle(self.surface, self.color, self.position, self.radius)
self.draw()
class BeatButton(CircleButton):
def __init__(self, gui, position, radius):
self.playing = False
super().__init__(gui, position, radius)
def on_click(self):
self.playing = not self.playing
def draw(self):
x, y = self.position
pygame.draw.polygon(self.surface, "black", [
(x-self.radius/2.5, y-self.radius/1.5),
(x+self.radius/1.5, y),
(x-self.radius/2.5, y+self.radius/1.5)
], 2 if self.playing else 0)
class LoopButton(CircleButton):
def __init__(self, gui, position, radius):
self.state = False
self.counter = 0
self.frame_threshold = 30
self.recording = False
super().__init__(gui, position, radius)
def on_click(self):
self.recording = not self.recording
self.state = not self.state
def draw(self):
pygame.draw.circle(self.surface, "black", self.position, self.radius/1.5)
pygame.draw.circle(self.surface, self.color, self.position, self.radius/2,
2 if not self.state else 0)
if self.recording:
if self.counter == self.frame_threshold:
self.state = not self.state
self.counter = 0
self.counter += 1