Proper grid snapping for audio clips, adjust audio clip and timeline styling

This commit is contained in:
2025-02-16 18:04:44 +01:00
parent ec16023158
commit 178fa40c15
4 changed files with 52 additions and 16 deletions

View File

@@ -1,10 +1,15 @@
class_name AudioClip
extends Panel
@export var clip_name: String = "New Audio Clip"
@export var start_time: float = 0.0
@export var end_time: float = 0.0
@export var track_idx: int = 0
signal on_selected
signal on_deselected
signal on_double_click
var timeline: Timeline
var dragging: bool
@@ -18,13 +23,17 @@ func _input(event):
var mouse_position = get_global_mouse_position()
if event is InputEventMouseButton:
if selected and event.double_click:
print("double clicked!")
on_double_click.emit()
return
if event.pressed and event.button_mask == MOUSE_BUTTON_LEFT:
if selected:
mouse_default_cursor_shape = CURSOR_MOVE
Input.set_default_cursor_shape(Input.CursorShape.CURSOR_MOVE)
dragging = true
else:
dragging = false
mouse_default_cursor_shape = CURSOR_ARROW
Input.set_default_cursor_shape(Input.CursorShape.CURSOR_ARROW)
if rect.has_point(mouse_position):
selected = true
make_selected()
@@ -36,28 +45,33 @@ func _input(event):
if !event.pressed and dragging:
dragging = false
mouse_default_cursor_shape = CURSOR_ARROW
Input.set_default_cursor_shape(Input.CursorShape.CURSOR_ARROW)
if selected and dragging:
if event is InputEventMouseMotion:
var movement = event.relative.x / timeline.get_pixels_per_unit() * timeline.time_interval
start_time += movement
end_time += movement
var mouse_position_timeline = (timeline.get_local_mouse_position().x / timeline.get_pixels_per_unit()) * timeline.time_interval
var mouse_position_snapped = snapped(mouse_position_timeline, timeline.time_interval)
if event.is_command_or_control_pressed():
start_time = snapped(start_time, timeline.time_interval)
end_time = snapped(end_time, timeline.time_interval)
var clip_length = end_time - start_time
start_time = mouse_position_snapped
end_time = start_time + clip_length
else:
start_time += movement
end_time += movement
timeline.queue_sort()
pass
func make_selected():
on_selected.emit()
var color = get_theme_color("selected_modulate", "AudioClip")
modulate = color
pass
func make_deselected():
on_deselected.emit()
var color = get_theme_color("deselected_modulate", "AudioClip")
modulate = color
pass