Add new UIBrush that uses UIBrushAsset json resource with a brush data
This commit is contained in:
@@ -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)),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
75
Source/Engine/UI/GUI/Brushes/UIBrush.cs
Normal file
75
Source/Engine/UI/GUI/Brushes/UIBrush.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
// Copyright (c) Wojciech Figat. All rights reserved.
|
||||
|
||||
namespace FlaxEngine.GUI
|
||||
{
|
||||
/// <summary>
|
||||
/// Asset with <see cref="IBrush"/> that can be reused in different UI controls.
|
||||
/// </summary>
|
||||
/// <seealso cref="IBrush" />
|
||||
/// <seealso cref="UIBrush" />
|
||||
public class UIBrushAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// Brush object.
|
||||
/// </summary>
|
||||
public IBrush Brush;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Implementation of <see cref="IBrush"/> for <see cref="FlaxEngine.VideoPlayer"/> frame displaying.
|
||||
/// </summary>
|
||||
/// <seealso cref="IBrush" />
|
||||
/// <seealso cref="UIBrushAsset" />
|
||||
public sealed class UIBrush : IBrush
|
||||
{
|
||||
/// <summary>
|
||||
/// The UI Brush asset to use.
|
||||
/// </summary>
|
||||
public JsonAssetReference<UIBrushAsset> Asset;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UIBrush"/> class.
|
||||
/// </summary>
|
||||
public UIBrush()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UIBrush"/> struct.
|
||||
/// </summary>
|
||||
/// <param name="asset">The UI Brush asset to use.</param>
|
||||
public UIBrush(JsonAssetReference<UIBrushAsset> asset)
|
||||
{
|
||||
Asset = asset;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UIBrush"/> struct.
|
||||
/// </summary>
|
||||
/// <param name="asset">The UI Brush asset to use.</param>
|
||||
public UIBrush(JsonAsset asset)
|
||||
{
|
||||
Asset = asset;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Float2 Size
|
||||
{
|
||||
get
|
||||
{
|
||||
var asset = (UIBrushAsset)Asset.Asset?.Instance;
|
||||
if (asset != null && asset.Brush != null)
|
||||
return asset.Brush.Size;
|
||||
return Float2.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Draw(Rectangle rect, Color color)
|
||||
{
|
||||
var asset = (UIBrushAsset)Asset.Asset?.Instance;
|
||||
if (asset != null && asset.Brush != null)
|
||||
asset.Brush.Draw(rect, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user