// Copyright (c) Wojciech Figat. All rights reserved.
namespace FlaxEngine.GUI
{
///
/// Implementation of for frame displaying.
///
///
public sealed class VideoBrush : IBrush
{
///
/// The video player to display frame from it.
///
public VideoPlayer Player;
///
/// The texture sampling filter mode.
///
[ExpandGroups]
public BrushFilter Filter = BrushFilter.Linear;
///
/// Initializes a new instance of the class.
///
public VideoBrush()
{
}
///
/// Initializes a new instance of the struct.
///
/// The video player to preview.
public VideoBrush(VideoPlayer player)
{
Player = player;
}
///
public Float2 Size
{
get
{
if (Player && Player.Size.LengthSquared > 0)
return (Float2)Player.Size;
return new Float2(1920, 1080);
}
}
///
public void Draw(Rectangle rect, Color color)
{
var texture = Player?.Frame;
if (texture == null || !texture.IsAllocated)
texture = GPUDevice.Instance.DefaultBlackTexture;
if (Filter == BrushFilter.Point)
Render2D.DrawTexturePoint(texture, rect, color);
else
Render2D.DrawTexture(texture, rect, color);
}
}
}