From 178fa40c15a812452a7efe0542d68616b04eb8db Mon Sep 17 00:00:00 2001 From: dnesov Date: Sun, 16 Feb 2025 18:04:44 +0100 Subject: [PATCH] Proper grid snapping for audio clips, adjust audio clip and timeline styling --- Assets/DefaultTheme.tres | 2 +- Controls/AudioClip.tscn | 27 +++++++++++++++++++++++++-- Scripts/AudioClip.gd | 32 +++++++++++++++++++++++--------- Views/Timeline.tscn | 7 +++---- 4 files changed, 52 insertions(+), 16 deletions(-) diff --git a/Assets/DefaultTheme.tres b/Assets/DefaultTheme.tres index 387bec0..ddc8806 100644 --- a/Assets/DefaultTheme.tres +++ b/Assets/DefaultTheme.tres @@ -4438,7 +4438,7 @@ TextEdit/styles/read_only = SubResource("StyleBoxFlat_6ucq2") ThemeEditor/colors/preview_picker_overlay_color = Color(0.1, 0.1, 0.1, 0.25) ThemeEditor/styles/preview_picker_label = SubResource("StyleBoxFlat_jtsa3") ThemeEditor/styles/preview_picker_overlay = SubResource("StyleBoxFlat_qixj3") -Timeline/colors/line_primary_color = Color(0.4, 0.4, 0.4, 1) +Timeline/colors/line_primary_color = Color(0.25, 0.25, 0.25, 1) Timeline/colors/line_secondary_color = Color(0.2, 0.2, 0.2, 1) Timeline/constants/time_label_offset_x = 30 Timeline/constants/time_label_offset_y = 20 diff --git a/Controls/AudioClip.tscn b/Controls/AudioClip.tscn index 6b4e079..37100cf 100644 --- a/Controls/AudioClip.tscn +++ b/Controls/AudioClip.tscn @@ -23,10 +23,11 @@ theme_override_styles/panel = SubResource("StyleBoxFlat_8tb17") script = ExtResource("1_iy5jd") [node name="Panel" type="Panel" parent="."] -custom_minimum_size = Vector2(0, 14) +custom_minimum_size = Vector2(0, 20) layout_mode = 1 anchors_preset = 10 anchor_right = 1.0 +offset_bottom = 20.0 grow_horizontal = 2 [node name="Label" type="Label" parent="Panel"] @@ -36,7 +37,29 @@ anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 -theme_override_font_sizes/font_size = 8 +theme_override_font_sizes/font_size = 10 text = "New Audio Clip" vertical_alignment = 1 text_overrun_behavior = 3 + +[node name="Window" type="ConfirmationDialog" parent="."] +title = "\"New Audio Clip\" Properties" +size = Vector2i(400, 600) + +[node name="Control" type="Control" parent="Window"] +layout_mode = 3 +anchors_preset = 0 +offset_left = 8.0 +offset_top = 8.0 +offset_right = 92.0 +offset_bottom = 51.0 +size_flags_horizontal = 3 +size_flags_vertical = 3 + +[node name="Label" type="Label" parent="Window/Control"] +layout_mode = 0 +offset_right = 40.0 +offset_bottom = 23.0 +text = "Clip properties!" + +[connection signal="on_double_click" from="." to="Window" method="popup_centered"] diff --git a/Scripts/AudioClip.gd b/Scripts/AudioClip.gd index 2b89cae..9c85015 100644 --- a/Scripts/AudioClip.gd +++ b/Scripts/AudioClip.gd @@ -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 \ No newline at end of file diff --git a/Views/Timeline.tscn b/Views/Timeline.tscn index d36b318..c66c049 100644 --- a/Views/Timeline.tscn +++ b/Views/Timeline.tscn @@ -22,10 +22,9 @@ layout_mode = 2 [node name="AudioClip" parent="." instance=ExtResource("2_an2hv")] layout_mode = 2 -start_time = 4000.0 -end_time = 8000.0 +end_time = 1000.0 [node name="AudioClip2" parent="." instance=ExtResource("2_an2hv")] layout_mode = 2 -start_time = 8000.0 -end_time = 12000.0 +start_time = 3000.0 +end_time = 10000.0