created a knobs module to outsource the grouping of the knobs

This commit is contained in:
SallarShayegan
2025-02-28 13:16:39 +01:00
parent 043c847801
commit 06006194a8
3 changed files with 94 additions and 87 deletions

13
knob.py
View File

@ -4,10 +4,9 @@ from colors import *
class Knob:
def __init__(self, gui, name, radius, position):
self.gui = gui
def __init__(self, group, name, radius, position):
self.group = group
self.name = name
self.screen = gui.screen
self.color = color_primary
self.radius = radius
self.position = position
@ -24,7 +23,7 @@ class Knob:
if focused:
self.focused = True
self.color = color_primary_light
self.gui.deactivate_knobs_except(self)
self.group.deactivate_knobs_except(self)
else:
self.focused = False
self.color = color_primary
@ -41,13 +40,13 @@ class Knob:
y = (self.radius - 5) * math.sin(angle) + self.position[1]
return(x, y)
def display(self):
def display(self, screen):
m1, m2, m3 = pygame.mouse.get_pressed(3)
if m1:
pos = pygame.mouse.get_pos()
if math.sqrt(math.pow(pos[0]-self.position[0],2) + math.pow(pos[1]-self.position[1],2)) < self.radius:
self.set_focused(True)
pygame.draw.circle(self.screen, self.color, self.position, self.radius)
pygame.draw.line(self.screen, "black", self.position, self.get_pointer_position(), 4)
pygame.draw.circle(screen, self.color, self.position, self.radius)
pygame.draw.line(screen, "black", self.position, self.get_pointer_position(), 4)