mirror of
https://github.com/DarthAffe/CUE.NET.git
synced 2025-12-12 16:58:29 +00:00
Added new brush-effect to move gradients
This commit is contained in:
parent
55dff06380
commit
9a9bf52fe9
@ -74,6 +74,7 @@
|
||||
<Compile Include="Devices\Mousemat\CorsairMousemat.cs" />
|
||||
<Compile Include="Devices\Mousemat\CorsairMousematDeviceInfo.cs" />
|
||||
<Compile Include="Devices\Mousemat\Enums\CorsairMousematLedId.cs" />
|
||||
<Compile Include="Effects\MoveGradientEffect.cs" />
|
||||
<Compile Include="Gradients\AbstractGradient.cs" />
|
||||
<Compile Include="Gradients\GradientStop.cs" />
|
||||
<Compile Include="Gradients\IGradient.cs" />
|
||||
|
||||
97
Effects/MoveGradientEffect.cs
Normal file
97
Effects/MoveGradientEffect.cs
Normal file
@ -0,0 +1,97 @@
|
||||
using CUE.NET.Brushes;
|
||||
using CUE.NET.Gradients;
|
||||
|
||||
namespace CUE.NET.Effects
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents an effect which allows to move an gradient by modifying his offset.
|
||||
/// </summary>
|
||||
public class MoveGradientEffect : AbstractBrushEffect<IGradientBrush>
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the direction the gradient is moved.
|
||||
/// True leads to an offset-increment (normaly moving to the right), false to an offset-decrement (normaly moving to the left).
|
||||
/// </summary>
|
||||
public bool Direction { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the speed of the movement in units per second.
|
||||
/// The meaning of units differs for the different gradients, but 360 units will always be one complete cycle:
|
||||
/// LinearGradient: 360 unit = 1 offset.
|
||||
/// RainbowGradient: 1 unit = 1 degree.
|
||||
/// </summary>
|
||||
public float Speed { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="speed"></param>
|
||||
/// <param name="direction"></param>
|
||||
public MoveGradientEffect(float speed = 180f, bool direction = true)
|
||||
{
|
||||
this.Speed = speed;
|
||||
this.Direction = direction;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
/// <summary>
|
||||
/// Updates the effect.
|
||||
/// </summary>
|
||||
/// <param name="deltaTime">The elapsed time (in seconds) since the last update.</param>
|
||||
public override void Update(float deltaTime)
|
||||
{
|
||||
float movement = Speed * deltaTime;
|
||||
|
||||
if (!Direction)
|
||||
movement = -movement;
|
||||
|
||||
if (Brush.Gradient is LinearGradient)
|
||||
{
|
||||
LinearGradient linearGradient = (LinearGradient)Brush.Gradient;
|
||||
|
||||
movement /= 360f;
|
||||
|
||||
foreach (GradientStop gradientStop in linearGradient.GradientStops)
|
||||
{
|
||||
gradientStop.Offset = gradientStop.Offset + movement;
|
||||
|
||||
if (gradientStop.Offset > 1f)
|
||||
gradientStop.Offset -= 1f;
|
||||
else if (gradientStop.Offset < 0)
|
||||
gradientStop.Offset += 1f;
|
||||
}
|
||||
}
|
||||
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 > 360f && rainbowGradient.EndHue > 360f)
|
||||
{
|
||||
rainbowGradient.StartHue -= 360f;
|
||||
rainbowGradient.EndHue -= 360f;
|
||||
}
|
||||
else if (rainbowGradient.StartHue < -360f && rainbowGradient.EndHue < -360f)
|
||||
{
|
||||
rainbowGradient.StartHue += 360f;
|
||||
rainbowGradient.EndHue += 360f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user