public override object GetCurrentValue(object defaultOriginValue,
                                               object defaultDestinationValue, AnimationClock animationClock)
        {
            GridUnitType    fromUnitType = ((GridLength)GetValue(GridLengthAnimation.FromProperty)).GridUnitType;
            GridUnitType    toUnitType   = ((GridLength)GetValue(GridLengthAnimation.ToProperty)).GridUnitType;
            double          fromVal      = ((GridLength)GetValue(GridLengthAnimation.FromProperty)).Value;
            double          toVal        = ((GridLength)GetValue(GridLengthAnimation.ToProperty)).Value;
            IEasingFunction easer        = (IEasingFunction)GetValue(GridLengthAnimation.EasingFunctionProperty);

            if (fromVal > toVal)
            {
                if (easer == null)
                {
                    return(new GridLength((1 - animationClock.CurrentProgress.Value) * (fromVal - toVal) + toVal, fromUnitType));
                }
                else
                {
                    return(new GridLength((1 - easer.Ease(animationClock.CurrentProgress.Value)) * (fromVal - toVal) + toVal, fromUnitType));
                }
            }
            else
            {
                if (easer == null)
                {
                    return(new GridLength(animationClock.CurrentProgress.Value * (toVal - fromVal) + fromVal, toUnitType));
                }
                else
                {
                    return(new GridLength(easer.Ease(animationClock.CurrentProgress.Value) * (toVal - fromVal) + fromVal, toUnitType));
                }
            }
        }
        /// <summary>
        /// Apply easing function on each component of a ColorOffset
        /// </summary>
        public static ColorOffset Ease(this IEasingFunction easing, long frame, ColorOffset from, ColorOffset to, long duration)
        {
            var a = (int)easing.Ease(frame, from.A, to.A, duration);
            var r = (int)easing.Ease(frame, from.R, to.R, duration);
            var g = (int)easing.Ease(frame, from.G, to.G, duration);
            var b = (int)easing.Ease(frame, from.B, to.B, duration);

            return(ColorOffset.FromArgb(a, r, g, b));
        }
示例#3
0
        /// <summary>
        /// Animates the grid let set
        /// </summary>
        /// <param name="defaultOriginValue">The original value to animate</param>
        /// <param name="defaultDestinationValue">The final value</param>
        /// <param name="animationClock">The animation clock (timer)</param>
        /// <returns>Returns the new grid length to set</returns>
        public override object GetCurrentValue(object defaultOriginValue,
                                               object defaultDestinationValue, AnimationClock animationClock)
        {
            double fromVal = ((GridLength)GetValue(FromProperty)).Value;

            double toVal = ((GridLength)GetValue(ToProperty)).Value;

            //check that from was set from the caller
            //if (fromVal == 1)
            //  //set the from as the actual value
            //  fromVal = ((GridLength)defaultDestinationValue).Value;

            double progress = animationClock.CurrentProgress.Value;

            IEasingFunction easingFunction = EasingFunction;

            if (easingFunction != null)
            {
                progress = easingFunction.Ease(progress);
            }


            if (fromVal > toVal)
            {
                return(new GridLength((1 - progress) * (fromVal - toVal) + toVal, GridUnitType.Pixel));
            }

            return(new GridLength(progress * (toVal - fromVal) + fromVal, GridUnitType.Pixel));
        }
示例#4
0
        /// <summary>
        /// Precalculates the frame values.
        /// </summary>
        private void PrebuildFrames()
        {
            var frames = (FrameRate * _duration) / MillisecondsPerSecond;

            _numberOfFrames = (int)Math.Max(
                Math.Min(frames, MaxNumberOfFrames),
                MinNumberOfFrames);

            _animatedValues = new float[_numberOfFrames];

            var by            = _to - _from;          //how much to change the value
            var interpolation = by / _numberOfFrames; //step size

            for (int f = 0; f < _numberOfFrames; f++)
            {
                //Modifies the frame values of the animation depending on the easing function
                if (_easingFunction != null)
                {
                    _animatedValues[f] = (float)_easingFunction.Ease(f, _from, _to, _numberOfFrames);                    //frame value
                }
                else
                {
                    //Regular Linear Function
                    _animatedValues[f] = _from + (interpolation * f);                    //frame value
                }
            }
        }
