mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-13 01:58:30 +00:00
Improved gradient-movement
This commit is contained in:
parent
026b7e7d14
commit
1345b50a8f
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@ -56,44 +56,7 @@ namespace RGB.NET.Effects
|
||||
if (!Direction)
|
||||
movement = -movement;
|
||||
|
||||
// ReSharper disable once CanBeReplacedWithTryCastAndCheckForNull
|
||||
if (Brush.Gradient is LinearGradient)
|
||||
{
|
||||
LinearGradient linearGradient = (LinearGradient)Brush.Gradient;
|
||||
|
||||
movement /= 360.0;
|
||||
|
||||
foreach (GradientStop gradientStop in linearGradient.GradientStops)
|
||||
{
|
||||
gradientStop.Offset = gradientStop.Offset + movement;
|
||||
|
||||
if (gradientStop.Offset > 1)
|
||||
gradientStop.Offset -= 1;
|
||||
else if (gradientStop.Offset < 0)
|
||||
gradientStop.Offset += 1;
|
||||
}
|
||||
}
|
||||
else if (Brush.Gradient is RainbowGradient)
|
||||
{
|
||||
RainbowGradient rainbowGradient = (RainbowGradient)Brush.Gradient;
|
||||
|
||||
// RainbowGradient is calculated inverse but the movement should be the same for all.
|
||||
movement *= -1;
|
||||
|
||||
rainbowGradient.StartHue += movement;
|
||||
rainbowGradient.EndHue += movement;
|
||||
|
||||
if ((rainbowGradient.StartHue > 360) && (rainbowGradient.EndHue > 360))
|
||||
{
|
||||
rainbowGradient.StartHue -= 360;
|
||||
rainbowGradient.EndHue -= 360;
|
||||
}
|
||||
else if ((rainbowGradient.StartHue < -360) && (rainbowGradient.EndHue < -360))
|
||||
{
|
||||
rainbowGradient.StartHue += 360;
|
||||
rainbowGradient.EndHue += 360;
|
||||
}
|
||||
}
|
||||
Brush?.Gradient?.Move(movement);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user