mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
Test handle Windows Explorer drag'n'drop in ImGui
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,7 +220,7 @@ namespace GlitchyEngine.ImGui
|
||||
Debug.Profiler.ProfileScope!("ImGuiRenderEvent");
|
||||
|
||||
var event = scope ImGuiRenderEvent();
|
||||
Application.Get().OnEvent(event);
|
||||
Application.Instance.OnEvent(event);
|
||||
}
|
||||
|
||||
End();
|
||||
|
||||
Reference in New Issue
Block a user