From 0e503b1c7afda777f3c99d589e320cfd5b61eb28 Mon Sep 17 00:00:00 2001 From: Mario Steele Date: Fri, 23 May 2025 00:20:04 -0500 Subject: [PATCH 1/4] Added ExtensionMethods Added ToVector2I() for Vector2. --- src/Utils/ExtensionMethods.cs | 12 ++++++++++++ src/Utils/ExtensionMethods.cs.uid | 1 + 2 files changed, 13 insertions(+) create mode 100644 src/Utils/ExtensionMethods.cs create mode 100644 src/Utils/ExtensionMethods.cs.uid diff --git a/src/Utils/ExtensionMethods.cs b/src/Utils/ExtensionMethods.cs new file mode 100644 index 0000000..a1dc4de --- /dev/null +++ b/src/Utils/ExtensionMethods.cs @@ -0,0 +1,12 @@ +using Godot; + +namespace GodAmp.Utils; + +public static class ExtensionMethods +{ + public static Vector2I ToVector2I(this Vector2 vector) + { + var v = vector.Floor(); + return new Vector2I((int)v.X, (int)v.Y); + } +} \ No newline at end of file diff --git a/src/Utils/ExtensionMethods.cs.uid b/src/Utils/ExtensionMethods.cs.uid new file mode 100644 index 0000000..29bf003 --- /dev/null +++ b/src/Utils/ExtensionMethods.cs.uid @@ -0,0 +1 @@ +uid://nmivlvtbjtc0 From 4dcc648727131f291d286858a26e0ebf4c922141 Mon Sep 17 00:00:00 2001 From: Mario Steele Date: Fri, 23 May 2025 00:22:08 -0500 Subject: [PATCH 2/4] Removed Old Code for Dragging --- src/Components/WindowPanelContainer.cs | 53 -------------------------- 1 file changed, 53 deletions(-) diff --git a/src/Components/WindowPanelContainer.cs b/src/Components/WindowPanelContainer.cs index 1ca46a3..8c1ff40 100644 --- a/src/Components/WindowPanelContainer.cs +++ b/src/Components/WindowPanelContainer.cs @@ -7,40 +7,9 @@ public partial class WindowPanelContainer : PanelContainer [Signal] public delegate void CloseButtonClickedEventHandler(); [Export] public Control Contents; - [Export] public bool MoveGlobalWindow = false; private bool _minimized = false; private bool _closed = false; - - private bool _dragging = false; - private Vector2 _dragOffset = Vector2.Zero; - private Input.MouseModeEnum _previousMouseMode; - - public override void _Input(InputEvent @event) - { - if (_dragging && MoveGlobalWindow && @event is InputEventMouseMotion motionEvent) - { - // Calculate the window scale factor by comparing current size to content scale - float scaleFactorX = GetWindow().Size.X / GetViewport().GetVisibleRect().Size.X; - float scaleFactorY = GetWindow().Size.Y / GetViewport().GetVisibleRect().Size.Y; - float scaleFactor = (scaleFactorX + scaleFactorY) / 2.0f; - - Vector2 scaledMotion = motionEvent.Relative * scaleFactor; - - // Apply the scaled movement to the window position - Vector2I windowPosition = DisplayServer.WindowGetPosition(); - windowPosition += new Vector2I((int)scaledMotion.X, (int)scaledMotion.Y); - DisplayServer.WindowSetPosition(windowPosition); - } - } - - public override void _Process(double delta) - { - if (_dragging && !MoveGlobalWindow) - { - GlobalPosition = GetGlobalMousePosition() - _dragOffset; - } - } public virtual void OnCloseButtonPressed() { @@ -54,26 +23,4 @@ public virtual void OnMinimizeButtonPressed() _minimized = !_minimized; Contents.Visible = !Contents.Visible; } - - private void OnDraggablePanelInput(InputEvent @event) - { - if (@event is InputEventMouseButton mouseEvent) - { - if (mouseEvent.ButtonIndex == MouseButton.Left) - { - if (mouseEvent.Pressed) - { - _dragging = true; - if (!MoveGlobalWindow) - { - _dragOffset = GetGlobalMousePosition() - GlobalPosition; - } - } - else - { - _dragging = false; - } - } - } - } } \ No newline at end of file From a8289f9a243cde19a65eebc00d859011f98d4f96 Mon Sep 17 00:00:00 2001 From: Mario Steele Date: Fri, 23 May 2025 00:23:47 -0500 Subject: [PATCH 3/4] Updated DraggablePanel Changed from Panel to Control Internalized Moving Window to said control, instead of having it on the WindowPanelContainer. Moved to GuiInput to handle capturing of Mouse Button events, and toggling on/off grabbing the DraggablePanel. Used _Process to directly move the main window. --- src/Components/DraggablePanel.cs | 41 ++++++++++++++++------------- src/Components/draggable_panel.tscn | 11 ++++---- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/src/Components/DraggablePanel.cs b/src/Components/DraggablePanel.cs index 00a2790..2e0bb33 100644 --- a/src/Components/DraggablePanel.cs +++ b/src/Components/DraggablePanel.cs @@ -1,26 +1,31 @@ +using GodAmp.Utils; using Godot; namespace GodAmp.Components; -public partial class DraggablePanel : Panel +public partial class DraggablePanel : Control { - [Signal] public delegate void OnDraggablePanelInputEventHandler(); - - public override void _Input(InputEvent @event) + private bool _following = false; + + private Vector2I _mouseOffset; + + public override void _Ready() + { + GuiInput += OnGuiInput; + } + + private void OnGuiInput(InputEvent inputEvent) { - if (!Visible) - return; - - if (@event is InputEventMouseButton mouseEvent) - { - if (mouseEvent.Pressed && GetGlobalRect().HasPoint(mouseEvent.GlobalPosition)) - { - EmitSignal(SignalName.OnDraggablePanelInput, @event); - } - else if (!mouseEvent.Pressed) - { - EmitSignal(SignalName.OnDraggablePanelInput, @event); - } - } + if (inputEvent is not InputEventMouseButton { ButtonIndex: MouseButton.Left }) return; + _following = !_following; + MouseDefaultCursorShape = _following ? CursorShape.Move : CursorShape.Arrow; + _mouseOffset = GetTree().Root.GetMousePosition().ToVector2I(); + } + + public override void _Process(double delta) + { + if (!_following) return; + + GetTree().Root.Position = DisplayServer.MouseGetPosition() - _mouseOffset; } } \ No newline at end of file diff --git a/src/Components/draggable_panel.tscn b/src/Components/draggable_panel.tscn index 63b8f6c..05562df 100644 --- a/src/Components/draggable_panel.tscn +++ b/src/Components/draggable_panel.tscn @@ -1,12 +1,11 @@ -[gd_scene load_steps=3 format=3 uid="uid://btjg3gj5nwcqw"] +[gd_scene load_steps=2 format=3 uid="uid://btjg3gj5nwcqw"] [ext_resource type="Script" uid="uid://cqqxnfydcmiuw" path="res://src/Components/DraggablePanel.cs" id="1_7rr22"] -[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_y504q"] - -[node name="DraggablePanel" type="Panel"] +[node name="DraggablePanel" type="Control"] custom_minimum_size = Vector2(0, 28) +layout_mode = 3 +anchors_preset = 0 +offset_bottom = 28.0 size_flags_vertical = 0 -mouse_filter = 2 -theme_override_styles/panel = SubResource("StyleBoxEmpty_y504q") script = ExtResource("1_7rr22") From 76e63b452937531bfbadebd5d72ce834f3970e3e Mon Sep 17 00:00:00 2001 From: Mario Steele Date: Fri, 23 May 2025 00:25:41 -0500 Subject: [PATCH 4/4] Updated UI Elements Updated UI Elements to use new DraggablePanel content. On Windows with Close Buttons, placed DraggablePanel inside of HBoxContainer, and placed an Empty Control where the Close Button would be, ensuring enough space to allow Mouse to fully interact with the Close Button. Ensured that DraggablePanel captures Mouse Inputs, while the Empty Control, will ignore them. --- src/Controls/Equalizer/equalizer.tscn | 14 ++++++++++++-- src/Controls/MasterPanel/master_panel.tscn | 14 ++++++++++++-- src/Controls/Playlist/playlist.tscn | 14 ++++++++++++-- src/Visualizer/visualizer.tscn | 1 - 4 files changed, 36 insertions(+), 7 deletions(-) diff --git a/src/Controls/Equalizer/equalizer.tscn b/src/Controls/Equalizer/equalizer.tscn index bcfe23a..0d56f7b 100644 --- a/src/Controls/Equalizer/equalizer.tscn +++ b/src/Controls/Equalizer/equalizer.tscn @@ -514,8 +514,19 @@ text = "16K" horizontal_alignment = 1 vertical_alignment = 1 -[node name="DraggablePanel" parent="." instance=ExtResource("7_r0ulg")] +[node name="HBoxContainer" type="HBoxContainer" parent="."] layout_mode = 2 +size_flags_vertical = 0 +mouse_filter = 2 + +[node name="DraggablePanel" parent="HBoxContainer" instance=ExtResource("7_r0ulg")] +layout_mode = 2 +size_flags_horizontal = 3 + +[node name="Control" type="Control" parent="HBoxContainer"] +custom_minimum_size = Vector2(28, 0) +layout_mode = 2 +mouse_filter = 2 [connection signal="pressed" from="HeaderContainer/HBoxContainer/MinimizeButton" to="." method="OnMinimizeButtonPressed"] [connection signal="pressed" from="HeaderContainer/HBoxContainer/CloseButton" to="." method="OnCloseButtonPressed"] @@ -531,4 +542,3 @@ layout_mode = 2 [connection signal="value_changed" from="ContentContainer/MarginContainer/VBoxContainer/HBoxContainer2/VBoxContainer9/12KSlider" to="." method="On12KSliderValueChanged"] [connection signal="value_changed" from="ContentContainer/MarginContainer/VBoxContainer/HBoxContainer2/VBoxContainer10/14KSlider" to="." method="On14KSliderValueChanged"] [connection signal="value_changed" from="ContentContainer/MarginContainer/VBoxContainer/HBoxContainer2/VBoxContainer11/16KSlider" to="." method="On16KSliderValueChanged"] -[connection signal="OnDraggablePanelInput" from="DraggablePanel" to="." method="OnDraggablePanelInput"] diff --git a/src/Controls/MasterPanel/master_panel.tscn b/src/Controls/MasterPanel/master_panel.tscn index 0572355..8ca35e5 100644 --- a/src/Controls/MasterPanel/master_panel.tscn +++ b/src/Controls/MasterPanel/master_panel.tscn @@ -515,8 +515,19 @@ texture_normal = SubResource("AtlasTexture_1qudr") texture_pressed = SubResource("AtlasTexture_u5eu6") stretch_mode = 5 -[node name="DraggablePanel" parent="." instance=ExtResource("12_x5ey5")] +[node name="HBoxContainer" type="HBoxContainer" parent="."] layout_mode = 2 +size_flags_vertical = 0 +mouse_filter = 2 + +[node name="DraggablePanel" parent="HBoxContainer" instance=ExtResource("12_x5ey5")] +layout_mode = 2 +size_flags_horizontal = 3 + +[node name="Control" type="Control" parent="HBoxContainer"] +custom_minimum_size = Vector2(28, 24) +layout_mode = 2 +mouse_filter = 2 [connection signal="pressed" from="HeaderContainer/HBoxContainer/MinimizeButton" to="." method="OnMinimizeButtonPressed"] [connection signal="pressed" from="HeaderContainer/HBoxContainer/CloseButton" to="." method="OnCloseButtonPressed"] @@ -541,4 +552,3 @@ layout_mode = 2 [connection signal="pressed" from="ContentContainer/MarginContainer/VBoxContainer/HBoxContainer3/HBoxContainer2/LoadTracksButton" to="." method="OnLoadTracksButtonPressed"] [connection signal="pressed" from="ContentContainer/MarginContainer/VBoxContainer/HBoxContainer3/HBoxContainer3/ShuffleModeButton" to="." method="OnShuffleModeButtonPressed"] [connection signal="pressed" from="ContentContainer/MarginContainer/VBoxContainer/HBoxContainer3/HBoxContainer3/RepeatModeButton" to="." method="OnRepeatModeButtonPressed"] -[connection signal="OnDraggablePanelInput" from="DraggablePanel" to="." method="OnDraggablePanelInput"] diff --git a/src/Controls/Playlist/playlist.tscn b/src/Controls/Playlist/playlist.tscn index fafd928..8c7564e 100644 --- a/src/Controls/Playlist/playlist.tscn +++ b/src/Controls/Playlist/playlist.tscn @@ -134,9 +134,19 @@ layout_mode = 2 size_flags_horizontal = 3 size_flags_vertical = 3 -[node name="DraggablePanel" parent="." instance=ExtResource("7_pgi81")] +[node name="HBoxContainer" type="HBoxContainer" parent="."] layout_mode = 2 +size_flags_vertical = 0 +mouse_filter = 2 + +[node name="DraggablePanel" parent="HBoxContainer" instance=ExtResource("7_pgi81")] +layout_mode = 2 +size_flags_horizontal = 3 + +[node name="Control" type="Control" parent="HBoxContainer"] +custom_minimum_size = Vector2(28, 0) +layout_mode = 2 +mouse_filter = 2 [connection signal="pressed" from="HeaderContainer/HBoxContainer/MinimizeButton" to="." method="OnMinimizeButtonPressed"] [connection signal="pressed" from="HeaderContainer/HBoxContainer/CloseButton" to="." method="OnCloseButtonPressed"] -[connection signal="OnDraggablePanelInput" from="DraggablePanel" to="." method="OnDraggablePanelInput"] diff --git a/src/Visualizer/visualizer.tscn b/src/Visualizer/visualizer.tscn index c67ce46..77730ed 100644 --- a/src/Visualizer/visualizer.tscn +++ b/src/Visualizer/visualizer.tscn @@ -121,4 +121,3 @@ layout_mode = 2 [connection signal="pressed" from="HeaderContainer/HBoxContainer/MinimizeButton" to="." method="OnMinimizeButtonPressed"] [connection signal="pressed" from="HeaderContainer/HBoxContainer/CloseButton" to="." method="OnCloseButtonPressed"] -[connection signal="OnDraggablePanelInput" from="DraggablePanel" to="." method="OnDraggablePanelInput"]