diff --git a/RGB.NET.Brushes/Gradients/AbstractGradient.cs b/RGB.NET.Brushes/Gradients/AbstractGradient.cs index b4dc152..3ed396b 100644 --- a/RGB.NET.Brushes/Gradients/AbstractGradient.cs +++ b/RGB.NET.Brushes/Gradients/AbstractGradient.cs @@ -82,6 +82,22 @@ namespace RGB.NET.Brushes.Gradients /// public abstract Color GetColor(double offset); + /// + 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 } } diff --git a/RGB.NET.Brushes/Gradients/IGradient.cs b/RGB.NET.Brushes/Gradients/IGradient.cs index e8ffebc..2f30fb8 100644 --- a/RGB.NET.Brushes/Gradients/IGradient.cs +++ b/RGB.NET.Brushes/Gradients/IGradient.cs @@ -13,5 +13,11 @@ namespace RGB.NET.Brushes.Gradients /// The percentage offset to take the from. /// The at the specific offset. Color GetColor(double offset); + + /// + /// Moves the by the provided offset. + /// + /// The offset the should be moved. + void Move(double offset); } } diff --git a/RGB.NET.Brushes/Gradients/RainbowGradient.cs b/RGB.NET.Brushes/Gradients/RainbowGradient.cs index 66deb4b..a35591c 100644 --- a/RGB.NET.Brushes/Gradients/RainbowGradient.cs +++ b/RGB.NET.Brushes/Gradients/RainbowGradient.cs @@ -56,6 +56,27 @@ namespace RGB.NET.Brushes.Gradients return new Color(hue, 1f, 1f); } + /// + 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 } } diff --git a/RGB.NET.Effects/Effects/MoveGradientEffect.cs b/RGB.NET.Effects/Effects/MoveGradientEffect.cs index 92452e8..634a8fa 100644 --- a/RGB.NET.Effects/Effects/MoveGradientEffect.cs +++ b/RGB.NET.Effects/Effects/MoveGradientEffect.cs @@ -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