示例#5
0
        protected override Color GetCurrentValueCore(Color defaultOriginValue, Color defaultDestinationValue, AnimationClock animationClock)
        {
            System.Diagnostics.Debug.Assert(animationClock.CurrentState != ClockState.Stopped);
            if (!_isAnimationFunctionValid)
            {
                ValidateAnimationFunction();
            }
            double          progress       = animationClock.CurrentProgress.Value;
            IEasingFunction easingFunction = EasingFunction;

            if (easingFunction != null)
            {
                progress = easingFunction.Ease(progress);
            }
            double fromVal = _keyvalues[0];
            double toVal   = _keyvalues[1];
            double target;

            if (fromVal > toVal)
            {
                target = (1 - progress) * (fromVal - toVal) + toVal;
            }
            else
            {
                target = (toVal - fromVal) * progress + fromVal;
            }
            Color originColor = OriginColor;

            if (target == 0)
            {
                return(originColor);
            }
            return(ColorEx.ChangeColorBrightness(originColor, target));
        }
        public override Vector2 Interpolate(Vector2 start, double keyframe)
        {
            if (keyframe <= 0.0)
            {
                return(start);
            }
            if (keyframe >= 1.0)
            {
                return(Value);
            }
            if (double.IsNaN(keyframe))
            {
                return(start);
            }

            IEasingFunction easingFunction = EasingFunction;

            if (easingFunction != null)
            {
                keyframe = easingFunction.Ease(keyframe);
            }

            double x = (start.X + ((Value.X - start.X) * keyframe));
            double y = (start.Y + ((Value.Y - start.Y) * keyframe));

            return(new Vector2((float)x, (float)y));
        }
        private static List <double> CalculateEaseValues(double range, int count, IEasingFunction easingFunction, double baseValue = 0d)
        {
            var items = new List <double>();

            var easePhase = 1d / count;

            for (var i = 0; i < count; i++)
            {
                var valueToEase = easePhase * i;
                var easeValue   = easingFunction.Ease(valueToEase);

                items.Add(baseValue + (easeValue * range));
            }

            return(items);
        }
        private static List<double> CalculateEaseValues(double range, int count, IEasingFunction easingFunction, double baseValue = 0d)
        {
            var items = new List<double>();

            var easePhase = 1d / count;

            for (var i = 0; i < count; i++)
            {
                var valueToEase = easePhase * i;
                var easeValue = easingFunction.Ease(valueToEase);

                items.Add(baseValue + (easeValue * range));
            }

            return items;
        }
示例#9
0
        /// <summary>
        /// Gets 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">
        /// The <see cref="AnimationClock"/> which can generate the Animation.Clock.CurrentTime or
        /// Animation.Clock.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 override object GetCurrentValue(
            object defaultOriginValue,
            object defaultDestinationValue,
            AnimationClock animationClock)
        {
            ReadPreamble();

            if (animationClock == null)
            {
                throw new ArgumentNullException("animationClock");
            }

            if (animationClock.CurrentState == ClockState.Stopped ||
                !animationClock.CurrentProgress.HasValue)
            {
                return(defaultOriginValue);
            }

            GradientBrush defaultOriginalBrush    = defaultOriginValue as GradientBrush;
            GradientBrush defaultDestinationBrush = defaultDestinationValue as GradientBrush;

            if (gradientBrush == null)
            {
                AnimationBrush = defaultDestinationBrush;
            }
            if (AnimationBrush == null)
            {
                return(defaultOriginValue);
            }

            double progress = animationClock.CurrentProgress.Value;

            IEasingFunction easingFunction = EasingFunction;

            if (easingFunction != null)
            {
                progress = easingFunction.Ease(progress);
            }

            if (!progress.IsBetween(0, 1))
            {
                return(defaultOriginValue);
            }

            return(GetCurrentValue(defaultOriginalBrush, defaultDestinationBrush, progress));
        }
示例#10
0
        internal override void DoAnimation(TimelineContext context, uint timepassed)
        {
            PropertyAnimationTimelineContext patc = (PropertyAnimationTimelineContext)context;

            if (patc.DataDescriptor == null)
            {
                return;
            }

            Color from = From ?? ConvertToColor(patc.StartValue);
            Color to   = To ?? (By.HasValue ? ColorConverter.FromArgb(
                                    from.A + By.Value.A,
                                    from.R + By.Value.R,
                                    from.G + By.Value.G,
                                    from.B + By.Value.B) : (Color)patc.OriginalValue);

            double duration = Duration.TotalMilliseconds;

            if (timepassed > duration)
            {
                patc.DataDescriptor.Value = to;
                return;
            }

            double progress = timepassed / duration;

            IEasingFunction easingFunction = EasingFunction;

            if (easingFunction != null)
            {
                progress = easingFunction.Ease(progress);
            }

            object value = Color.SmoothStep(from, to, (float)progress);

            if (TypeConverter.Convert(value, patc.DataDescriptor.DataType, out value))
            {
                patc.DataDescriptor.Value = value;
            }
            else
            {
                throw new InvalidCastException(string.Format("Cannot from {0} to {1}", value == null ? null : value.GetType(), patc.DataDescriptor.DataType));
            }
            patc.DataDescriptor.Value = value;
        }
