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();
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);
+37 -5
View File
@@ -135,7 +135,7 @@ namespace GlitchyEditor
public override Result<void> 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;
+3
View File
@@ -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";
}
}
}
+1 -1
View File
@@ -220,7 +220,7 @@ namespace GlitchyEngine.ImGui
Debug.Profiler.ProfileScope!("ImGuiRenderEvent");
var event = scope ImGuiRenderEvent();
Application.Get().OnEvent(event);
Application.Instance.OnEvent(event);
}
End();