// Copyright (c) Wojciech Figat. All rights reserved. using System; namespace FlaxEngine.GUI { /// /// Implementation of for linear color gradient (made of 2 color). /// /// public sealed class LinearGradientBrush : IBrush, IEquatable { /// /// The brush start color. /// [EditorOrder(0), ExpandGroups, Tooltip("The brush start color.")] public Color StartColor; /// /// The brush end color. /// [EditorOrder(1), Tooltip("The brush end color.")] public Color EndColor; /// /// Initializes a new instance of the class. /// public LinearGradientBrush() { StartColor = Color.White; EndColor = Color.Black; } /// /// Initializes a new instance of the struct. /// /// The start color. /// The end color. public LinearGradientBrush(Color startColor, Color endColor) { StartColor = startColor; EndColor = endColor; } /// public Float2 Size => Float2.One; /// public void Draw(Rectangle rect, Color color) { var startColor = StartColor * color; var endColor = EndColor * color; Render2D.FillRectangle(rect, startColor, startColor, endColor, endColor); } /// public bool Equals(LinearGradientBrush other) { return other != null && StartColor == other.StartColor && EndColor == other.EndColor; } /// public override bool Equals(object obj) { return obj is LinearGradientBrush other && Equals(other); } /// public override int GetHashCode() { return HashCode.Combine(StartColor, EndColor); } /// public int CompareTo(object obj) { return Equals(obj) ? 1 : 0; } } }