예제 #1
0
        //--------------------------------------------------------------
        #region Methods
        //--------------------------------------------------------------

        /// <inheritdoc/>
        public override TimeSpan GetTotalDuration()
        {
            TimeSpan duration = TimeSpan.Zero;

            if (X != null)
            {
                duration = AnimationHelper.Max(duration, X.GetTotalDuration());
            }

            if (Y != null)
            {
                duration = AnimationHelper.Max(duration, Y.GetTotalDuration());
            }

            return(duration);
        }
예제 #2
0
        /// <inheritdoc/>
        public TimeSpan?GetAnimationTime(TimeSpan time)
        {
            // Get the effective start, end and duration of the clip.
            TimeSpan clipStart, clipEnd, clipLength;

            GetClip(out clipStart, out clipEnd, out clipLength);

            // ----- Delay
            time -= Delay;
            if (time < TimeSpan.Zero)
            {
                // The animation has not started.
                return(null);
            }

            // ----- Speed
            time = new TimeSpan((long)(time.Ticks * (double)Speed));

            // ----- Duration
            TimeSpan duration = Duration ?? clipLength;

            // ----- FillBehavior
            if (time > duration)
            {
                if (FillBehavior == FillBehavior.Stop)
                {
                    // The animation has stopped.
                    return(null);
                }

                // The animation holds the last value.
                Debug.Assert(FillBehavior == FillBehavior.Hold);
                time = duration;
            }

            // ----- Adjust animation time to play/loop clip from original timeline.
            time = clipStart + ClipOffset + time;
            AnimationHelper.LoopParameter(time, clipStart, clipEnd, LoopBehavior, out time);

            // ----- Reverse
            if (IsClipReversed)
            {
                time = clipEnd - (time - clipStart);
            }

            return(time);
        }
예제 #3
0
        //--------------------------------------------------------------
        #region Methods
        //--------------------------------------------------------------

        /// <inheritdoc/>
        public override TimeSpan GetTotalDuration()
        {
            TimeSpan duration = TimeSpan.Zero;

            if (Scale != null)
            {
                duration = AnimationHelper.Max(duration, Scale.GetTotalDuration());
            }

            if (Rotation != null)
            {
                duration = AnimationHelper.Max(duration, Rotation.GetTotalDuration());
            }

            if (Translation != null)
            {
                duration = AnimationHelper.Max(duration, Translation.GetTotalDuration());
            }

            return(duration);
        }
예제 #4
0
        private void GetValueCore(TimeSpan time, ref T defaultSource, ref T defaultTarget, ref T result)
        {
            if (Animation == null)
            {
                Traits.Copy(ref defaultSource, ref result);
                return;
            }

            TimeSpan clipStart, clipEnd, clipLength;

            GetClip(out clipStart, out clipEnd, out clipLength);

            // Correct time parameter.
            time = clipStart + ClipOffset + time;

            TimeSpan loopedTime;
            bool     hasCycleOffset = AnimationHelper.LoopParameter(time, clipStart, clipEnd, LoopBehavior, out loopedTime);

            // ----- Reverse
            if (IsClipReversed)
            {
                loopedTime = clipEnd - (loopedTime - clipStart);
            }

            if (!hasCycleOffset)
            {
                // Get animation value.
                Animation.GetValue(loopedTime, ref defaultSource, ref defaultTarget, ref result);
            }
            else
            {
                // Animation with cycle offset.
                var traits = Traits;

                // 'defaultSource', 'defaultTarget' and 'result' may be the same instance! We need to
                // ensure that the source and target values are not overwritten by GetValue().
                // --> Use local variable to get animation value.
                T value, startValue, endValue, cycleOffset;
                traits.Create(ref defaultSource, out value);
                traits.Create(ref defaultSource, out startValue);
                traits.Create(ref defaultSource, out endValue);
                traits.Create(ref defaultSource, out cycleOffset);

                // Get animation value.
                Animation.GetValue(loopedTime, ref defaultSource, ref defaultTarget, ref value);

                // Apply cycle offset.
                Animation.GetValue(clipStart, ref defaultSource, ref defaultTarget, ref startValue);
                Animation.GetValue(clipEnd, ref defaultSource, ref defaultTarget, ref endValue);

                if (IsClipReversed)
                {
                    MathHelper.Swap(ref startValue, ref endValue);
                }

                AnimationHelper.GetCycleOffset(time, clipStart, clipEnd, ref startValue, ref endValue, traits, LoopBehavior, ref cycleOffset);
                traits.Add(ref value, ref cycleOffset, ref result);

                traits.Recycle(ref cycleOffset);
                traits.Recycle(ref endValue);
                traits.Recycle(ref startValue);
                traits.Recycle(ref value);
            }
        }
예제 #5
0
 /// <inheritdoc/>
 public AnimationState GetState(TimeSpan time)
 {
     return(AnimationHelper.GetState(this, time));
 }
예제 #6
0
 /// <inheritdoc/>
 public TimeSpan?GetAnimationTime(TimeSpan time)
 {
     return(AnimationHelper.GetAnimationTime(this, time));
 }