示例#11
0
        /// <summary>Interpolates, according to the easing function used, between the previous key frame value and the value of the current key frame, using the supplied progress increment.</summary>
        /// <param name="baseValue"> The value to animate from.</param>
        /// <param name="keyFrameProgress"> A value between 0.0 and 1.0, inclusive, that specifies the percentage of time that has elapsed for this key frame.</param>
        /// <returns>The output value of this key frame given the specified base value and progress.</returns>
        // Token: 0x06001736 RID: 5942 RVA: 0x00071E80 File Offset: 0x00070080
        protected override Thickness InterpolateValueCore(Thickness baseValue, double keyFrameProgress)
        {
            IEasingFunction easingFunction = this.EasingFunction;

            if (easingFunction != null)
            {
                keyFrameProgress = easingFunction.Ease(keyFrameProgress);
            }
            if (keyFrameProgress == 0.0)
            {
                return(baseValue);
            }
            if (keyFrameProgress == 1.0)
            {
                return(base.Value);
            }
            return(AnimatedTypeHelpers.InterpolateThickness(baseValue, base.Value, keyFrameProgress));
        }
示例#12
0
        public override object GetCurrentValue(object defaultOriginValue, object defaultDestinationValue, AnimationClock animationClock)
        {
            double fromValue = ((GridLength)GetValue(GridLengthAnimation.FromProperty)).Value;
            double toValue   = ((GridLength)GetValue(GridLengthAnimation.ToProperty)).Value;

            IEasingFunction easingFunction = this.EasingFunction;

            double progress = (easingFunction != null) ? easingFunction.Ease(animationClock.CurrentProgress.Value) : animationClock.CurrentProgress.Value;

            if (fromValue > toValue)
            {
                return(new GridLength((1 - progress) * (fromValue - toValue) + toValue, this.To.IsStar ? GridUnitType.Star : GridUnitType.Pixel));
            }
            else
            {
                return(new GridLength((progress) * (toValue - fromValue) + fromValue, this.To.IsStar ? GridUnitType.Star : GridUnitType.Pixel));
            }
        }
示例#13
0
        protected void OnFrame(object sender, object e)
        {
            var elapsed = _elapsed.ElapsedMilliseconds;

            if (elapsed < StartDelay)
            {
                // We got an invalid tick ... handle it gracefully

                // Reconfigure the start interval to tick only at the end of the start delay
                ConfigureStartInterval(elapsed);

                CurrentPlayTime = 0;
                _currentValue   = _from;
            }
            else if (elapsed >= Duration)
            {
                IsRunning = false;
                DisableFrameReporting();
                _elapsed.Stop();

                CurrentPlayTime = Duration;
                _currentValue   = _to;

                Update?.Invoke(this, EventArgs.Empty);
                AnimationEnd?.Invoke(this, EventArgs.Empty);
            }
            else
            {
                if (_isDelaying)
                {
                    ConfigureAnimationInterval();
                }

                var frame = elapsed - StartDelay;
                var value = (float)_easing.Ease(frame, _from, _to, Duration);

                CurrentPlayTime = elapsed;
                _currentValue   = value;

                Update?.Invoke(this, EventArgs.Empty);
            }
        }
示例#14
0
        /// <summary>
        /// 获取当前动画进度
        /// </summary>
        /// <param name="animationClock"></param>
        /// <returns></returns>
        private double GetCurrentProgress(AnimationClock animationClock)
        {
            double progress = animationClock.CurrentProgress.Value;

            //获取经缓动函数变换后的进度
            IEasingFunction easingFunction = EasingFunction;

            if (easingFunction != null)
            {
                progress = easingFunction.Ease(progress);
            }

            //进度不大于1
            if (progress > 1)
            {
                progress = 1;
            }

            return(progress);
        }
示例#15
0
        internal override void DoAnimation(TimelineContext context, uint timepassed)
        {
            PropertyAnimationTimelineContext patc = (PropertyAnimationTimelineContext)context;

            if (patc.DataDescriptor == null)
            {
                return;
            }

            Vector2 from = From ?? (Vector2)patc.StartValue;
            Vector2 to   = To ?? (By.HasValue ? new Vector2(from.X + By.Value.X, from.Y + By.Value.Y) : (Vector2)patc.OriginalValue);

            double duration = Duration.TotalMilliseconds;

            if (timepassed > duration)
            {
                patc.DataDescriptor.Value = to;
                return;
            }

            double progress = timepassed / duration;

            IEasingFunction easingFunction = EasingFunction;

            if (easingFunction != null)
            {
                progress = easingFunction.Ease(progress);
            }

            double distx = to.X - from.X;

            distx *= progress;
            distx += from.X;

            double disty = to.Y - from.Y;

            disty *= progress;
            disty += from.Y;

            SetValue(context, new Vector2((float)distx, (float)disty));
        }
