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.

43 lines
1.6 KiB

using Colore;
using Colore.Data;
using Colore.Effects.Keyboard;
using System;
namespace ChromaController
{
internal class FlashKey : KeyEffect
{
public float FlashTime { get; }
/// <summary>
/// Flashes key with specified color for specified time.
/// </summary>
/// <param name="keys">The <see cref="Colore.Effects.Keyboard.Key"/> that will flash</param>
/// <param name="color1">The startcolor</param>
/// <param name="color2">The endcolor</param>
/// <param name="flashTime">The amount of steps that <paramref name="color1"/> will be shown</param>
public FlashKey(Key[] keys, Color color1, Color color2, int flashTime, int delayTime = 0) : base(keys, color1, color2, delayTime)
{
if (flashTime <= 0) throw new ArgumentException("argument should be between 0 and 1", "stepPercentage");
FlashTime = flashTime;
}
public FlashKey(Key key, Color color1, Color color2, int flashTime, int delayTime = 0)
: this(new Key[] { key }, color1, color2, flashTime, delayTime)
{
}
public override bool Step(IChroma chroma)
{
bool baseResult = base.Step(chroma);
if (StepCounter <= DelayTime) return baseResult;
if (StepCounter > FlashTime + DelayTime)
{
chroma.Keyboard.SetKeysAsync(Keys, Color2, false);
return true;
}
chroma.Keyboard.SetKeysAsync(Keys, Color1, false);
return baseResult;
}
}
}