using Colore; using Colore.Data; using Colore.Effects.Keyboard; using System; namespace ChromaController { internal class FadeKey : KeyEffect { public float StepPercentage { get; } /// /// Fades from to in the specified time /// /// The that will have the fade effect /// The startcolor /// The endcolor /// Must be between 0 and 1. Each step, the transition will be incremented by this amount 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; } } }