示例#16
0
        public override object GetCurrentValue(object defaultOriginValue, object defaultDestinationValue, AnimationClock animationClock)
        {
            double fromValue = this.From.Value;
            double toValue   = this.To.Value;

            double animationProgress = animationClock.CurrentProgress.Value;

            IEasingFunction easingFunction = EasingFunction;

            if (easingFunction != null)
            {
                animationProgress = easingFunction.Ease(animationProgress);
            }

            return(new GridLength(From.Value + ((To.Value - From.Value) * animationProgress), this.To.IsStar ? GridUnitType.Star : GridUnitType.Pixel));

            //if (fromValue > toValue) {
            //    return new GridLength((1 - animationProgress) * (fromValue - toValue) + toValue, this.To.IsStar ? GridUnitType.Star : GridUnitType.Pixel);
            //} else {
            //    return new GridLength(animationProgress * (toValue - fromValue) + fromValue, this.To.IsStar ? GridUnitType.Star : GridUnitType.Pixel);
            //}
        }
示例#17
0
        public override object GetCurrentValue(object defaultOriginValue,
                                               object defaultDestinationValue, AnimationClock animationClock)
        {
            double fromVal = ((GridLength)GetValue(FromProperty)).Value;

            double toVal = ((GridLength)GetValue(ToProperty)).Value;

            double progress = animationClock.CurrentProgress.Value;

            IEasingFunction easingFunction = EasingFunction;

            if (easingFunction != null)
            {
                progress = easingFunction.Ease(progress);
            }


            if (fromVal > toVal)
            {
                return(new GridLength((1 - progress) * (fromVal - toVal) + toVal, GridUnitType.Star));
            }

            return(new GridLength(progress * (toVal - fromVal) + fromVal, GridUnitType.Star));
        }
示例#18
0
        public override Color Interpolate(Color start, double keyframe)
        {
            if (keyframe <= 0.0)
            {
                return(start);
            }
            if (keyframe >= 1.0)
            {
                return(Value);
            }
            if (double.IsNaN(keyframe))
            {
                return(start);
            }

            IEasingFunction easingFunction = EasingFunction;

            if (easingFunction != null)
            {
                keyframe = easingFunction.Ease(keyframe);
            }

            return(Color.SmoothStep(start, Value, (float)keyframe));
        }
示例#19
0
        internal override void DoAnimation(TimelineContext context, uint timepassed)
        {
            PropertyAnimationTimelineContext patc = (PropertyAnimationTimelineContext)context;

            if (patc.DataDescriptor == null)
            {
                return;
            }

            double from = From ?? (double)patc.StartValue;
            double to   = To ?? (By.HasValue ? from + By.Value : (double)patc.OriginalValue);

            double duration = Duration.TotalMilliseconds;

            if (timepassed > duration)
            {
                patc.DataDescriptor.Value = to;
                return;
            }

            double progress = timepassed / duration;

            IEasingFunction easingFunction = EasingFunction;

            if (easingFunction != null)
            {
                progress = easingFunction.Ease(progress);
            }

            double dist = to - from;

            dist *= progress;
            dist += from;

            patc.DataDescriptor.Value = dist;
        }
示例#20
0
        public override double Interpolate(double start, double keyframe)
        {
            if (keyframe <= 0.0)
            {
                return(start);
            }
            if (keyframe >= 1.0)
            {
                return(Value);
            }
            if (double.IsNaN(keyframe))
            {
                return(start);
            }

            IEasingFunction easingFunction = EasingFunction;

            if (easingFunction != null)
            {
                keyframe = easingFunction.Ease(keyframe);
            }

            return(start + ((Value - start) * keyframe));
        }
示例#21
0
        protected override Matrix3D GetCurrentValueCore(Matrix3D defaultOriginValue, Matrix3D defaultDestinationValue, AnimationClock animationClock)
        {
            Debug.Assert(animationClock.CurrentState != ClockState.Stopped);

            if (!_isAnimationFunctionValid)
            {
                ValidateAnimationFunction();
            }

            double progress = animationClock.CurrentProgress.Value;

            IEasingFunction easingFunction = EasingFunction;

            if (easingFunction != null)
            {
                progress = easingFunction.Ease(progress);
            }

            Matrix3D from = new Matrix3D();
            Matrix3D to   = new Matrix3D();

            switch (_animationType)
            {
            case AnimationType.Automatic:
                from = defaultOriginValue;
                to   = defaultDestinationValue;
                break;

            case AnimationType.From:
                from = _keyValues[0];
                to   = defaultDestinationValue;
                break;

            case AnimationType.To:
                from = defaultOriginValue;
                to   = _keyValues[0];
                break;

            case AnimationType.By:
                to = _keyValues[0];
                break;

            case AnimationType.FromTo:
                from = _keyValues[0];
                to   = _keyValues[1];
                break;

            default:
                Debug.Fail("Unknown animation type.");
                break;
            }

            Matrix3D matrix3D = from;

            matrix3D.M11 = from.M11 + (to.M11 - from.M11) * progress;
            matrix3D.M12 = from.M12 + (to.M12 - from.M12) * progress;
            matrix3D.M13 = from.M13 + (to.M13 - from.M13) * progress;
            matrix3D.M14 = from.M14 + (to.M14 - from.M14) * progress;
            matrix3D.M21 = from.M21 + (to.M21 - from.M21) * progress;
            matrix3D.M22 = from.M22 + (to.M22 - from.M22) * progress;
            matrix3D.M23 = from.M23 + (to.M23 - from.M23) * progress;
            matrix3D.M24 = from.M24 + (to.M24 - from.M24) * progress;
            matrix3D.M31 = from.M31 + (to.M31 - from.M31) * progress;
            matrix3D.M32 = from.M32 + (to.M32 - from.M32) * progress;
            matrix3D.M33 = from.M33 + (to.M33 - from.M33) * progress;
            matrix3D.M34 = from.M34 + (to.M34 - from.M34) * progress;
            matrix3D.M44 = from.M44 + (to.M44 - from.M44) * progress;

            matrix3D.OffsetX = from.OffsetX + (to.OffsetX - from.OffsetX) * progress;
            matrix3D.OffsetY = from.OffsetY + (to.OffsetY - from.OffsetY) * progress;
            matrix3D.OffsetZ = from.OffsetZ + (to.OffsetZ - from.OffsetZ) * progress;

            return(matrix3D);
        }
 public CornerRadiusAnimation()
 {
     Graph = x => EasingFunction == null ? x : EasingFunction.Ease(x);
 }
