public override object GetCurrentValue(object defaultOriginValue, object defaultDestinationValue, AnimationTimelineClock animationClock) { if (KeyFrames.Count == 0) { return(defaultDestinationValue); } TimeSpan duration = Duration.HasTimeSpan ? Duration.TimeSpan : GetKeyFramesDuration(); TimeSpan time = duration.Scale(animationClock.CurrentState.Progress); int index = GetKeyFrameIndexAtTime(time, duration); double?value; if (index == KeyFrames.Count) { value = KeyFrames[KeyFrames.Count - 1].Value; } else { double?baseValue; if (index == 0) { baseValue = IsAdditive && isAccumulable ? animationOperations.Zero : (double?)defaultOriginValue; } else { baseValue = KeyFrames[index - 1].Value; } TimeSpan segmentStart = index == 0 ? TimeSpan.Zero : GetKeyFrameTime(KeyFrames[index - 1], duration); TimeSpan segmentEnd = GetKeyFrameTime(KeyFrames[index], duration); double progress = segmentEnd == segmentStart ? 1 : (double)(time - segmentStart).Ticks / (segmentEnd - segmentStart).Ticks; value = KeyFrames[index].InterpolateValue(baseValue, progress); } if (IsAdditive && isAccumulable) { value = animationOperations.Add(value, (double?)defaultOriginValue); } if (IsCumulative && isAccumulable) { value = animationOperations.Add(value, animationOperations.Scale(KeyFrames[KeyFrames.Count - 1].Value, Math.Floor(animationClock.CurrentState.Iteration))); } return(value); }
public override object GetCurrentValue(object defaultOriginValue, object defaultDestinationValue, AnimationTimelineClock animationClock) { double progress = EasingFunction != null?EasingFunction.Ease(animationClock.CurrentState.Progress) : animationClock.CurrentState.Progress; double?baseValue = animationOperations.Zero; double?from; double?to; if (this.From != null) { if (this.To != null) { if (IsAdditive && isAccumulable) { baseValue = (double?)defaultOriginValue; } from = this.From; to = this.To; } else if (this.By != null) { if (IsAdditive && isAccumulable) { baseValue = (double?)defaultOriginValue; } from = this.From; to = animationOperations.Add(this.From, this.By); } else { from = this.From; to = (double?)defaultDestinationValue; } } else if (this.To != null) { from = (double?)defaultOriginValue; to = this.To; } else if (this.By != null) { if (isAccumulable) { baseValue = (double?)defaultOriginValue; } from = animationOperations.Zero; to = this.By; } else { from = (double?)defaultOriginValue; to = (double?)defaultDestinationValue; } if (IsCumulative && isAccumulable) { baseValue = animationOperations.Add(baseValue, animationOperations.Scale(animationOperations.Subtract(to, from), Math.Floor(animationClock.CurrentState.Iteration))); } return(animationOperations.Add(baseValue, animationOperations.Interpolate(from, to, progress))); }