// ReSharper disable MemberCanBeProtected.Global
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable AutoPropertyCanBeMadeGetOnly.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();
///
/// Gets or sets if the Gradient wraps around if there isn't a second stop to take.
/// Example: There is a stop at offset 0f, 0.5f and 0.75f.
/// Without wrapping offset 1f will be calculated the same as 0.75f. With wrapping it would be the same as 0f.
///
public bool WrapGradient { get; set; }
#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);
}
///
/// Initializes a new instance of the class.
///
/// Specifies whether the gradient should wrapp or not (see for an example of what this means).
/// The stops with which the gradient should be initialized.
protected AbstractGradient(bool wrapGradient, params GradientStop[] gradientStops)
{
this.WrapGradient = wrapGradient;
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);
return offset < min ? min : 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
}
}