/// <summary>
        /// Gets the cycle offset for a time value.
        /// </summary>
        /// <typeparam name="T">The type of animation value.</typeparam>
        /// <param name="time">The time value.</param>
        /// <param name="startTime">The start time.</param>
        /// <param name="endTime">The end time.</param>
        /// <param name="startValue">In: The animation value at <paramref name="startTime"/>.</param>
        /// <param name="endValue">In: The animation value at <paramref name="endTime"/>.</param>
        /// <param name="traits">The traits of the animation value.</param>
        /// <param name="loopBehavior">The post-loop behavior.</param>
        /// <param name="cycleOffset">
        /// Out: The cycle offset.
        /// </param>
        /// <remarks>
        /// The cycle offset is <see cref="IAnimationValueTraits{T}.SetIdentity"/> if the
        /// <see cref="LoopBehavior"/> is unequal to <see cref="LoopBehavior.CycleOffset"/> or if the
        /// <paramref name="time"/> is in the regular cycle (between the first and the last key frame).
        /// </remarks>
        internal static void GetCycleOffset <T>(TimeSpan time,
                                                TimeSpan startTime, TimeSpan endTime,
                                                ref T startValue, ref T endValue,
                                                IAnimationValueTraits <T> traits,
                                                LoopBehavior loopBehavior,
                                                ref T cycleOffset)
        {
            Debug.Assert(endTime > startTime, "Invalid start and end time.");
            TimeSpan length = endTime - startTime;

            // Handle cycle offset.
            if (loopBehavior == LoopBehavior.CycleOffset && length != TimeSpan.Zero)
            {
                traits.Invert(ref startValue, ref startValue);
                traits.Add(ref startValue, ref endValue, ref cycleOffset);

                if (time < startTime)
                {
                    long numberOfPeriods = (time.Ticks - endTime.Ticks) / length.Ticks;
                    Debug.Assert(numberOfPeriods < 0, "Negative number of periods expected.");
                    traits.Multiply(ref cycleOffset, (int)numberOfPeriods, ref cycleOffset);
                }
                else if (time > endTime)
                {
                    long numberOfPeriods = (time.Ticks - startTime.Ticks) / length.Ticks;
                    Debug.Assert(numberOfPeriods > 0, "Positive number of periods expected.");
                    traits.Multiply(ref cycleOffset, (int)numberOfPeriods, ref cycleOffset);
                }
                else
                {
                    traits.SetIdentity(ref cycleOffset);
                }
            }
        }
Exemple #2
0
 private void Reset()
 {
     Clear();
     ClearSnapshot();
     _weakReference.Target = null;
     _traits.Recycle(ref _value);
     _traits = null;
 }
Exemple #3
0
        public static T Identity <T>(this IAnimationValueTraits <T> traits)
        {
            T reference = default(T);
            T identity;

            traits.Create(ref reference, out identity);
            traits.SetIdentity(ref identity);
            return(identity);
        }
    /// <summary>
    /// Initializes the <see cref="AnimationCompositionChain{T}"/>.
    /// </summary>
    /// <param name="property">The property that should be animated.</param>
    /// <param name="traits">The animation value traits.</param>
    /// <exception cref="ArgumentNullException">
    /// Either <paramref name="property"/> or <paramref name="traits"/> is <see langword="null"/>.
    /// </exception>
    public void Initialize(IAnimatableProperty<T> property, IAnimationValueTraits<T> traits)
    {
      Debug.Assert(Count == 0, "Animation composition chain has not been reset properly.");
      Debug.Assert(_weakReference.Target == null, "Animation composition chain has not been reset properly.");
      Debug.Assert(_hasSnapshot == false, "Animation composition chain has not been reset properly.");
      Debug.Assert(_traits == null, "Animation composition chain has not been reset properly.");

      if (property == null)
        throw new ArgumentNullException("property");
      if (traits == null)
        throw new ArgumentNullException("traits");

      _weakReference.Target = property;
      _traits = traits;

      var reference = (property.HasBaseValue) ? property.BaseValue : property.AnimationValue;
      traits.Create(ref reference, out _value);
    }
Exemple #5
0
 public static T Interpolate <T>(this IAnimationValueTraits <T> traits, T source, T target, float parameter)
 {
     traits.Interpolate(ref source, ref target, parameter, ref source);
     return(source);
 }
Exemple #6
0
 public static T Multiply <T>(this IAnimationValueTraits <T> traits, T value, int factor)
 {
     traits.Multiply(ref value, factor, ref value);
     return(value);
 }
Exemple #7
0
 public static T Add <T>(this IAnimationValueTraits <T> traits, T value0, T value1)
 {
     traits.Add(ref value0, ref value1, ref value0);
     return(value0);
 }
Exemple #8
0
 public static T Inverse <T>(this IAnimationValueTraits <T> traits, T value)
 {
     traits.Invert(ref value, ref value);
     return(value);
 }
Exemple #9
0
        /// <summary>
        /// Creates a new instance of the <see cref="AnimationCompositionChain{T}"/> class.
        /// </summary>
        /// <param name="property">The property that should be animated.</param>
        /// <param name="traits">The animation value traits.</param>
        /// <exception cref="ArgumentNullException">
        /// Either <paramref name="property"/> or <paramref name="traits"/> is <see langword="null"/>.
        /// </exception>
        public static AnimationCompositionChain <T> Create(IAnimatableProperty <T> property, IAnimationValueTraits <T> traits)
        {
            var compositionChain = Pool.Obtain();

            compositionChain.Initialize(property, traits);
            return(compositionChain);
        }
Exemple #10
0
    /// <summary>
    /// Gets the animation composition chain of the given animatable property and type.
    /// </summary>
    /// <typeparam name="T">The type of the property.</typeparam>
    /// <param name="property">
    /// The animatable property. Can be <see langword="null"/>.
    /// </param>
    /// <param name="traits">
    /// The animation value traits.
    /// </param>
    /// <param name="createIfNotFound">
    /// If set to <see langword="true"/> a new animation composition chain will be created 
    /// automatically when necessary. (<paramref name="property"/> must not be 
    /// <see langword="null"/>.)
    /// </param>
    /// <returns>
    /// The <see cref="IAnimationCompositionChain"/> of the animated property.
    /// </returns>
    /// <exception cref="ArgumentNullException">
    /// <paramref name="createIfNotFound"/> is set, but <paramref name="property"/> or 
    /// <paramref name="traits"/> is <see langword="null"/>.
    /// </exception>
    internal AnimationCompositionChain<T> GetCompositionChain<T>(IAnimatableProperty<T> property, IAnimationValueTraits<T> traits, bool createIfNotFound)
    {
      if (property == null)
      {
        if (createIfNotFound)
          throw new ArgumentNullException("property", "The property must not be null if a new animation composition chain should be created.");

        return null;
      }

      int index;
      IAnimationCompositionChain untypedCompositionChain;
      _compositionChains.Get(property, out index, out untypedCompositionChain);

      AnimationCompositionChain<T> compositionChain = untypedCompositionChain as AnimationCompositionChain<T>;
      if (compositionChain == null && createIfNotFound)
      {
        if (traits == null)
          throw new ArgumentNullException("traits", "The animation value traits need to be set when a new animation composition chain should be created.");

        // Create new animation composition chain.
        compositionChain = AnimationCompositionChain<T>.Create(property, traits);
        _compositionChains.Insert(index, compositionChain);
      }

      return compositionChain;
    }