示例#23
0
 public static T Evaluate <T>(this IInterpolator <T> interpolator, T start, T end, double progress, IEasingFunction easingFunction = null)
 {
     return(interpolator.Evaluate(start, end, easingFunction?.Ease(progress) ?? progress));
 }
        protected LinearGradientBrush GetCurrentValueCore(LinearGradientBrush defaultOriginValue, LinearGradientBrush defaultDestinationValue, AnimationClock animationClock)
        {
            if (!this._isAnimationFunctionValid)
            {
                this.ValidateAnimationFunction();
            }
            double          num            = animationClock.CurrentProgress.Value;
            IEasingFunction easingFunction = this.EasingFunction;

            if (easingFunction != null)
            {
                num = easingFunction.Ease(num);
            }
            LinearGradientBrush brush  = null;
            LinearGradientBrush brush2 = null;
            LinearGradientBrush value  = null;
            LinearGradientBrush value2 = null;

            switch (this._animationType)
            {
            case AnimationType.Automatic:
                brush  = defaultOriginValue;
                brush2 = defaultDestinationValue;
                value  = GetDefaultLinearGradientBrush(brush);
                value2 = GetDefaultLinearGradientBrush(brush);
                break;

            case AnimationType.From:
                brush  = this._keyValues[0];
                brush2 = defaultDestinationValue;
                value  = GetDefaultLinearGradientBrush(brush);
                value2 = GetDefaultLinearGradientBrush(brush);
                break;

            case AnimationType.To:
                brush  = defaultOriginValue;
                brush2 = this._keyValues[0];
                value  = GetDefaultLinearGradientBrush(brush2);
                value2 = GetDefaultLinearGradientBrush(brush2);
                break;

            case AnimationType.By:
                brush2 = this._keyValues[0];
                value2 = defaultOriginValue;
                value  = GetDefaultLinearGradientBrush(brush2);
                value2 = GetDefaultLinearGradientBrush(brush2);
                break;

            case AnimationType.FromTo:
                brush  = this._keyValues[0];
                brush2 = this._keyValues[1];
                value  = GetDefaultLinearGradientBrush(brush);
                value2 = GetDefaultLinearGradientBrush(brush);
                if (this.IsAdditive)
                {
                    value2 = defaultOriginValue;
                }
                break;

            case AnimationType.FromBy:
                brush  = this._keyValues[0];
                brush2 = AddLinearGradientBrush(this._keyValues[0], this._keyValues[1]);
                value  = GetDefaultLinearGradientBrush(brush);
                value2 = GetDefaultLinearGradientBrush(brush);
                if (this.IsAdditive)
                {
                    value2 = defaultOriginValue;
                }
                break;
            }

            if (this.IsCumulative)
            {
                double num2 = (double)(animationClock.CurrentIteration - 1).Value;
                if (num2 > 0.0)
                {
                    LinearGradientBrush value3 = SubtractLinearGradientBrush(brush2, brush);
                    value = ScaleLinearGradientBrush(value3, num2);
                }
            }
            LinearGradientBrush returnBrush = AddLinearGradientBrush(value2, AddLinearGradientBrush(value, InterpolateGradientBrush(brush, brush2, num)));

            return(returnBrush);
        }
