Test handle Windows Explorer drag'n'drop in ImGui

This commit is contained in:
Simon Lübeß
2025-06-17 16:46:05 +02:00
parent 9b6bb2b8d8
commit 60482059a4
4 changed files with 60 additions and 6 deletions
@@ -187,6 +187,25 @@ namespace GlitchyEditor.EditWindows
} }
ImGui.EndTable(); 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); ImGui.PopStyleVar(1);
+36 -4
View File
@@ -135,7 +135,7 @@ namespace GlitchyEditor
public override Result<void> OnDragLeave() public override Result<void> OnDragLeave()
{ {
DragDropEvent event = scope DragDropEvent(.Over, .(-1, -1)); DragDropEvent event = scope DragDropEvent(.Leave, .(-1, -1));
Application.Instance.OnEvent(event); Application.Instance.OnEvent(event);
return .Ok; return .Ok;
} }
@@ -157,6 +157,9 @@ namespace GlitchyEditor
ScriptEngine.ApplicationInfo.IsEditor = true; ScriptEngine.ApplicationInfo.IsEditor = true;
// TODO: Das muss weg
_layer = this;
_dragDropTarget = new .(); _dragDropTarget = new .();
_dragDropTarget.Register(); _dragDropTarget.Register();
@@ -1201,6 +1204,17 @@ namespace GlitchyEditor
ImGui.Viewport* viewport = ImGui.GetMainViewport(); ImGui.Viewport* viewport = ImGui.GetMainViewport();
ImGui.DockSpaceOverViewport(viewport); ImGui.DockSpaceOverViewport(viewport);
if (_isDraggingFromOutside)
{
SetDropEffect(.None);
if (ImGui.BeginDragDropSource(.SourceExtern | .SourceAutoExpirePayload))
{
ImGui.SetDragDropPayload(.ExternFiles, null, 0);
ImGui.EndDragDropSource();
}
}
DrawMainMenuBar(); DrawMainMenuBar();
#if GE_EDITOR_IMGUI_DEMO #if GE_EDITOR_IMGUI_DEMO
@@ -1657,23 +1671,41 @@ namespace GlitchyEditor
} }
private bool _isDraggingFromOutside; private bool _isDraggingFromOutside;
private bool _droppedFromOutside;
private DropEffect _effectWhenDropping = .None; 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) private bool OnDragDrop(DragDropEvent e)
{ {
Log.EngineLogger.Info($"D'n'D: {e.DragDropType} {e.CursorPosition.X} {e.CursorPosition.Y}"); 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) switch (e.DragDropType)
{ {
case .Enter: case .Enter:
_isDraggingFromOutside = true; _isDraggingFromOutside = true;
_droppedFromOutside = false; ImGui.GetIO().MouseDown[0] = true;
case .Over: case .Over:
case .Leave: case .Leave:
_isDraggingFromOutside = false; _isDraggingFromOutside = false;
ImGui.ClearDragDrop();
case .Drop: case .Drop:
_droppedFromOutside = true; _isDraggingFromOutside = false;
ImGui.GetIO().MouseDown[0] = false;
} }
e.OutDropEffect = _effectWhenDropping; e.OutDropEffect = _effectWhenDropping;
+3
View File
@@ -6,6 +6,7 @@ enum DragDropPayloadType
{ {
case ContentBrowserItem; case ContentBrowserItem;
case Entity; case Entity;
case ExternFiles;
public String GetName() public String GetName()
{ {
@@ -15,6 +16,8 @@ enum DragDropPayloadType
return "CONTENT_BROWSER_ITEM"; return "CONTENT_BROWSER_ITEM";
case .Entity: case .Entity:
return "ENTITY"; return "ENTITY";
case .ExternFiles:
return "EXTERN_FILES";
} }
} }
} }
+1 -1
View File
@@ -220,7 +220,7 @@ namespace GlitchyEngine.ImGui
Debug.Profiler.ProfileScope!("ImGuiRenderEvent"); Debug.Profiler.ProfileScope!("ImGuiRenderEvent");
var event = scope ImGuiRenderEvent(); var event = scope ImGuiRenderEvent();
Application.Get().OnEvent(event); Application.Instance.OnEvent(event);
} }
End(); End();