// ReSharper disable MemberCanBeProtected.Global using System.Collections.Generic; using System.Linq; using CUE.NET.Devices.Generic; namespace CUE.NET.Gradients { /// /// Represents a basic gradient. /// public abstract class AbstractGradient : IGradient { #region Properties & Fields /// /// Gets a list of the stops used by this gradient. /// public IList GradientStops { get; } = new List(); #endregion #region Constructors /// /// Initializes a new instance of the class. /// protected AbstractGradient() { } /// /// Initializes a new instance of the class. /// /// The stops with which the gradient should be initialized. protected AbstractGradient(params GradientStop[] gradientStops) { foreach (GradientStop gradientStop in gradientStops) GradientStops.Add(gradientStop); } #endregion #region Methods /// /// Clips the offset and ensures, that it is inside the bounds of the stop list. /// /// /// protected float ClipOffset(float offset) { float max = GradientStops.Max(n => n.Offset); if (offset > max) return max; float min = GradientStops.Min(n => n.Offset); if (offset < min) return min; return offset; } /// /// Gets the color of the gradient on the specified offset. /// /// The percentage offset to take the color from. /// The color at the specific offset. public abstract CorsairColor GetColor(float offset); #endregion } }