/// <summary>
        /// Adds a keyframe to the collection.
        /// </summary>
        /// <param name="keyframe">The keyframe to add to the collection.</param>
        /// <returns><see langword="true"/> if the keyframe was added to the collection; otherwise, <see langword="false"/>.</returns>
        public Boolean Add(AnimationKeyframe <T> keyframe)
        {
            Contract.Require(keyframe, nameof(keyframe));

            if (Contains(keyframe))
            {
                return(false);
            }

            var index = 0;

            if (Count > 0)
            {
                for (int i = 0; i < keyframes.Count - 1; i++)
                {
                    if (keyframes[i].Time < keyframe.Time && keyframes[i + 1].Time >= keyframe.Time)
                    {
                        index = i + 1;
                        break;
                    }
                }
                index = keyframes.Count;
            }
            keyframes.Insert(index, keyframe);

            animation.RecalculateDuration();
            return(true);
        }
        /// <summary>
        /// Removes the specified keyframe from the collection.
        /// </summary>
        /// <param name="keyframe">The keyframe to remove from the collection.</param>
        /// <returns><see langword="true"/> if the keyframe was removed from the collection; otherwise, false.</returns>
        public Boolean Remove(AnimationKeyframe <T> keyframe)
        {
            Contract.Require(keyframe, nameof(keyframe));

            if (keyframes.Remove(keyframe))
            {
                animation.RecalculateDuration();
                return(true);
            }
            return(false);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the keyframes that surround the specified moment in time.
        /// </summary>
        /// <param name="time">The time to evaluate.</param>
        /// <param name="kf1">The keyframe that precedes the specified time.</param>
        /// <param name="kf2">The keyframe that succeeds the specified time.</param>
        public void GetKeyframes(TimeSpan time, out AnimationKeyframe <T> kf1, out AnimationKeyframe <T> kf2)
        {
            if (keyframes.Count == 0)
            {
                kf1 = null;
                kf2 = null;
                return;
            }

            if (time < keyframes[0].Time)
            {
                kf1 = null;
                kf2 = keyframes[0];
                return;
            }

            if (time > keyframes[keyframes.Count - 1].Time)
            {
                kf1 = keyframes[keyframes.Count - 1];
                kf2 = null;
                return;
            }

            for (int i = 0; i < keyframes.Count - 1; i++)
            {
                if (keyframes[i].Time <= time && keyframes[i + 1].Time >= time)
                {
                    kf1 = keyframes[i];
                    kf2 = keyframes[i + 1];
                    return;
                }
            }

            kf1 = keyframes[keyframes.Count - 1];
            kf2 = null;
        }
        /// <summary>
        /// Gets a value indicating whether the collection contains the specified keyframe.
        /// </summary>
        /// <param name="keyframe">The keyframe to evaluate.</param>
        /// <returns><see langword="true"/> if the collection contains the specified keyframe; otherwise, <see langword="false"/>.</returns>
        public Boolean Contains(AnimationKeyframe <T> keyframe)
        {
            Contract.Require(keyframe, nameof(keyframe));

            return(keyframes.Contains(keyframe));
        }