added an animation for vanishing the label path
This commit is contained in:
9
knob.py
9
knob.py
@ -12,6 +12,9 @@ class Knob:
|
|||||||
self.position = position
|
self.position = position
|
||||||
self.value = value
|
self.value = value
|
||||||
self.focused = False
|
self.focused = False
|
||||||
|
self.fade_count_down = 300
|
||||||
|
self.vanish_label_path = False
|
||||||
|
self.label_path = []
|
||||||
|
|
||||||
def set_value(self, value):
|
def set_value(self, value):
|
||||||
self.value = value
|
self.value = value
|
||||||
@ -26,6 +29,8 @@ class Knob:
|
|||||||
else:
|
else:
|
||||||
self.focused = False
|
self.focused = False
|
||||||
self.color = color_primary
|
self.color = color_primary
|
||||||
|
self.fade_count_down = 300
|
||||||
|
if not self.vanish_label_path: self.label_path = []
|
||||||
|
|
||||||
def get_position(self):
|
def get_position(self):
|
||||||
return self.position
|
return self.position
|
||||||
@ -46,7 +51,11 @@ class Knob:
|
|||||||
pos = pygame.mouse.get_pos()
|
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:
|
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)
|
self.group.set_focused(self)
|
||||||
|
if self.focused: self.fade_count_down -= 1
|
||||||
|
|
||||||
|
if self.fade_count_down == 0:
|
||||||
|
self.vanish_label_path = True
|
||||||
|
self.set_focused(False)
|
||||||
pygame.draw.circle(screen, self.color, self.position, self.radius)
|
pygame.draw.circle(screen, self.color, self.position, self.radius)
|
||||||
pygame.draw.line(screen, "black", self.position, self.get_pointer_position(), 4)
|
pygame.draw.line(screen, "black", self.position, self.get_pointer_position(), 4)
|
||||||
|
|
||||||
84
knobs.py
84
knobs.py
@ -49,34 +49,68 @@ class Knobs:
|
|||||||
label_y = (self.gui.screenH - label_fx_name.get_height() - label_fx_value.get_height()) / 2
|
label_y = (self.gui.screenH - label_fx_name.get_height() - label_fx_value.get_height()) / 2
|
||||||
self.gui.screen.blit(label_fx_name, (label_x, label_y))
|
self.gui.screen.blit(label_fx_name, (label_x, label_y))
|
||||||
self.gui.screen.blit(label_fx_value, (label_x, self.gui.screenH / 2))
|
self.gui.screen.blit(label_fx_value, (label_x, self.gui.screenH / 2))
|
||||||
pygame.draw.line(self.gui.screen, color_primary_dark, (label_x - 10, label_y), (label_x - 10, self.gui.screenH - label_y), 2)
|
pygame.draw.line(
|
||||||
|
self.gui.screen,
|
||||||
|
color_primary_dark,
|
||||||
|
(label_x - 10, label_y),
|
||||||
|
(label_x - 10, self.gui.screenH - label_y),
|
||||||
|
2
|
||||||
|
)
|
||||||
|
|
||||||
|
self.calculate_label_path(knob, label_x)
|
||||||
|
|
||||||
|
for i in range(len(knob.label_path)-1):
|
||||||
|
pygame.draw.line(
|
||||||
|
self.gui.screen,
|
||||||
|
color_primary_dark,
|
||||||
|
knob.label_path[i],
|
||||||
|
knob.label_path[i+1],
|
||||||
|
2
|
||||||
|
)
|
||||||
|
|
||||||
line_points = []
|
def calculate_label_path(self, knob, label_x):
|
||||||
line_points.append(knob.get_position())
|
if len(knob.label_path) == 0:
|
||||||
|
knob.label_path.append(knob.get_position())
|
||||||
|
if (knob == self.knobs[0] or knob == self.knobs[1] or
|
||||||
|
knob == self.knobs[4] or knob == self.knobs[5]):
|
||||||
|
x = knob.get_position()[0] + self.knobs_radius * 1.5
|
||||||
|
y = knob.get_position()[1] + self.knobs_radius * 1.5
|
||||||
|
knob.label_path.append((x, y))
|
||||||
|
elif (knob == self.knobs[2] or knob == self.knobs[3] or knob == self.knobs[6]):
|
||||||
|
x = knob.get_position()[0] + self.knobs_radius * 1.5
|
||||||
|
y = knob.get_position()[1] - self.knobs_radius * 1.5
|
||||||
|
knob.label_path.append((x, y))
|
||||||
|
elif (knob == self.knobs[7]):
|
||||||
|
x = knob.get_position()[0] - self.knobs_radius * 1.5
|
||||||
|
y = knob.get_position()[1] + self.knobs_radius * 1.5
|
||||||
|
knob.label_path.append((x, y))
|
||||||
|
|
||||||
if (knob == self.knobs[0] or knob == self.knobs[1] or
|
if (knob == self.knobs[0] or knob == self.knobs[3]):
|
||||||
knob == self.knobs[4] or knob == self.knobs[5]):
|
knob.label_path.append((self.knobs[0].get_position()[0] + self.knobs_radius * 1.5, self.gui.screenH/2))
|
||||||
x = knob.get_position()[0] + self.knobs_radius * 1.5
|
elif (knob == self.knobs[4] or knob == self.knobs[6] or knob == self.knobs[7]):
|
||||||
y = knob.get_position()[1] + self.knobs_radius * 1.5
|
knob.label_path.append((self.knobs[4].get_position()[0] + self.knobs_radius * 1.5, self.gui.screenH/2))
|
||||||
line_points.append((x, y))
|
|
||||||
elif (knob == self.knobs[2] or knob == self.knobs[3] or knob == self.knobs[6]):
|
|
||||||
x = knob.get_position()[0] + self.knobs_radius * 1.5
|
|
||||||
y = knob.get_position()[1] - self.knobs_radius * 1.5
|
|
||||||
line_points.append((x, y))
|
|
||||||
elif (knob == self.knobs[7]):
|
|
||||||
x = knob.get_position()[0] - self.knobs_radius * 1.5
|
|
||||||
y = knob.get_position()[1] + self.knobs_radius * 1.5
|
|
||||||
line_points.append((x, y))
|
|
||||||
|
|
||||||
if (knob == self.knobs[0] or knob == self.knobs[3]):
|
knob.label_path.append((label_x - 10, self.gui.screenH/2))
|
||||||
line_points.append((self.knobs[0].get_position()[0] + self.knobs_radius * 1.5, self.gui.screenH/2))
|
|
||||||
elif (knob == self.knobs[4] or knob == self.knobs[6] or knob == self.knobs[7]):
|
|
||||||
line_points.append((self.knobs[4].get_position()[0] + self.knobs_radius * 1.5, self.gui.screenH/2))
|
|
||||||
|
|
||||||
line_points.append((label_x - 10, self.gui.screenH/2))
|
elif knob.vanish_label_path:
|
||||||
|
if len(knob.label_path) > 1:
|
||||||
for i in range(len(line_points)-1):
|
p1 = list(knob.label_path[0])
|
||||||
pygame.draw.line(self.gui.screen, color_primary_dark, line_points[i], line_points[i+1], 2)
|
p2 = list(knob.label_path[1])
|
||||||
|
if abs(p1[0] - p2[0]) <= 10 and abs(p1[1] - p2[1]) <= 10:
|
||||||
|
knob.label_path.remove(tuple(p1))
|
||||||
|
else:
|
||||||
|
if p1[0] > p2[0]:
|
||||||
|
p1[0] -= 10
|
||||||
|
elif p1[0] < p2[0]:
|
||||||
|
p1[0] += 10
|
||||||
|
if p1[1] > p2[1]:
|
||||||
|
p1[1] -= 10
|
||||||
|
elif p1[1] < p2[1]:
|
||||||
|
p1[1] += 10
|
||||||
|
knob.label_path[0] = tuple(p1)
|
||||||
|
else:
|
||||||
|
knob.vanish_label_path = False
|
||||||
|
knob.label_path = []
|
||||||
|
|
||||||
def set_focused(self, knob):
|
def set_focused(self, knob):
|
||||||
for k in self.knobs:
|
for k in self.knobs:
|
||||||
@ -84,5 +118,5 @@ class Knobs:
|
|||||||
|
|
||||||
def display(self):
|
def display(self):
|
||||||
for knob in self.knobs:
|
for knob in self.knobs:
|
||||||
if knob.focused: self.display_label(knob)
|
if knob.focused or knob.vanish_label_path: self.display_label(knob)
|
||||||
knob.display(self.gui.screen)
|
knob.display(self.gui.screen)
|
||||||
|
|||||||
Reference in New Issue
Block a user