63
Source/Editor/CustomEditors/Dedicated/GPUTextureEditor.cs
Normal file
63
Source/Editor/CustomEditors/Dedicated/GPUTextureEditor.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
// Copyright (c) Wojciech Figat. All rights reserved.
|
||||
|
||||
using FlaxEditor.GUI.ContextMenu;
|
||||
using FlaxEngine;
|
||||
using FlaxEngine.GUI;
|
||||
|
||||
namespace FlaxEditor.CustomEditors.Dedicated
|
||||
{
|
||||
/// <summary>
|
||||
/// Basic editor/viewer for <see cref="GPUTexture"/>.
|
||||
/// </summary>
|
||||
[CustomEditor(typeof(GPUTexture)), DefaultEditor]
|
||||
public class GPUTextureEditor : CustomEditor
|
||||
{
|
||||
private Image _image;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override DisplayStyle Style => DisplayStyle.Inline;
|
||||
|
||||
/// <inheritdoc />
|
||||
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);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
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";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// basic custom property editor for GPUTexture
|
||||
/// </summary>
|
||||
[CustomEditor(typeof(GPUTexture))]
|
||||
public class GPUTexturePropertyEditor : GenericEditor
|
||||
{
|
||||
public override DisplayStyle Style => DisplayStyle.Inline;
|
||||
|
||||
ImageElement imageElement;
|
||||
GroupElement group;
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="layout"></param>
|
||||
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();
|
||||
}
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
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
|
||||
Reference in New Issue
Block a user