From bc1f466d18ad98aa00a354c5d8e76c985076d3c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20L=C3=BCbe=C3=9F?= Date: Sat, 13 Aug 2022 13:47:58 +0200 Subject: [PATCH] Drag drop Texture --- .../src/EditWindows/ComponentEditWindow.bf | 23 ++++++++++++++++++- .../src/EditWindows/ContentBrowserWindow.bf | 6 ++++- GlitchyEngine/src/Content/ContentManager.bf | 4 +++- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/GlitchyEditor/src/EditWindows/ComponentEditWindow.bf b/GlitchyEditor/src/EditWindows/ComponentEditWindow.bf index b00f508..a7898a5 100644 --- a/GlitchyEditor/src/EditWindows/ComponentEditWindow.bf +++ b/GlitchyEditor/src/EditWindows/ComponentEditWindow.bf @@ -299,7 +299,28 @@ namespace GlitchyEditor.EditWindows for (let texture in effect.Textures) { - ImGui.Text(texture.key); + //ImGui.Text(texture.key); + ImGui.Button(texture.key); + + if (ImGui.BeginDragDropTarget()) + { + ImGui.Payload* payload = ImGui.AcceptDragDropPayload("CONTENT_BROWSER_ITEM"); + + if (payload != null) + { + Log.EngineLogger.Warning(""); + + StringView path = .((char8*)payload.Data, (int)payload.DataSize); + + using (Texture2D newTexture = new Texture2D(path, true)) + { + newTexture.SamplerState = SamplerStateManager.AnisotropicWrap; + material.SetTexture(texture.key, newTexture); + } + } + + ImGui.EndDragDropTarget(); + } } for (let (name, arguments) in effect.[Friend]_variableDescriptions) diff --git a/GlitchyEditor/src/EditWindows/ContentBrowserWindow.bf b/GlitchyEditor/src/EditWindows/ContentBrowserWindow.bf index 7be59de..d34b3ce 100644 --- a/GlitchyEditor/src/EditWindows/ContentBrowserWindow.bf +++ b/GlitchyEditor/src/EditWindows/ContentBrowserWindow.bf @@ -242,7 +242,11 @@ namespace GlitchyEditor.EditWindows if (ImGui.BeginDragDropSource()) { String fullpath = scope $"{_currentDirectory}{Path.DirectorySeparatorChar}{entry.Name}"; - + + // TODO: this is dirty + if (fullpath.StartsWith(ContentDirectory, .OrdinalIgnoreCase)) + fullpath.Remove(0, ContentDirectory.Length); + ImGui.SetDragDropPayload("CONTENT_BROWSER_ITEM", fullpath.CStr(), (.)fullpath.Length, .Once); ImGui.EndDragDropSource(); diff --git a/GlitchyEngine/src/Content/ContentManager.bf b/GlitchyEngine/src/Content/ContentManager.bf index 624d4dd..f0f9f73 100644 --- a/GlitchyEngine/src/Content/ContentManager.bf +++ b/GlitchyEngine/src/Content/ContentManager.bf @@ -47,12 +47,14 @@ namespace GlitchyEngine.Content { Path.InternalCombine(outFilename, _contentRoot, filename); } - + public Stream GetFile(String filename) { String fullpath = scope .(_contentRoot.Length + 1 + filename.Length); GetFilePath(fullpath, filename); + Log.EngineLogger.AssertDebug(File.Exists(fullpath), "File doesn't exist!"); + FileStream stream = new FileStream(); var result = stream.Open(fullpath, .Read, .Read);