From 5a05038a9b6fd0a5e1227d21185809633ffda750 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Tue, 24 Jun 2025 13:08:25 +0200 Subject: [PATCH] Add new `UIBrush` that uses `UIBrushAsset` json resource with a brush data --- .../CustomEditors/Editors/IBrushEditor.cs | 1 + Source/Engine/UI/GUI/Brushes/UIBrush.cs | 75 +++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 Source/Engine/UI/GUI/Brushes/UIBrush.cs diff --git a/Source/Editor/CustomEditors/Editors/IBrushEditor.cs b/Source/Editor/CustomEditors/Editors/IBrushEditor.cs index b32f58923..ce5207414 100644 --- a/Source/Editor/CustomEditors/Editors/IBrushEditor.cs +++ b/Source/Editor/CustomEditors/Editors/IBrushEditor.cs @@ -26,6 +26,7 @@ namespace FlaxEditor.CustomEditors.Editors new OptionType("Texture 9-Slicing", typeof(Texture9SlicingBrush)), new OptionType("Sprite 9-Slicing", typeof(Sprite9SlicingBrush)), new OptionType("Video", typeof(VideoBrush)), + new OptionType("UI Brush", typeof(UIBrush)), }; } } diff --git a/Source/Engine/UI/GUI/Brushes/UIBrush.cs b/Source/Engine/UI/GUI/Brushes/UIBrush.cs new file mode 100644 index 000000000..4441899c0 --- /dev/null +++ b/Source/Engine/UI/GUI/Brushes/UIBrush.cs @@ -0,0 +1,75 @@ +// Copyright (c) Wojciech Figat. All rights reserved. + +namespace FlaxEngine.GUI +{ + /// + /// Asset with that can be reused in different UI controls. + /// + /// + /// + public class UIBrushAsset + { + /// + /// Brush object. + /// + public IBrush Brush; + } + + /// + /// Implementation of for frame displaying. + /// + /// + /// + public sealed class UIBrush : IBrush + { + /// + /// The UI Brush asset to use. + /// + public JsonAssetReference Asset; + + /// + /// Initializes a new instance of the class. + /// + public UIBrush() + { + } + + /// + /// Initializes a new instance of the struct. + /// + /// The UI Brush asset to use. + public UIBrush(JsonAssetReference asset) + { + Asset = asset; + } + + /// + /// Initializes a new instance of the struct. + /// + /// The UI Brush asset to use. + public UIBrush(JsonAsset asset) + { + Asset = asset; + } + + /// + public Float2 Size + { + get + { + var asset = (UIBrushAsset)Asset.Asset?.Instance; + if (asset != null && asset.Brush != null) + return asset.Brush.Size; + return Float2.Zero; + } + } + + /// + public void Draw(Rectangle rect, Color color) + { + var asset = (UIBrushAsset)Asset.Asset?.Instance; + if (asset != null && asset.Brush != null) + asset.Brush.Draw(rect, color); + } + } +}