import pygame import math from .colors import * FADE_COUNT_DOWN = 150 class Knob: def __init__(self, group, name, radius, position, value = 0): self.group = group self.name = name self.color = color_primary self.radius = radius self.position = position self.value = value self.focused = False self.count_down = FADE_COUNT_DOWN self.vanish_label_path = False self.label_path = [] def set_value(self, value): self.value = value self.count_down = FADE_COUNT_DOWN def set_color(self, color): self.color = color def set_focused(self, focused): if focused: self.focused = True self.color = color_primary_light else: self.focused = False self.color = color_primary self.count_down = FADE_COUNT_DOWN if not self.vanish_label_path: self.label_path = [] def get_position(self): return self.position def get_index(self, knobs): return knobs.index(self) def __eq__(self, other): if other is None: return False return self.name == other.name def get_pointer_position(self): angle = (self.value * 0.8 * 2 + 0.7) * math.pi x = (self.radius - 5) * math.cos(angle) + self.position[0] y = (self.radius - 5) * math.sin(angle) + self.position[1] return(x, y) def display(self, surface): 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.group.set_focused(self) if self.focused: self.count_down -= 1 if self.count_down == 0: self.vanish_label_path = True self.set_focused(False) pygame.draw.circle(surface, self.color + (self.group.opacity,), self.position, self.radius) pygame.draw.line(surface, "black", self.position, self.get_pointer_position(), 4)