You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.6 KiB
38 lines
1.6 KiB
using Colore; |
|
using Colore.Data; |
|
using Colore.Effects.Keyboard; |
|
using System; |
|
|
|
namespace ChromaController |
|
{ |
|
internal class FadeKey : KeyEffect |
|
{ |
|
public float StepPercentage { get; } |
|
|
|
/// <summary> |
|
/// Fades from <paramref name="color1"/> to <paramref name="color2"/> in the specified time |
|
/// </summary> |
|
/// <param name="keys">The <see cref="Colore.Effects.Keyboard.Key"/> that will have the fade effect</param> |
|
/// <param name="color1">The startcolor</param> |
|
/// <param name="color2">The endcolor</param> |
|
/// <param name="stepPercentage">Must be between 0 and 1. Each step, the transition will be incremented by this amount</param> |
|
public FadeKey(Key[] keys, Color color1, Color color2, float stepPercentage = 0.1F, int delayTime = 0) : base(keys, color1, color2, delayTime) |
|
{ |
|
if (stepPercentage <= 0 || stepPercentage > 1) throw new ArgumentException("argument should be between 0 and 1", "stepPercentage"); |
|
StepPercentage = stepPercentage; |
|
} |
|
|
|
public override bool Step(IChroma chroma) |
|
{ |
|
bool baseResult = base.Step(chroma); |
|
if (StepCounter <= DelayTime) return baseResult; |
|
if ((StepPercentage * (StepCounter - DelayTime)) > 1) |
|
{ |
|
chroma.Keyboard.SetKeysAsync(Keys, Color2, false); |
|
return true; |
|
} |
|
chroma.Keyboard.SetKeysAsync(Keys, ColorMixer(Color1, Color2, StepPercentage * (StepCounter - DelayTime)), clear: false); |
|
return baseResult; |
|
} |
|
} |
|
} |