Improved gradient-movement

This commit is contained in:
DarthAffe committed 2017-05-13 07:46:00 +02:00
1 parent 026b7e7d14
commit 1345b50a8f
4 files changed
+44 -38

No files matched your search

@@ -82,6 +82,22 @@ namespace RGB.NET.Brushes.Gradients
/// <inheritdoc />
public abstract Color GetColor(double offset);
/// <inheritdoc />
public virtual void Move(double offset)
{
offset /= 360.0;
foreach (GradientStop gradientStop in GradientStops)
{
gradientStop.Offset = gradientStop.Offset + offset;
if (gradientStop.Offset > 1)
gradientStop.Offset -= 1;
else if (gradientStop.Offset < 0)
gradientStop.Offset += 1;
}
}
#endregion
}
}
+6
View File
@@ -13,5 +13,11 @@ namespace RGB.NET.Brushes.Gradients
/// <param name="offset">The percentage offset to take the <see cref="Color"/> from.</param>
/// <returns>The <see cref="Color"/> at the specific offset.</returns>
Color GetColor(double offset);
/// <summary>
/// Moves the <see cref="IGradient"/> by the provided offset.
/// </summary>
/// <param name="offset">The offset the <see cref="IGradient"/> should be moved.</param>
void Move(double offset);
}
}
@@ -56,6 +56,27 @@ namespace RGB.NET.Brushes.Gradients
return new Color(hue, 1f, 1f);
}
/// <inheritdoc />
public void Move(double offset)
{
// RainbowGradient is calculated inverse
offset *= -1;
StartHue += offset;
EndHue += offset;
if ((StartHue > 360) && (EndHue > 360))
{
StartHue -= 360;
EndHue -= 360;
}
else if ((StartHue < -360) && (EndHue < -360))
{
StartHue += 360;
EndHue += 360;
}
}
#endregion
}
}