From 60482059a426f0d82bc7b42d2df7ac6903836ed4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20L=C3=BCbe=C3=9F?= Date: Tue, 17 Jun 2025 16:46:05 +0200 Subject: [PATCH] Test handle Windows Explorer drag'n'drop in ImGui --- .../src/EditWindows/ContentBrowserWindow.bf | 19 +++++++++ GlitchyEditor/src/EditorLayer.bf | 42 ++++++++++++++++--- GlitchyEditor/src/ImGuiExtension.bf | 3 ++ GlitchyEngine/src/ImGui/ImGuiLayer.bf | 2 +- 4 files changed, 60 insertions(+), 6 deletions(-) diff --git a/GlitchyEditor/src/EditWindows/ContentBrowserWindow.bf b/GlitchyEditor/src/EditWindows/ContentBrowserWindow.bf index b9cd06f..53bb485 100644 --- a/GlitchyEditor/src/EditWindows/ContentBrowserWindow.bf +++ b/GlitchyEditor/src/EditWindows/ContentBrowserWindow.bf @@ -187,6 +187,25 @@ namespace GlitchyEditor.EditWindows } ImGui.EndTable(); + + if (ImGui.BeginDragDropTarget()) + { + ImGui.Payload* peekPayload = ImGui.AcceptDragDropPayload(.ExternFiles, .AcceptBeforeDelivery); + + if (peekPayload != null) + { + if (peekPayload.IsDelivery()) + { + Log.EngineLogger.Info("Buup!"); + } + else + { + EditorLayer.SetDropEffect(.Copy); + } + } + + ImGui.EndDragDropTarget(); + } } ImGui.PopStyleVar(1); diff --git a/GlitchyEditor/src/EditorLayer.bf b/GlitchyEditor/src/EditorLayer.bf index d0babcb..a214953 100644 --- a/GlitchyEditor/src/EditorLayer.bf +++ b/GlitchyEditor/src/EditorLayer.bf @@ -135,7 +135,7 @@ namespace GlitchyEditor public override Result OnDragLeave() { - DragDropEvent event = scope DragDropEvent(.Over, .(-1, -1)); + DragDropEvent event = scope DragDropEvent(.Leave, .(-1, -1)); Application.Instance.OnEvent(event); return .Ok; } @@ -149,7 +149,7 @@ namespace GlitchyEditor } private GlobalDragDropTarget _dragDropTarget ~ _?.ReleaseRef(); - + [AllowAppend] public this(String[] args, EditorContentManager contentManager) : base("Editor") { @@ -157,6 +157,9 @@ namespace GlitchyEditor ScriptEngine.ApplicationInfo.IsEditor = true; + // TODO: Das muss weg + _layer = this; + _dragDropTarget = new .(); _dragDropTarget.Register(); @@ -1201,6 +1204,17 @@ namespace GlitchyEditor ImGui.Viewport* viewport = ImGui.GetMainViewport(); ImGui.DockSpaceOverViewport(viewport); + if (_isDraggingFromOutside) + { + SetDropEffect(.None); + + if (ImGui.BeginDragDropSource(.SourceExtern | .SourceAutoExpirePayload)) + { + ImGui.SetDragDropPayload(.ExternFiles, null, 0); + ImGui.EndDragDropSource(); + } + } + DrawMainMenuBar(); #if GE_EDITOR_IMGUI_DEMO @@ -1657,23 +1671,41 @@ namespace GlitchyEditor } private bool _isDraggingFromOutside; - private bool _droppedFromOutside; private DropEffect _effectWhenDropping = .None; + private static EditorLayer _layer; + + public static void SetDropEffect(DropEffect effect) + { + if (!_layer._isDraggingFromOutside) + { + Log.EngineLogger.Warning("Setting drop effect, eventhou the user is currently not dragging."); + } + + _layer._effectWhenDropping = effect; + } + private bool OnDragDrop(DragDropEvent e) { Log.EngineLogger.Info($"D'n'D: {e.DragDropType} {e.CursorPosition.X} {e.CursorPosition.Y}"); + if (all(e.CursorPosition != .(-1,-1))) + { + ImGui.GetIO().MousePos = .(e.CursorPosition.X, e.CursorPosition.Y); + } + switch (e.DragDropType) { case .Enter: _isDraggingFromOutside = true; - _droppedFromOutside = false; + ImGui.GetIO().MouseDown[0] = true; case .Over: case .Leave: _isDraggingFromOutside = false; + ImGui.ClearDragDrop(); case .Drop: - _droppedFromOutside = true; + _isDraggingFromOutside = false; + ImGui.GetIO().MouseDown[0] = false; } e.OutDropEffect = _effectWhenDropping; diff --git a/GlitchyEditor/src/ImGuiExtension.bf b/GlitchyEditor/src/ImGuiExtension.bf index 668a427..3a3ef6e 100644 --- a/GlitchyEditor/src/ImGuiExtension.bf +++ b/GlitchyEditor/src/ImGuiExtension.bf @@ -6,6 +6,7 @@ enum DragDropPayloadType { case ContentBrowserItem; case Entity; + case ExternFiles; public String GetName() { @@ -15,6 +16,8 @@ enum DragDropPayloadType return "CONTENT_BROWSER_ITEM"; case .Entity: return "ENTITY"; + case .ExternFiles: + return "EXTERN_FILES"; } } } diff --git a/GlitchyEngine/src/ImGui/ImGuiLayer.bf b/GlitchyEngine/src/ImGui/ImGuiLayer.bf index 847536b..51dbde4 100644 --- a/GlitchyEngine/src/ImGui/ImGuiLayer.bf +++ b/GlitchyEngine/src/ImGui/ImGuiLayer.bf @@ -220,7 +220,7 @@ namespace GlitchyEngine.ImGui Debug.Profiler.ProfileScope!("ImGuiRenderEvent"); var event = scope ImGuiRenderEvent(); - Application.Get().OnEvent(event); + Application.Instance.OnEvent(event); } End();