From ed4d5a53972d7ef6898b7788eed25016c6af990a Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Sun, 12 Jan 2025 22:15:38 +0200 Subject: [PATCH] _drag release offset investigation --- Source/Editor/GUI/Docking/DockHintWindow.cs | 9 ++- Source/Engine/Platform/SDL/SDLInput.cpp | 10 ++- .../Engine/Platform/SDL/SDLPlatform.Linux.cpp | 13 ++-- Source/Engine/Platform/SDL/SDLWindow.cpp | 62 ++++++++++--------- 4 files changed, 54 insertions(+), 40 deletions(-) diff --git a/Source/Editor/GUI/Docking/DockHintWindow.cs b/Source/Editor/GUI/Docking/DockHintWindow.cs index 95c89d34f..ea2703e15 100644 --- a/Source/Editor/GUI/Docking/DockHintWindow.cs +++ b/Source/Editor/GUI/Docking/DockHintWindow.cs @@ -342,7 +342,7 @@ namespace FlaxEditor.GUI.Docking if (dockPanel != _toDock) { - //Editor.Log($"UpdateRects: {_mouse}, panel: {dockPanel?.RootWindow?.Window?.Title}"); + Editor.Log($"UpdateRects: {_mouse}, panel: {dockPanel?.RootWindow?.Window?.Title}"); _toDock?.RootWindow.Window.RemoveDockHints(); RemoveDockHints(); @@ -422,8 +422,8 @@ namespace FlaxEditor.GUI.Docking hoveredSizeOverride = new Float2(size.X, size.Y); } - if (toSet != DockState.Float) - Editor.Log($"docking: {toSet}"); + //if (toSet != DockState.Float) + _toSet = toSet; } @@ -431,6 +431,8 @@ namespace FlaxEditor.GUI.Docking { _toSet = DockState.Float; } + + Editor.Log($"docking: {_toSet}, pos: {_mouse}"); // Calculate proxy/dock/window rectangles if (_toDock == null) @@ -524,6 +526,7 @@ namespace FlaxEditor.GUI.Docking var mousePos = Platform.MousePosition; if (_mouse != mousePos) { + Editor.Log($"mouse pos {_mouse} -> {mousePos}"); OnMouseMove(mousePos); } } diff --git a/Source/Engine/Platform/SDL/SDLInput.cpp b/Source/Engine/Platform/SDL/SDLInput.cpp index 5a87fdee6..d4fd45bfc 100644 --- a/Source/Engine/Platform/SDL/SDLInput.cpp +++ b/Source/Engine/Platform/SDL/SDLInput.cpp @@ -1,5 +1,6 @@ // Copyright (c) 2012-2024 Wojciech Figat. All rights reserved. +#include "Engine/Engine/Engine.h" #if PLATFORM_SDL #include "SDLInput.h" @@ -496,14 +497,17 @@ bool SDLInput::HandleEvent(SDLWindow* window, SDL_Event& event) } return true; } - case SDL_EVENT_DROP_POSITION: + /*case SDL_EVENT_DROP_POSITION: { // We are not receiving mouse motion events during drag-and-drop auto dpiScale = window->GetDpiScale(); - const Float2 mousePos = window->ClientToScreen({ event.drop.x * dpiScale, event.drop.y * dpiScale}); + //const Float2 mousePos(event.drop.x * dpiScale, event.drop.y * dpiScale);// = window->ClientToScreen({ event.drop.x * dpiScale, event.drop.y * dpiScale}); + Float2 mousePos = window->ClientToScreen({ event.drop.x * dpiScale, event.drop.y * dpiScale}); + if (window != Engine::MainWindow) + mousePos = window->GetPosition() - mousePos; Input::Mouse->OnMouseMove(mousePos, window); return true; - } + }*/ case SDL_EVENT_WINDOW_MOUSE_LEAVE: { Input::Mouse->OnMouseLeave(window); diff --git a/Source/Engine/Platform/SDL/SDLPlatform.Linux.cpp b/Source/Engine/Platform/SDL/SDLPlatform.Linux.cpp index cf33de7eb..f44bc6753 100644 --- a/Source/Engine/Platform/SDL/SDLPlatform.Linux.cpp +++ b/Source/Engine/Platform/SDL/SDLPlatform.Linux.cpp @@ -499,8 +499,8 @@ void WaylandDataSource_Cancelled(void* data, wl_data_source *source) wl_data_source_destroy(source); // The mouse up event was ignored earlier, release the button now - SDLWindow* window = ((LinuxDropTextData*)inputData)->Window; - Input::Mouse->OnMouseUp(Platform::GetMousePosition(), MouseButton::Left, window); + //SDLWindow* window = ((LinuxDropTextData*)inputData)->Window; + //Input::Mouse->OnMouseUp(Platform::GetMousePosition(), MouseButton::Left, window); /*if (DragTargetWindow != nullptr) { @@ -517,7 +517,7 @@ void WaylandDataSource_DnDDropPerformed(void *data, { // The destination is being asked to begin DnD, asking confirmation with ASK actionh //SDLWindow* window = static_cast(data); - //LOG(Info, "WaylandDataSource_DnDDropPerformed"); + LOG(Info, "WaylandDataSource_DnDDropPerformed"); } void WaylandDataSource_DnDFinished(void *data, @@ -533,8 +533,8 @@ void WaylandDataSource_DnDFinished(void *data, wl_data_source_destroy(wl_data_source); // The mouse up event was ignored earlier, release the button now - SDLWindow* window = ((LinuxDropTextData*)inputData)->Window; - Input::Mouse->OnMouseUp(Platform::GetMousePosition(), MouseButton::Left, window); + //SDLWindow* window = ((LinuxDropTextData*)inputData)->Window; + //Input::Mouse->OnMouseUp(Platform::GetMousePosition(), MouseButton::Left, window); /*if (DragTargetWindow != nullptr) { @@ -886,6 +886,9 @@ DragDropEffect Window::DoDragDropWayland(const StringView& data, Window* dragSou } } + // The mouse up event was ignored earlier, release the button now + Input::Mouse->OnMouseUp(Platform::GetMousePosition(), MouseButton::Left, this); + Platform::AtomicStore(&task->ExitFlag, 1); task->Wait(); diff --git a/Source/Engine/Platform/SDL/SDLWindow.cpp b/Source/Engine/Platform/SDL/SDLWindow.cpp index 543dc3639..52439450e 100644 --- a/Source/Engine/Platform/SDL/SDLWindow.cpp +++ b/Source/Engine/Platform/SDL/SDLWindow.cpp @@ -640,16 +640,41 @@ void SDLWindow::HandleEvent(SDL_Event& event) return; } case SDL_EVENT_DROP_BEGIN: + case SDL_EVENT_DROP_POSITION: + case SDL_EVENT_DROP_FILE: + case SDL_EVENT_DROP_TEXT: + case SDL_EVENT_DROP_COMPLETE: { - LOG(Info, "SDL_EVENT_DROP_BEGIN"); + //LOG(Info, "SDL_EVENT_DROP_BEGIN"); + + static Float2 dragStartPosition = Float2::Zero; auto dpiScale = GetDpiScale(); - const Float2 mousePos = ClientToScreen({ event.drop.x * dpiScale, event.drop.y * dpiScale}); + //const Float2 mousePos = ClientToScreen({ event.drop.x * dpiScale, event.drop.y * dpiScale}); + const Float2 mousePos = dragStartPosition + Float2(event.drop.x * dpiScale, event.drop.y * dpiScale); DragDropEffect effect = DragDropEffect::None; auto daata = event.drop.data; SDLDropTextData dropData; - OnDragEnter(&dropData, mousePos, effect); + + + + if (event.type == SDL_EVENT_DROP_BEGIN) + { + dragStartPosition = Platform::GetMousePosition(); + OnDragEnter(&dropData, mousePos, effect); + } + else if (event.type == SDL_EVENT_DROP_POSITION) + { + Input::Mouse->OnMouseMove(mousePos, this); + OnDragOver(&dropData, mousePos, effect); + } + else if (event.type == SDL_EVENT_DROP_FILE) + OnDragDrop(&dropData, mousePos, effect); + else if (event.type == SDL_EVENT_DROP_TEXT) + OnDragDrop(&dropData, mousePos, effect); + else if (event.type == SDL_EVENT_DROP_COMPLETE) + OnDragLeave(); /*Focus(); Float2 mousePosition; SDL_GetGlobalMouseState(&mousePosition.X, &mousePosition.Y); @@ -659,21 +684,19 @@ void SDLWindow::HandleEvent(SDL_Event& event) SDLDropTextData dropData; OnDragEnter(&dropData, mousePosition, effect); OnDragOver(&dropData, mousePosition, effect);*/ - return; + break; } - case SDL_EVENT_DROP_POSITION: + /*case SDL_EVENT_DROP_POSITION: { auto dpiScale = GetDpiScale(); - const Float2 mousePos = ClientToScreen({ event.drop.x * dpiScale, event.drop.y * dpiScale}); + //const Float2 mousePos = ClientToScreen({ event.drop.x * dpiScale, event.drop.y * dpiScale}); + const Float2 mousePos(event.drop.x * dpiScale, event.drop.y * dpiScale); DragDropEffect effect = DragDropEffect::None; auto daata = event.drop.data; SDLDropTextData dropData; OnDragOver(&dropData, mousePos, effect); - /*DragDropEffect effect = DragDropEffect::None; - SDLDropTextData dropData; - OnDragOver(&dropData, Float2(static_cast(event.drop.x), static_cast(event.drop.y)), effect);*/ break; } case SDL_EVENT_DROP_FILE: @@ -688,16 +711,7 @@ void SDLWindow::HandleEvent(SDL_Event& event) OnDragDrop(&dropData, mousePos, effect); - /*SDLDropFilesData dropData; - dropData.Files.Add(StringAnsi(event.drop.data).ToString()); // TODO: collect multiple files at once? - Focus(); - - Float2 mousePosition; - SDL_GetGlobalMouseState(&mousePosition.X, &mousePosition.Y); - mousePosition = ScreenToClient(mousePosition); - DragDropEffect effect = DragDropEffect::None; - OnDragDrop(&dropData, mousePosition, effect);*/ return; } case SDL_EVENT_DROP_TEXT: @@ -713,16 +727,6 @@ void SDLWindow::HandleEvent(SDL_Event& event) SDLDropTextData dropData; OnDragDrop(&dropData, mousePos, effect); - /*SDLDropTextData dropData; - String str = StringAnsi(event.drop.data).ToString(); - dropData.Text = StringView(str); - - Focus(); - Float2 mousePosition; - SDL_GetGlobalMouseState(&mousePosition.X, &mousePosition.Y); - mousePosition = ScreenToClient(mousePosition); - DragDropEffect effect = DragDropEffect::None; - OnDragDrop(&dropData, mousePosition, effect);*/ return; } case SDL_EVENT_DROP_COMPLETE: @@ -740,7 +744,7 @@ void SDLWindow::HandleEvent(SDL_Event& event) //_dragOver = false; } return; - } + }*/ #endif case SDL_EVENT_WINDOW_MOUSE_LEAVE: {