/// <summary> /// Plays the mouse leave animation to change the foreground and background colour /// of a windows forms control (or any object with fields BackColor and ForeColor). /// </summary> /// <param name="animProperties">The animation properties for this object.</param> /// <param name="control">The object itself (this)</param> /// <param name="e">From the regular event.</param> public static void AnimateMouseLeave(EventArgs e, object control, AnimProperties animProperties) { // If the override is none. if (animProperties.MouseEnterOverride == AnimOverrides.MouseEnterOverride.None) { if (control is IAnimatedControl animatedControl) { animatedControl.OnMouseEnterWrapper(e); } return; } // Else if the BackColor and/or ForeColor are to be interpolated. // Cancel old task & interpolate Animate colours respectively. if (animProperties.MouseLeaveOverride.HasFlag(AnimOverrides.MouseLeaveOverride.BackColorInterpolate)) { animProperties.BackColorMessage.PlayAnimation = false; animProperties.BackColorMessage = new AnimMessage(control); Task.Run(() => AnimAnimations.InterpolateBackcolor(animProperties.BackColorMessage, new AnimInterpolator(animProperties.MouseLeaveDuration, animProperties.MouseLeaveFramerate), animProperties.MouseLeaveBackColor)); } if (animProperties.MouseLeaveOverride.HasFlag(AnimOverrides.MouseLeaveOverride.ForeColorInterpolate)) { animProperties.ForeColorMessage.PlayAnimation = false; animProperties.ForeColorMessage = new AnimMessage(control); Task.Run(() => AnimAnimations.InterpolateForecolor(animProperties.ForeColorMessage, new AnimInterpolator(animProperties.MouseLeaveDuration, animProperties.MouseLeaveFramerate), animProperties.MouseLeaveForeColor)); } }
/// <summary> /// Plays the mouse enter animation to change the foreground and background colour /// of a windows forms control (or any object with fields BackColor and ForeColor). /// </summary> /// <param name="animProperties">The animation properties for this object.</param> /// <param name="control">The object itself (this)</param> /// <param name="e">From the regular event.</param> /// <param name="animMessageBackground">The individual message for the background interpolation action used to cancel ongoing animations if necessary.</param> /// <param name="animMessageForeground">The individual message for the foreground interpolation action used to cancel ongoing animations if necessary.</param> /// <param name="sourceColor">The colour from which the mouse leave animation begins from (source colour).</param> public static (AnimMessage, AnimMessage) AnimateMouseEnter(EventArgs e, object control, AnimProperties animProperties, AnimMessage animMessageBackground, AnimMessage animMessageForeground, Color sourceColor) { // If the override is none. if (animProperties.MouseEnterOverride == AnimOverrides.MouseEnterOverride.None) { if (control is IAnimatedControl animatedControl) { animatedControl.OnMouseEnterWrapper(e); } return(new AnimMessage(), new AnimMessage()); } // Else if the BackColor and/or ForeColor are to be interpolated. // Cancel old task & interpolate Animate colours respectively. if (animProperties.MouseEnterOverride.HasFlag(AnimOverrides.MouseEnterOverride.BackColorInterpolate)) { animMessageBackground.PlayAnimation = false; animMessageBackground = new AnimMessage(control); Task.Run(() => AnimAnimations.InterpolateBackcolor(animMessageBackground, new AnimInterpolator(animProperties.MouseEnterDuration, animProperties.MouseEnterFramerate), sourceColor, animProperties.MouseEnterBackColor)); } if (animProperties.MouseEnterOverride.HasFlag(AnimOverrides.MouseEnterOverride.ForeColorInterpolate)) { animMessageForeground.PlayAnimation = false; animMessageForeground = new AnimMessage(control); Task.Run(() => AnimAnimations.InterpolateForecolor(animMessageForeground, new AnimInterpolator(animProperties.MouseEnterDuration, animProperties.MouseEnterFramerate), sourceColor, animProperties.MouseEnterForeColor)); } return(animMessageBackground, animMessageForeground); }