示例#25
0
        /// <summary>
        /// Calculates a value that represents the current value of the property being animated, as determined by the <see cref="T:System.Windows.Media.Animation.ThicknessAnimation"/>.
        /// </summary>
        ///
        /// <returns>
        /// The calculated value of the property, as determined by the current animation.
        /// </returns>
        /// <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="T:System.Windows.Media.Animation.AnimationClock"/> that generates the <see cref="P:System.Windows.Media.Animation.Clock.CurrentTime"/> or <see cref="P:System.Windows.Media.Animation.Clock.CurrentProgress"/> used by the animation.</param>
        protected override CornerRadius GetCurrentValueCore(CornerRadius defaultOriginValue, CornerRadius defaultDestinationValue, AnimationClock animationClock)
        {
            if (!this._isAnimationFunctionValid)
            {
                this.ValidateAnimationFunction();
            }
            double          num1           = animationClock.CurrentProgress.Value;
            IEasingFunction easingFunction = this.EasingFunction;

            if (easingFunction != null)
            {
                num1 = easingFunction.Ease(num1);
            }
            var  from       = new CornerRadius();
            var  to         = new CornerRadius();
            var  thickness1 = new CornerRadius();
            var  thickness2 = new CornerRadius();
            bool flag1      = false;
            bool flag2      = false;

            switch (this._AnimationMode)
            {
            case AnimationMode.Automatic:
                from  = defaultOriginValue;
                to    = defaultDestinationValue;
                flag1 = true;
                flag2 = true;
                break;

            case AnimationMode.From:
                from  = this._keyValues[0];
                to    = defaultDestinationValue;
                flag2 = true;
                break;

            case AnimationMode.To:
                from  = defaultOriginValue;
                to    = this._keyValues[0];
                flag1 = true;
                break;

            case AnimationMode.By:
                to         = this._keyValues[0];
                thickness2 = defaultOriginValue;
                flag1      = true;
                break;

            case AnimationMode.FromTo:
                from = this._keyValues[0];
                to   = this._keyValues[1];
                if (this.IsAdditive)
                {
                    thickness2 = defaultOriginValue;
                    flag1      = true;
                    break;
                }
                break;

            case AnimationMode.FromBy:
                from = this._keyValues[0];
                to   = AnimationHelpers.AddCornerRadius(this._keyValues[0], this._keyValues[1]);
                if (this.IsAdditive)
                {
                    thickness2 = defaultOriginValue;
                    flag1      = true;
                    break;
                }
                break;
            }
            if (flag1 && !AnimationHelpers.IsValidAnimationValueCornerRadius(defaultOriginValue))
            {
                throw new InvalidOperationException("Animation_Invalid_DefaultValue");
            }
            if (flag2 && !AnimationHelpers.IsValidAnimationValueCornerRadius(defaultDestinationValue))
            {
                throw new InvalidOperationException("Animation_Invalid_DefaultValue");
            }
            if (this.IsCumulative)
            {
                int?   currentIteration = animationClock.CurrentIteration;
                int    num2             = 1;
                double factor           = (double)(currentIteration.HasValue ? new int?(currentIteration.GetValueOrDefault() - num2) : new int?()).Value;
                if (factor > 0.0)
                {
                    thickness1 = AnimationHelpers.ScaleCornerRadius(AnimationHelpers.SubtractCornerRadius(to, from), factor);
                }
            }
            return(AnimationHelpers.AddCornerRadius(thickness2, AnimationHelpers.AddCornerRadius(thickness1, AnimationHelpers.InterpolateCornerRadius(from, to, num1))));
        }
