WIP: audio clip controls and UI
This commit is contained in:
63
Scripts/AudioClip.gd
Normal file
63
Scripts/AudioClip.gd
Normal file
@@ -0,0 +1,63 @@
|
||||
class_name AudioClip
|
||||
extends Panel
|
||||
|
||||
@export var start_time: float = 0.0
|
||||
@export var end_time: float = 0.0
|
||||
@export var track_idx: int = 0
|
||||
|
||||
var timeline: Timeline
|
||||
|
||||
var dragging: bool
|
||||
var selected: bool
|
||||
|
||||
func _ready():
|
||||
timeline = get_parent()
|
||||
|
||||
func _input(event):
|
||||
var rect = get_global_rect()
|
||||
var mouse_position = get_global_mouse_position()
|
||||
|
||||
if event is InputEventMouseButton:
|
||||
if event.pressed and event.button_mask == MOUSE_BUTTON_LEFT:
|
||||
if selected:
|
||||
mouse_default_cursor_shape = CURSOR_MOVE
|
||||
dragging = true
|
||||
else:
|
||||
dragging = false
|
||||
mouse_default_cursor_shape = CURSOR_ARROW
|
||||
if rect.has_point(mouse_position):
|
||||
selected = true
|
||||
make_selected()
|
||||
return
|
||||
else:
|
||||
selected = false
|
||||
make_deselected()
|
||||
return
|
||||
|
||||
if !event.pressed and dragging:
|
||||
dragging = false
|
||||
mouse_default_cursor_shape = 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
|
||||
|
||||
if event.is_command_or_control_pressed():
|
||||
start_time = snapped(start_time, timeline.time_interval)
|
||||
end_time = snapped(end_time, timeline.time_interval)
|
||||
|
||||
timeline.queue_sort()
|
||||
pass
|
||||
|
||||
func make_selected():
|
||||
var color = get_theme_color("selected_modulate", "AudioClip")
|
||||
modulate = color
|
||||
pass
|
||||
|
||||
func make_deselected():
|
||||
var color = get_theme_color("deselected_modulate", "AudioClip")
|
||||
modulate = color
|
||||
pass
|
||||
Reference in New Issue
Block a user