From 56077a268abaac7b80afeb17cc1bf34e4066f652 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Tue, 16 Sep 2025 00:15:48 +0200 Subject: [PATCH] SImplify and cleanup GPUTexture editor #3452 #3194 --- .../Dedicated/GPUTextureEditor.cs | 63 ++++++++++ Source/Editor/GUI/GPUTextureEditor.cs | 112 ------------------ 2 files changed, 63 insertions(+), 112 deletions(-) create mode 100644 Source/Editor/CustomEditors/Dedicated/GPUTextureEditor.cs delete mode 100644 Source/Editor/GUI/GPUTextureEditor.cs diff --git a/Source/Editor/CustomEditors/Dedicated/GPUTextureEditor.cs b/Source/Editor/CustomEditors/Dedicated/GPUTextureEditor.cs new file mode 100644 index 000000000..9df7ca377 --- /dev/null +++ b/Source/Editor/CustomEditors/Dedicated/GPUTextureEditor.cs @@ -0,0 +1,63 @@ +// Copyright (c) Wojciech Figat. All rights reserved. + +using FlaxEditor.GUI.ContextMenu; +using FlaxEngine; +using FlaxEngine.GUI; + +namespace FlaxEditor.CustomEditors.Dedicated +{ + /// + /// Basic editor/viewer for . + /// + [CustomEditor(typeof(GPUTexture)), DefaultEditor] + public class GPUTextureEditor : CustomEditor + { + private Image _image; + + /// + public override DisplayStyle Style => DisplayStyle.Inline; + + /// + public override void Initialize(LayoutElementsContainer layout) + { + _image = new Image + { + Brush = new GPUTextureBrush(), + Size = new Float2(200, 100), + Parent = layout.ContainerControl, + }; + _image.Clicked += OnImageClicked; + } + + private void OnImageClicked(Image image, MouseButton button) + { + var texture = Values[0] as GPUTexture; + if (!texture) + return; + var menu = new ContextMenu(); + menu.AddButton("Save...", () => Screenshot.Capture(Values[0] as GPUTexture)); + menu.AddButton("Enlarge", () => _image.Size *= 2); + menu.AddButton("Shrink", () => _image.Size /= 2).Enabled = _image.Height > 32; + var location = image.PointFromScreen(Input.MouseScreenPosition); + menu.Show(image, location); + } + + /// + public override void Refresh() + { + base.Refresh(); + + var texture = Values[0] as GPUTexture; + ((GPUTextureBrush)_image.Brush).Texture = texture; + if (texture) + { + var desc = texture.Description; + _image.TooltipText = $"{texture.Name}\nType: {texture.ResourceType}\nSize: {desc.Width}x{desc.Height}\nFormat: {desc.Format}\nMemory: {Utilities.Utils.FormatBytesCount(texture.MemoryUsage)}"; + } + else + { + _image.TooltipText = "None"; + } + } + } +} diff --git a/Source/Editor/GUI/GPUTextureEditor.cs b/Source/Editor/GUI/GPUTextureEditor.cs deleted file mode 100644 index 5dd672941..000000000 --- a/Source/Editor/GUI/GPUTextureEditor.cs +++ /dev/null @@ -1,112 +0,0 @@ -#if FLAX_EDITOR -using FlaxEditor.CustomEditors; -using FlaxEditor.CustomEditors.Editors; -using FlaxEditor.CustomEditors.Elements; -using FlaxEditor.GUI.ContextMenu; -using FlaxEditor.Scripting; -using FlaxEditor.Tools.Foliage; -using FlaxEngine; -using FlaxEngine.GUI; -using FlaxEngine.Utilities; - -namespace FlaxEditor.GUI -{ - /// - /// basic custom property editor for GPUTexture - /// - [CustomEditor(typeof(GPUTexture))] - public class GPUTexturePropertyEditor : GenericEditor - { - public override DisplayStyle Style => DisplayStyle.Inline; - - ImageElement imageElement; - GroupElement group; - /// - /// - /// - public override void Initialize(LayoutElementsContainer layout) - { - imageElement = (group = layout.Group("")).Image(SpriteHandle.Default); - - //todo fix the AddSettingsButton func - //shit is buged - //the code below (until the Paint) is untested the Clear might not work - group.AddSettingsButton(); - group.SetupContextMenu += (ContextMenu.ContextMenu cxm, DropPanel dp) => - { - cxm.AddButton("Clear", (ContextMenuButton bt) => - { - SetValue(null); - }); - - cxm.AddSeparator(); - - //todo - //editor is needed - //cxm.AddButton("Display Full Texture", (ContextMenuButton bt) => - //{ - //}); - - //todo - // - //cxm.AddButton("Save To Asset", (ContextMenuButton bt) => - //{ - //}); - }; - Paint(); - group.Panel.Close(); - } - /// - /// - public override void Refresh() - { - Paint(); - base.Refresh(); - } - private void Paint() - { - string name = null; - string tt = null; - if (Values[0] is GPUTexture gputex) - { - name = gputex.Name; - tt += "Type: " + gputex.ResourceType.ToString() + "\n"; - tt += "Memory Usage: " + gputex.MemoryUsage + "B" + "\n"; - tt += "Format: " + gputex.Format.ToString() + "\n"; - //shorten the name it is a full path - if (name.EndsWith(".flax")) - { - if (name != ".flax")//sanity guard - { - var nameStartIndexWithEx = Globals.ProjectFolder.Length + 9 /* +9 to remove the "/Content/" */; - name = name.Substring - ( - nameStartIndexWithEx, - nameStartIndexWithEx - 5 /* -5 to remove the .flax */ + 2 - ); - - tt += "Path: " + gputex.Name.Remove(0, Globals.ProjectFolder.Length + 1); - } - } - - if (imageElement.Image.Brush is GPUTextureBrush brush) - { - brush.Texture = gputex; - imageElement.Control.Size = new Float2(group.Control.Width); - } - else - { - imageElement.Image.Brush = new GPUTextureBrush(); - Paint(); - } - } - name ??= "..."; - - DropPanel p = group.Control as DropPanel; - - p.HeaderText = name; - p.TooltipText = tt; - } - } -} -#endif