private void SetCurrentCumulativeModifier(IAnimationClock animationClock) { if (IsCumulative) { double factor = animationClock.CurrentIteration.GetValueOrDefault() - 1; if (factor > 0d) { T toFromDistance = SubtractValues(_actualTo, _actualFrom); _cumulativeModifier = ScaleValue(toFromDistance, factor); _useCumulativeModifier = true; } } }
/// <summary> /// Returns the current value of the animation. /// </summary> /// <param name="defaultOriginValue"> /// The origin value provided to the animation if the animation does not have its /// own start value. If this animation is the first in a composition chain it will /// be the base value of the property being animated; otherwise it will be the value /// returned by the previous animation in the chain. /// </param> /// <param name="defaultDestinationValue"> /// The destination value provided to the animation if the animation does not have /// its own destination value. /// </param> /// <param name="animationClock"> /// A non-specific <see cref="IAnimationClock"/> which can generate the <see cref="IClock.CurrentTime"/> /// or <see cref="IClock.CurrentProgress"/> value to be used by the /// animation to generate its output value. /// </param> /// <returns>The value this animation believes should be the current value for the property.</returns> public virtual T GetCurrentValue( object defaultOriginValue, object defaultDestinationValue, IAnimationClock animationClock) { ReadPreamble(); if (animationClock == null) { throw new ArgumentNullException(nameof(animationClock)); } if (!(defaultOriginValue is T) && !(defaultOriginValue is null)) { ThrowForInvalidAnimationValueType(nameof(defaultOriginValue)); } if (!(defaultDestinationValue is T) && !(defaultDestinationValue is null)) { ThrowForInvalidAnimationValueType(nameof(defaultDestinationValue)); } return(GetCurrentValueCore( (T)defaultOriginValue, (T)defaultDestinationValue, animationClock)); }
protected override double GetCurrentValueCore( double from, double to, IAnimationClock animationClock) { double progress = animationClock.CurrentProgress.Value; // Perform a very simple animation. // Return a scaled value between from and to, depending on the current progress. if (progress == 0) { return(from); } else if (progress == 1) { return(to); } else { return(from + (to - from) * progress); } }
private void SetDynamicAnimationValues(T defaultOrigin, T defaultDestination, IAnimationClock animationClock) { SetActualFromAndTo(defaultOrigin, defaultDestination); SetCurrentAdditiveModifier(defaultOrigin); SetCurrentCumulativeModifier(animationClock); }
/// <summary> /// Returns the value which represents the current value of the animation. /// </summary> /// <param name="defaultOriginValue"> /// The suggested origin value, used if <see cref="From"/> is not set. /// </param> /// <param name="defaultDestinationValue"> /// The suggested origin value, used if <see cref="To"/> is not set. /// </param> /// <param name="animationClock"> /// The <see cref="IAnimationClock"/> to be used by the animation to generate its output value. /// </param> /// <returns>The value which this animation believes to be the current one.</returns> protected override T GetCurrentValueCore(T defaultOriginValue, T defaultDestinationValue, IAnimationClock animationClock) { SetConstantAnimationValues(); SetDynamicAnimationValues(defaultOriginValue, defaultDestinationValue, animationClock); ValidateAnimationValues(_actualFrom, _actualTo); double progress = animationClock.CurrentProgress.Value; T interpolatedValue; interpolatedValue = InterpolateValue(_actualFrom, _actualTo, progress); if (_useCumulativeModifier) { interpolatedValue = AddValues(interpolatedValue, _cumulativeModifier); } if (_useAdditiveModifier) { interpolatedValue = AddValues(interpolatedValue, _additiveModifier); } return(interpolatedValue); }
/// <summary> /// Calculates a value that represents the current value of the property being animated, /// as determined by the host animation. /// </summary> /// <param name="defaultOriginValue"> /// The suggested origin value, used if the animation /// does not have its own explicitly set start value. /// </param> /// <param name="defaultDestinationValue"> /// The suggested destination value, used if the animation /// does not have its own explicitly set end value. /// </param> /// <param name="animationClock"> /// An <see cref="IAnimationClock"/> which can generate the <see cref="IClock.CurrentTime"/> /// or <see cref="IClock.CurrentProgress"/> value to be used by the /// animation to generate its output value. /// </param> /// <returns>The value this animation believes should be the current value for the property.</returns> protected abstract T GetCurrentValueCore( T defaultOriginValue, T defaultDestinationValue, IAnimationClock animationClock);