示例#26
0
        /// <summary>Calculates a value that represents the current value of the property being animated, as determined by the <see cref="T:System.Windows.Media.Animation.ThicknessAnimation" />. </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="T:System.Windows.Media.Animation.AnimationClock" /> that generates the <see cref="P:System.Windows.Media.Animation.Clock.CurrentTime" /> or <see cref="P:System.Windows.Media.Animation.Clock.CurrentProgress" /> used by the animation.</param>
        /// <returns>The calculated value of the property, as determined by the current animation.</returns>
        // Token: 0x06001742 RID: 5954 RVA: 0x00072068 File Offset: 0x00070268
        protected override Thickness GetCurrentValueCore(Thickness defaultOriginValue, Thickness defaultDestinationValue, AnimationClock animationClock)
        {
            if (!this._isAnimationFunctionValid)
            {
                this.ValidateAnimationFunction();
            }
            double          num            = animationClock.CurrentProgress.Value;
            IEasingFunction easingFunction = this.EasingFunction;

            if (easingFunction != null)
            {
                num = easingFunction.Ease(num);
            }
            Thickness thickness  = default(Thickness);
            Thickness thickness2 = default(Thickness);
            Thickness value      = default(Thickness);
            Thickness value2     = default(Thickness);
            bool      flag       = false;
            bool      flag2      = false;

            switch (this._animationType)
            {
            case AnimationType.Automatic:
                thickness  = defaultOriginValue;
                thickness2 = defaultDestinationValue;
                flag       = true;
                flag2      = true;
                break;

            case AnimationType.From:
                thickness  = this._keyValues[0];
                thickness2 = defaultDestinationValue;
                flag2      = true;
                break;

            case AnimationType.To:
                thickness  = defaultOriginValue;
                thickness2 = this._keyValues[0];
                flag       = true;
                break;

            case AnimationType.By:
                thickness2 = this._keyValues[0];
                value2     = defaultOriginValue;
                flag       = true;
                break;

            case AnimationType.FromTo:
                thickness  = this._keyValues[0];
                thickness2 = this._keyValues[1];
                if (this.IsAdditive)
                {
                    value2 = defaultOriginValue;
                    flag   = true;
                }
                break;

            case AnimationType.FromBy:
                thickness  = this._keyValues[0];
                thickness2 = AnimatedTypeHelpers.AddThickness(this._keyValues[0], this._keyValues[1]);
                if (this.IsAdditive)
                {
                    value2 = defaultOriginValue;
                    flag   = true;
                }
                break;
            }
            if (flag && !AnimatedTypeHelpers.IsValidAnimationValueThickness(defaultOriginValue))
            {
                throw new InvalidOperationException(SR.Get("Animation_Invalid_DefaultValue", new object[]
                {
                    base.GetType(),
                    "origin",
                    defaultOriginValue.ToString(CultureInfo.InvariantCulture)
                }));
            }
            if (flag2 && !AnimatedTypeHelpers.IsValidAnimationValueThickness(defaultDestinationValue))
            {
                throw new InvalidOperationException(SR.Get("Animation_Invalid_DefaultValue", new object[]
                {
                    base.GetType(),
                    "destination",
                    defaultDestinationValue.ToString(CultureInfo.InvariantCulture)
                }));
            }
            if (this.IsCumulative)
            {
                double num2 = (double)(animationClock.CurrentIteration - 1).Value;
                if (num2 > 0.0)
                {
                    Thickness value3 = AnimatedTypeHelpers.SubtractThickness(thickness2, thickness);
                    value = AnimatedTypeHelpers.ScaleThickness(value3, num2);
                }
            }
            return(AnimatedTypeHelpers.AddThickness(value2, AnimatedTypeHelpers.AddThickness(value, AnimatedTypeHelpers.InterpolateThickness(thickness, thickness2, num))));
        }
 public GridLengthAnimation()
 {
     Graph = x => EasingFunction == null ? x : EasingFunction.Ease(x);
 }
示例#28
0
 protected override double EaseInCore(double normalizedTime)
 {
     return(function.Ease(normalizedTime));
 }
 public SolidColorBrushAnimation()
 {
     Graph = x => EasingFunction == null ? x : EasingFunction.Ease(x);
 }
