Add option to use Point sampling when drawing textures and sprites in UI via Brushes

This commit is contained in:
Wojtek Figat
2021-05-19 19:48:39 +02:00
parent 1a55e7c734
commit 62cca0682c
4 changed files with 52 additions and 5 deletions

View File

@@ -14,6 +14,12 @@ namespace FlaxEngine.GUI
[HideInEditor]
public GPUTexture Texture;
/// <summary>
/// The texture sampling filter mode.
/// </summary>
[ExpandGroups, Tooltip("The texture sampling filter mode.")]
public BrushFilter Filter = BrushFilter.Linear;
/// <summary>
/// Initializes a new instance of the <see cref="GPUTextureBrush"/> class.
/// </summary>
@@ -36,7 +42,10 @@ namespace FlaxEngine.GUI
/// <inheritdoc />
public void Draw(Rectangle rect, Color color)
{
Render2D.DrawTexture(Texture, rect, color);
if (Filter == BrushFilter.Point)
Render2D.DrawTexturePoint(Texture, rect, color);
else
Render2D.DrawTexture(Texture, rect, color);
}
}
}

View File

@@ -2,6 +2,24 @@
namespace FlaxEngine.GUI
{
/// <summary>
/// Texture brush sampling modes.
/// </summary>
public enum BrushFilter
{
/// <summary>
/// The point sampling without blending.
/// </summary>
[Tooltip("The point sampling without blending.")]
Point = 0,
/// <summary>
/// The linear color sampling.
/// </summary>
[Tooltip("The linear color sampling.")]
Linear = 1,
};
/// <summary>
/// Interface that unifies input source textures, sprites, render targets, and any other brushes to be used in a more generic way.
/// </summary>

View File

@@ -11,9 +11,15 @@ namespace FlaxEngine.GUI
/// <summary>
/// The sprite.
/// </summary>
[ExpandGroups]
[ExpandGroups, EditorOrder(0), Tooltip("The sprite.")]
public SpriteHandle Sprite;
/// <summary>
/// The texture sampling filter mode.
/// </summary>
[ExpandGroups, EditorOrder(1), Tooltip("The texture sampling filter mode.")]
public BrushFilter Filter = BrushFilter.Linear;
/// <summary>
/// Initializes a new instance of the <see cref="SpriteBrush"/> class.
/// </summary>
@@ -36,7 +42,10 @@ namespace FlaxEngine.GUI
/// <inheritdoc />
public void Draw(Rectangle rect, Color color)
{
Render2D.DrawSprite(Sprite, rect, color);
if (Filter == BrushFilter.Point)
Render2D.DrawSpritePoint(Sprite, rect, color);
else
Render2D.DrawSprite(Sprite, rect, color);
}
}
}

View File

@@ -1,5 +1,7 @@
// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
using System;
namespace FlaxEngine.GUI
{
/// <summary>
@@ -11,9 +13,15 @@ namespace FlaxEngine.GUI
/// <summary>
/// The texture.
/// </summary>
[ExpandGroups, Tooltip("The texture asset.")]
[ExpandGroups, EditorOrder(0), Tooltip("The texture asset.")]
public Texture Texture;
/// <summary>
/// The texture sampling filter mode.
/// </summary>
[ExpandGroups, EditorOrder(1), Tooltip("The texture sampling filter mode.")]
public BrushFilter Filter = BrushFilter.Linear;
/// <summary>
/// Initializes a new instance of the <see cref="TextureBrush"/> class.
/// </summary>
@@ -36,7 +44,10 @@ namespace FlaxEngine.GUI
/// <inheritdoc />
public void Draw(Rectangle rect, Color color)
{
Render2D.DrawTexture(Texture, rect, color);
if (Filter == BrushFilter.Point)
Render2D.DrawTexturePoint(Texture?.Texture, rect, color);
else
Render2D.DrawTexture(Texture, rect, color);
}
}
}