// Copyright (c) Wojciech Figat. All rights reserved. using System; namespace FlaxEngine.GUI { /// /// Implementation of for frame displaying. /// /// public sealed class VideoBrush : IBrush, IEquatable { /// /// 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); } /// public bool Equals(VideoBrush other) { return other != null && Player == other.Player && Filter == other.Filter; } /// public override bool Equals(object obj) { return obj is VideoBrush other && Equals(other); } /// public override int GetHashCode() { return HashCode.Combine(Player, (int)Filter); } /// public int CompareTo(object obj) { return Equals(obj) ? 1 : 0; } } }