mirror of
https://github.com/DarthAffe/CUE.NET.git
synced 2025-12-12 08:48:30 +00:00
Implemented Gradient-Wrapping
This commit is contained in:
parent
da15638817
commit
55dff06380
@ -1,4 +1,6 @@
|
||||
// ReSharper disable MemberCanBeProtected.Global
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
// ReSharper disable AutoPropertyCanBeMadeGetOnly.Global
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -18,6 +20,13 @@ namespace CUE.NET.Gradients
|
||||
/// </summary>
|
||||
public IList<GradientStop> GradientStops { get; } = new List<GradientStop>();
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
public bool WrapGradient { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
@ -38,6 +47,19 @@ namespace CUE.NET.Gradients
|
||||
GradientStops.Add(gradientStop);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AbstractGradient"/> class.
|
||||
/// </summary>
|
||||
/// <param name="wrapGradient">Specifies whether the gradient should wrapp or not (see <see cref="WrapGradient"/> for an example of what this means).</param>
|
||||
/// <param name="gradientStops">The stops with which the gradient should be initialized.</param>
|
||||
protected AbstractGradient(bool wrapGradient, params GradientStop[] gradientStops)
|
||||
{
|
||||
this.WrapGradient = wrapGradient;
|
||||
|
||||
foreach (GradientStop gradientStop in gradientStops)
|
||||
GradientStops.Add(gradientStop);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
@ -26,6 +26,15 @@ namespace CUE.NET.Gradients
|
||||
: base(gradientStops)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AbstractGradient"/> class.
|
||||
/// </summary>
|
||||
/// <param name="wrapGradient">Specifies whether the gradient should wrapp or not (see <see cref="AbstractGradient.WrapGradient"/> for an example of what this means).</param>
|
||||
/// <param name="gradientStops">The stops with which the gradient should be initialized.</param>
|
||||
public LinearGradient(bool wrapGradient, params GradientStop[] gradientStops)
|
||||
: base(wrapGradient, gradientStops)
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
@ -40,10 +49,32 @@ namespace CUE.NET.Gradients
|
||||
if (!GradientStops.Any()) return CorsairColor.Transparent;
|
||||
if (GradientStops.Count == 1) return GradientStops.First().Color;
|
||||
|
||||
offset = ClipOffset(offset);
|
||||
GradientStop gsBefore;
|
||||
GradientStop gsAfter;
|
||||
|
||||
GradientStop gsBefore = GradientStops.Where(n => n.Offset <= offset).OrderBy(n => n.Offset).Last();
|
||||
GradientStop gsAfter = GradientStops.Where(n => n.Offset >= offset).OrderBy(n => n.Offset).First();
|
||||
if (WrapGradient)
|
||||
{
|
||||
gsBefore = GradientStops.Where(n => n.Offset <= offset).OrderBy(n => n.Offset).LastOrDefault();
|
||||
if (gsBefore == null)
|
||||
{
|
||||
GradientStop lastStop = GradientStops.OrderBy(n => n.Offset).Last();
|
||||
gsBefore = new GradientStop(lastStop.Offset - 1f, lastStop.Color);
|
||||
}
|
||||
|
||||
gsAfter = GradientStops.Where(n => n.Offset >= offset).OrderBy(n => n.Offset).FirstOrDefault();
|
||||
if (gsAfter == null)
|
||||
{
|
||||
GradientStop firstStop = GradientStops.OrderBy(n => n.Offset).First();
|
||||
gsAfter = new GradientStop(firstStop.Offset + 1f, firstStop.Color);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
offset = ClipOffset(offset);
|
||||
|
||||
gsBefore = GradientStops.Where(n => n.Offset <= offset).OrderBy(n => n.Offset).Last();
|
||||
gsAfter = GradientStops.Where(n => n.Offset >= offset).OrderBy(n => n.Offset).First();
|
||||
}
|
||||
|
||||
float blendFactor = 0f;
|
||||
if (!gsBefore.Offset.Equals(gsAfter.Offset))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user