示例#30
0
        /// <summary>
        /// Calculates the value this animation believes should be the current value for the property.
        /// </summary>
        /// <param name="defaultOriginValue">
        /// This value is the suggested origin value provided to the animation
        /// to be used if the animation does not have its own concept of a
        /// start value. If this animation is the first in a composition chain
        /// this value will be the snapshot value if one is available or the
        /// base property value if it is not; otherise this value will be the
        /// value returned by the previous animation in the chain with an
        /// animationClock that is not Stopped.
        /// </param>
        /// <param name="defaultDestinationValue">
        /// This value is the suggested destination value provided to the animation
        /// to be used if the animation does not have its own concept of an
        /// end value. This value will be the base value if the animation is
        /// in the first composition layer of animations on a property;
        /// otherwise this value will be the output value from the previous
        /// composition layer of animations for the property.
        /// </param>
        /// <param name="animationClock">
        /// This is the animationClock which can generate the CurrentTime or
        /// 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 override Int16 GetCurrentValueCore(Int16 defaultOriginValue, Int16 defaultDestinationValue, AnimationClock animationClock)
        {
            Debug.Assert(animationClock.CurrentState != ClockState.Stopped);

            if (!_isAnimationFunctionValid)
            {
                ValidateAnimationFunction();
            }

            double progress = animationClock.CurrentProgress.Value;

            IEasingFunction easingFunction = EasingFunction;

            if (easingFunction != null)
            {
                progress = easingFunction.Ease(progress);
            }

            Int16 from        = new Int16();
            Int16 to          = new Int16();
            Int16 accumulated = new Int16();
            Int16 foundation  = new Int16();

            // need to validate the default origin and destination values if
            // the animation uses them as the from, to, or foundation values
            bool validateOrigin      = false;
            bool validateDestination = false;

            switch (_animationType)
            {
            case AnimationType.Automatic:

                from = defaultOriginValue;
                to   = defaultDestinationValue;

                validateOrigin      = true;
                validateDestination = true;

                break;

            case AnimationType.From:

                from = _keyValues[0];
                to   = defaultDestinationValue;

                validateDestination = true;

                break;

            case AnimationType.To:

                from = defaultOriginValue;
                to   = _keyValues[0];

                validateOrigin = true;

                break;

            case AnimationType.By:

                // According to the SMIL specification, a By animation is
                // always additive.  But we don't force this so that a
                // user can re-use a By animation and have it replace the
                // animations that precede it in the list without having
                // to manually set the From value to the base value.

                to         = _keyValues[0];
                foundation = defaultOriginValue;

                validateOrigin = true;

                break;

            case AnimationType.FromTo:

                from = _keyValues[0];
                to   = _keyValues[1];

                if (IsAdditive)
                {
                    foundation     = defaultOriginValue;
                    validateOrigin = true;
                }

                break;

            case AnimationType.FromBy:

                from = _keyValues[0];
                to   = AnimatedTypeHelpers.AddInt16(_keyValues[0], _keyValues[1]);

                if (IsAdditive)
                {
                    foundation     = defaultOriginValue;
                    validateOrigin = true;
                }

                break;

            default:

                Debug.Fail("Unknown animation type.");

                break;
            }

            if (validateOrigin &&
                !AnimatedTypeHelpers.IsValidAnimationValueInt16(defaultOriginValue))
            {
                throw new InvalidOperationException(
                          SR.Get(
                              SRID.Animation_Invalid_DefaultValue,
                              this.GetType(),
                              "origin",
                              defaultOriginValue.ToString(CultureInfo.InvariantCulture)));
            }

            if (validateDestination &&
                !AnimatedTypeHelpers.IsValidAnimationValueInt16(defaultDestinationValue))
            {
                throw new InvalidOperationException(
                          SR.Get(
                              SRID.Animation_Invalid_DefaultValue,
                              this.GetType(),
                              "destination",
                              defaultDestinationValue.ToString(CultureInfo.InvariantCulture)));
            }


            if (IsCumulative)
            {
                double currentRepeat = (double)(animationClock.CurrentIteration - 1);

                if (currentRepeat > 0.0)
                {
                    Int16 accumulator = AnimatedTypeHelpers.SubtractInt16(to, from);

                    accumulated = AnimatedTypeHelpers.ScaleInt16(accumulator, currentRepeat);
                }
            }

            // return foundation + accumulated + from + ((to - from) * progress)

            return(AnimatedTypeHelpers.AddInt16(
                       foundation,
                       AnimatedTypeHelpers.AddInt16(
                           accumulated,
                           AnimatedTypeHelpers.InterpolateInt16(from, to, progress))));
        }
        /// <summary>
        /// Calculates the value this animation believes should be the current value for the property.
        /// </summary>
        /// <param name="defaultOriginValue">
        /// This value is the suggested origin value provided to the animation
        /// to be used if the animation does not have its own concept of a
        /// start value. If this animation is the first in a composition chain
        /// this value will be the snapshot value if one is available or the
        /// base property value if it is not; otherise this value will be the
        /// value returned by the previous animation in the chain with an
        /// animationClock that is not Stopped.
        /// </param>
        /// <param name="defaultDestinationValue">
        /// This value is the suggested destination value provided to the animation
        /// to be used if the animation does not have its own concept of an
        /// end value. This value will be the base value if the animation is
        /// in the first composition layer of animations on a property;
        /// otherwise this value will be the output value from the previous
        /// composition layer of animations for the property.
        /// </param>
        /// <param name="animationClock">
        /// This is the animationClock which can generate the CurrentTime or
        /// 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 override Color GetCurrentValueCore(
            Color defaultOriginValue,
            Color defaultDestinationValue,
            AnimationClock animationClock)
        {
            if (animationClock.CurrentState == ClockState.Stopped ||
                !animationClock.CurrentProgress.HasValue)
            {
                return(defaultOriginValue);
            }

            double          progress       = animationClock.CurrentProgress.Value;
            IEasingFunction easingFunction = EasingFunction;

            if (easingFunction != null)
            {
                progress = easingFunction.Ease(progress);
            }

            if (progress.IsLessThan(0) ||
                progress.IsGreaterThan(1))
            {
                return(defaultOriginValue);
            }

            // Need to double the pace if reverse effect is enabled
            float scaleFactor = (float)(reverseEffect ? progress * 2 : progress);

            float hueDelta        = hueOffset;
            float saturationDelta = saturationOffset;
            float brightnessDelta = brightnessOffset;

            if (!reverseEffect ||
                scaleFactor.IsLessThanOrClose(1))
            {
                hueDelta        *= scaleFactor;
                saturationDelta *= scaleFactor;
                brightnessDelta *= scaleFactor;
            }
            else
            {
                if (scaleFactor.IsGreaterThan(1))
                {
                    scaleFactor -= 1;

                    hueDelta        -= hueDelta * scaleFactor;
                    saturationDelta -= saturationDelta * scaleFactor;
                    brightnessDelta -= brightnessDelta * scaleFactor;
                }
            }

            if (hueDelta.IsZero() &&
                saturationDelta.IsZero() &&
                brightnessDelta.IsZero())
            {
                // No changes
                return(defaultOriginValue);
            }

            Color color = HsbColor.Offset(
                defaultDestinationValue,
                hueDelta,
                saturationDelta,
                brightnessDelta);

            return(color);
        }