mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-13 10:08:31 +00:00
Improved gradient-movement
This commit is contained in:
parent
026b7e7d14
commit
1345b50a8f
@ -82,6 +82,22 @@ namespace RGB.NET.Brushes.Gradients
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public abstract Color GetColor(double offset);
|
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
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,5 +13,11 @@ namespace RGB.NET.Brushes.Gradients
|
|||||||
/// <param name="offset">The percentage offset to take the <see cref="Color"/> from.</param>
|
/// <param name="offset">The percentage offset to take the <see cref="Color"/> from.</param>
|
||||||
/// <returns>The <see cref="Color"/> at the specific offset.</returns>
|
/// <returns>The <see cref="Color"/> at the specific offset.</returns>
|
||||||
Color GetColor(double offset);
|
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);
|
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
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -56,44 +56,7 @@ namespace RGB.NET.Effects
|
|||||||
if (!Direction)
|
if (!Direction)
|
||||||
movement = -movement;
|
movement = -movement;
|
||||||
|
|
||||||
// ReSharper disable once CanBeReplacedWithTryCastAndCheckForNull
|
Brush?.Gradient?.Move(movement);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user