コード例 #1
0
        /// <summary>
        /// Returns a <see cref="Brush"/> which serves as a zero-value for an additive animation.
        /// The exact type of the brush is dependent on the first key frame in the animation.
        /// </summary>
        /// <returns>A new <see cref="Brush"/> which serves as a zero-value.</returns>
        protected override sealed Brush GetZeroValue()
        {
            if (KeyFrames.Count == 0)
            {
                throw new InvalidOperationException(
                          "Creating a zero-brush requires at least one registered key frame.");
            }

            var firstFrame = KeyFrames.First();
            var brushType  = firstFrame.Value.GetType();

            return(BrushAnimationHelper.Instance.GetZeroValue());
        }
コード例 #2
0
        /// <summary>
        /// Called when the <see cref="ExtendedVisualStateManager"/> transitions to the element.
        /// The timeline which gets returned by this method is then used as a transitioning animation.
        /// </summary>
        /// <param name="toTimeline">
        /// The input timeline, for which a visual transition timeline should be generated.
        /// The VisualStateManager wants to transition to this timeline.
        /// </param>
        /// <param name="easingFunction">
        /// An easing function to be applied to the resulting timeline.
        /// Can be null.
        /// </param>
        /// <returns>
        /// A <see cref="Timeline"/> which displays a visual transition to this element.
        /// </returns>
        public Timeline CreateToTransitionTimeline(
            Timeline toTimeline, IEasingFunction easingFunction)
        {
            var result = new BrushAnimation()
            {
                EasingFunction = easingFunction
            };

            if (KeyFrames.Count > 0)
            {
                result.To = KeyFrames.First().Value;
            }
            return(result);
        }
コード例 #3
0
        public override float GetFrameValue(float frame, float startFrame = 0)
        {
            if (InterpolationType == STInterpoaltionType.Constant)
            {
                return(Constant);
            }

            if (KeyFrames.Count == 0)
            {
                return(0);
            }
            if (KeyFrames.Count == 1)
            {
                return(KeyFrames[0].Value);
            }

            STKeyFrame LK = KeyFrames.First();
            STKeyFrame RK = KeyFrames.Last();

            float Frame = frame - startFrame;

            foreach (STKeyFrame keyFrame in KeyFrames)
            {
                if (keyFrame.Frame <= Frame)
                {
                    LK = keyFrame;
                }
                if (keyFrame.Frame >= Frame && keyFrame.Frame < RK.Frame)
                {
                    RK = keyFrame;
                }
            }

            if (LK.Frame != RK.Frame)
            {
                float FrameDiff = Frame - LK.Frame;
                float Weight    = FrameDiff / (RK.Frame - LK.Frame);

                switch (InterpolationType)
                {
                case STInterpoaltionType.Constant: return(LK.Value);

                case STInterpoaltionType.Step: return(LK.Value);

                case STInterpoaltionType.Linear: return(InterpolationHelper.Lerp(LK.Value, RK.Value, Weight));

                case STInterpoaltionType.Bezier:
                {
                    return(InterpolationHelper.Lerp(LK.Value, RK.Value, Weight));

                    STBezierKeyFrame bezierKeyLK = (STBezierKeyFrame)LK;
                    STBezierKeyFrame bezierKeyRK = (STBezierKeyFrame)RK;

                    float length = RK.Frame - LK.Frame;

                    return(InterpolationHelper.BezierInterpolate(frame,
                                                                 bezierKeyLK.Frame,
                                                                 bezierKeyRK.Frame,
                                                                 bezierKeyLK.SlopeIn,
                                                                 bezierKeyRK.SlopeOut,
                                                                 bezierKeyLK.Value,
                                                                 bezierKeyRK.Value));
                }

                case STInterpoaltionType.Hermite:
                {
                    STHermiteKeyFrame hermiteKeyLK = (STHermiteKeyFrame)LK;
                    STHermiteKeyFrame hermiteKeyRK = (STHermiteKeyFrame)RK;

                    float length = RK.Frame - LK.Frame;

                    return(InterpolationHelper.HermiteInterpolate(frame,
                                                                  hermiteKeyLK.Frame,
                                                                  hermiteKeyRK.Frame,
                                                                  hermiteKeyLK.TangentIn,
                                                                  hermiteKeyLK.TangentOut,
                                                                  hermiteKeyLK.Value,
                                                                  hermiteKeyRK.Value));
                }
                }
            }

            return(LK.Value);
        }