Example #1
0
        internal override void DoAnimation(TimelineContext context, uint timepassed)
        {
            PropertyAnimationTimelineContext patc = (PropertyAnimationTimelineContext)context;

            if (patc.DataDescriptor == null)
            {
                return;
            }
            foreach (DiscreteObjectKeyFrame key in KeyFrames)
            {
                if (key.KeyTime.TotalMilliseconds > timepassed)
                {
                    continue;
                }
                object value = key.Value;
                if (patc.DataDescriptor.Value == value)
                {
                    return;
                }
                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));
                }
                return;
            }
        }
Example #2
0
 public override bool HasEnded(TimelineContext context)
 {
   if (base.HasEnded(context))
     return true;
   TimelineGroupContext tgc = (TimelineGroupContext) context;
   return !Children.Where((t, i) => !t.HasEnded(tgc[i])).Any();
 }
        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 dist = (to - from) / duration;

            dist *= timepassed;
            dist += from;

            patc.DataDescriptor.Value = dist;
        }
Example #4
0
 public override void Start(TimelineContext context, uint timePassed)
 {
   base.Start(context, timePassed);
   TimelineGroupContext tgc = (TimelineGroupContext) context;
   for (int i = 0; i < Children.Count; i++)
     Children[i].Start(tgc[i], timePassed);
 }
 public override void Reset(TimelineContext context)
 {
     PropertyAnimationTimelineContext patc = (PropertyAnimationTimelineContext) context;
       if (patc.DataDescriptor == null)
     return;
       patc.DataDescriptor.Value = patc.OriginalValue;
 }
        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 distx = (to.X - from.X) / duration;

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

            double disty = (to.X - from.Y) / duration;

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

            SetValue(context, new Vector2((float)distx, (float)disty));
        }
        internal override void DoAnimation(TimelineContext context, uint timepassed)
        {
            PropertyAnimationTimelineContext patc = (PropertyAnimationTimelineContext)context;

            if (patc.DataDescriptor == null)
            {
                return;
            }
            double  time  = 0;
            Vector2 start = (Vector2)patc.StartValue;

            foreach (PointKeyFrame key in KeyFrames)
            {
                if (key.KeyTime.TotalMilliseconds >= timepassed)
                {
                    double progress = timepassed - time;
                    if (progress == 0)
                    {
                        patc.DataDescriptor.Value = key.Value;
                    }
                    else
                    {
                        progress /= key.KeyTime.TotalMilliseconds - time;
                        Vector2 result = key.Interpolate(start, progress);
                        patc.DataDescriptor.Value = result;
                    }
                    return;
                }
                time  = key.KeyTime.TotalMilliseconds;
                start = key.Value;
            }
        }
 public override void Start(TimelineContext context, uint timePassed)
 {
     PropertyAnimationTimelineContext patc = (PropertyAnimationTimelineContext) context;
       if (patc.DataDescriptor == null)
     return;
       patc.State = State.Idle;
       base.Start(context, timePassed);
 }
Example #9
0
 public override void Setup(TimelineContext context, IDictionary <IDataDescriptor, object> propertyConfigurations)
 {
     base.Setup(context, propertyConfigurations);
     if (KeyFrames.Count > 0)
     {
         Duration = KeyFrames[KeyFrames.Count - 1].KeyTime;
     }
 }
 internal override void DoAnimation(TimelineContext context, uint reltime)
 {
   base.DoAnimation(context, reltime);
   TimelineGroupContext tgc = (TimelineGroupContext) context;
   for (int i = 0; i < Children.Count; i++)
     // Call Animate at the children, because the children have to do their own time management
     Children[i].Animate(tgc[i], reltime);
 }
 public override void AddAllAnimatedProperties(TimelineContext context,
     IDictionary<IDataDescriptor, object> result)
 {
     PropertyAnimationTimelineContext patc = (PropertyAnimationTimelineContext) context;
       if (patc.DataDescriptor == null)
     return;
       // Morpheus_xx, 2014-11-16: TODO: there can be multiple animations affection same property. This is not yet handled correctly!
       result[patc.DataDescriptor] = patc.OriginalValue;
 }
Example #12
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 ? Color.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 distA = (to.A - from.A) / duration;

            distA *= timepassed;
            distA += from.A;

            double distR = (to.R - from.R) / duration;

            distR *= timepassed;
            distR += from.R;

            double distG = (to.G - from.G) / duration;

            distG *= timepassed;
            distG += from.G;

            double distB = (to.B - from.B) / duration;

            distB *= timepassed;
            distB += from.B;

            object value = Color.FromArgb((int)distA, (int)distR, (int)distG, (int)distB);

            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;
        }
        public override bool HasEnded(TimelineContext context)
        {
            if (base.HasEnded(context))
            {
                return(true);
            }
            TimelineGroupContext tgc = (TimelineGroupContext)context;

            return(!Children.Where((t, i) => !t.HasEnded(tgc[i])).Any());
        }
Example #14
0
        // Method Start(TimelineContext) has to be overridden in subclasses, as we don't
        // know here when to start the child timelines.

        #region Animation control methods

        public override void Stop(TimelineContext context)
        {
            base.Stop(context);
            TimelineGroupContext tgc = (TimelineGroupContext)context;

            for (int i = 0; i < Children.Count; i++)
            {
                Children[i].Stop(tgc[i]);
            }
        }
Example #15
0
        public override void AddAllAnimatedProperties(TimelineContext context,
                                                      IDictionary <IDataDescriptor, object> result)
        {
            TimelineGroupContext tgc = (TimelineGroupContext)context;

            for (int i = 0; i < Children.Count; i++)
            {
                Children[i].AddAllAnimatedProperties(tgc[i], result);
            }
        }
        public override void Start(TimelineContext context, uint timePassed)
        {
            base.Start(context, timePassed);
            TimelineGroupContext tgc = (TimelineGroupContext)context;

            for (int i = 0; i < Children.Count; i++)
            {
                Children[i].Start(tgc[i], timePassed);
            }
        }
        internal override void DoAnimation(TimelineContext context, uint reltime)
        {
            base.DoAnimation(context, reltime);
            TimelineGroupContext tgc = (TimelineGroupContext)context;

            for (int i = 0; i < Children.Count; i++)
            {
                // Call Animate at the children, because the children have to do their own time management
                Children[i].Animate(tgc[i], reltime);
            }
        }
Example #18
0
        public override TimelineContext CreateTimelineContext(UIElement element)
        {
            TimelineGroupContext result = new TimelineGroupContext(element);

            foreach (Timeline line in Children)
            {
                TimelineContext childContext = line.CreateTimelineContext(element);
                result.Add(childContext);
            }
            return(result);
        }
Example #19
0
        public override void Setup(TimelineContext context,
                                   IDictionary <IDataDescriptor, object> propertyConfigurations)
        {
            base.Setup(context, propertyConfigurations);
            TimelineGroupContext tgc = (TimelineGroupContext)context;

            for (int i = 0; i < Children.Count; i++)
            {
                Children[i].Setup(tgc[i], propertyConfigurations);
            }
        }
Example #20
0
        public override void AddAllAnimatedProperties(TimelineContext context,
                                                      IDictionary <IDataDescriptor, object> result)
        {
            PropertyAnimationTimelineContext patc = (PropertyAnimationTimelineContext)context;

            if (patc.DataDescriptor == null)
            {
                return;
            }
            result.Add(patc.DataDescriptor, patc.OriginalValue);
        }
 public override void Setup(TimelineContext context,
     IDictionary<IDataDescriptor, object> propertyConfigurations)
 {
     base.Setup(context, propertyConfigurations);
       PropertyAnimationTimelineContext patc = (PropertyAnimationTimelineContext) context;
       if (patc.DataDescriptor == null)
     return;
       object value;
       patc.OriginalValue = propertyConfigurations.TryGetValue(patc.DataDescriptor, out value) ? value :
       patc.DataDescriptor.Value;
       patc.StartValue = patc.DataDescriptor.Value;
 }
Example #22
0
 internal override void DoAnimation(TimelineContext context, uint reltime)
 {
   try
   {
     base.DoAnimation(context, reltime);
     TimelineGroupContext tgc = (TimelineGroupContext) context;
     for (int i = 0; i < Children.Count; i++)
       // Call Animate at the children, because the children have to do their own time management
       Children[i].Animate(tgc[i], reltime);
   }
   catch (Exception ex)
   {
     ServiceRegistration.Get<ILogger>().Error("Error executing animation", ex);
   }
 }
 internal override void DoAnimation(TimelineContext context, uint reltime)
 {
     try
     {
         base.DoAnimation(context, reltime);
         TimelineGroupContext tgc = (TimelineGroupContext)context;
         for (int i = 0; i < Children.Count; i++)
         {
             // Call Animate at the children, because the children have to do their own time management
             Children[i].Animate(tgc[i], reltime);
         }
     }
     catch (Exception ex)
     {
         ServiceRegistration.Get <ILogger>().Error("Error executing animation", ex);
     }
 }
        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;
        }
Example #25
0
        internal override void Ended(TimelineContext context)
        {
            base.Ended(context);
            TimelineGroupContext tgc = (TimelineGroupContext)context;

            for (int i = 0; i < Children.Count; i++)
            {
                Timeline        child        = Children[i];
                TimelineContext childContext = tgc[i];
                if (child.FillBehavior == Animations.FillBehavior.Stop)
                {
                    child.Stop(childContext);
                }
                else
                {
                    child.Ended(childContext);
                }
            }
        }
Example #26
0
        internal override void DoAnimation(TimelineContext context, uint timepassed)
        {
            PropertyAnimationTimelineContext patc = (PropertyAnimationTimelineContext)context;

            if (patc.DataDescriptor == null)
            {
                return;
            }
            double time  = 0;
            Color  start = ColorAnimation.ConvertToColor(patc.StartValue);

            foreach (ColorKeyFrame key in KeyFrames)
            {
                if (key.KeyTime.TotalMilliseconds >= timepassed)
                {
                    double progress = timepassed - time;
                    object value;
                    if (progress == 0)
                    {
                        value = key.Value;
                    }
                    else
                    {
                        progress /= key.KeyTime.TotalMilliseconds - time;
                        Color result = key.Interpolate(start, progress);
                        value = result;
                    }
                    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));
                    }
                    return;
                }
                time  = key.KeyTime.TotalMilliseconds;
                start = key.Value;
            }
        }
        protected Vector2 GetValue(TimelineContext context)
        {
            PropertyAnimationTimelineContext patc = (PropertyAnimationTimelineContext)context;

            if (patc.DataDescriptor == null)
            {
                return(new Vector2(0, 0));
            }
            object o = patc.DataDescriptor.Value;

            if (o.GetType() == typeof(Vector2))
            {
                return((Vector2)o);
            }
            if (o.GetType() == typeof(Vector3))
            {
                Vector3 v = (Vector3)o;
                return(new Vector2(v.X, v.Y));
            }
            return(new Vector2(0, 0));
        }
        protected static void SetValue(TimelineContext context, Vector2 vector)
        {
            PropertyAnimationTimelineContext patc = (PropertyAnimationTimelineContext)context;

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

            if (o.GetType() == typeof(Vector2))
            {
                patc.DataDescriptor.Value = vector;
                return;
            }
            if (o.GetType() == typeof(Vector3))
            {
                Vector3 v = new Vector3(vector.X, vector.Y, ((Vector3)o).Z);
                patc.DataDescriptor.Value = v;
                return;
            }
        }
 public override void Start(TimelineContext context, uint timePassed)
 {
   PropertyAnimationTimelineContext patc = (PropertyAnimationTimelineContext) context;
   if (patc.DataDescriptor == null)
     return;
   patc.State = State.Idle;
   base.Start(context, timePassed);
 }
 protected static void SetValue(TimelineContext context,Vector2 vector)
 {
   PropertyAnimationTimelineContext patc = (PropertyAnimationTimelineContext) context;
   if (patc.DataDescriptor == null) return;
   object o = patc.DataDescriptor.Value;
   if (o.GetType() == typeof(Vector2))
   {
     patc.DataDescriptor.Value = vector;
     return;
   }
   if (o.GetType() == typeof(Vector3))
   {
     Vector3 v = new Vector3(vector.X, vector.Y, ((Vector3)o).Z);
     patc.DataDescriptor.Value = v;
     return;
   }
 }
Example #31
0
 /// <summary>
 /// Will be called if this timeline was started.
 /// </summary>
 /// <param name="context">Current animation context.</param>
 /// <param name="timePassed">The time counter for this animation. All further
 /// time values will be relative to this specified time.</param>
 internal virtual void Started(TimelineContext context, uint timePassed)
 {
   context.TimeStarted = timePassed;
   context.State = State.WaitBegin;
   DoAnimation(context, 0);
 }
Example #32
0
 /// <summary>
 /// Gets a value indicating whether this timeline was stopped.
 /// </summary>
 /// <param name="context">Current animation context.</param>
 /// <returns>
 /// <c>true</c> if this animation was stopped; otherwise, <c>false</c>.
 /// </returns>
 public bool IsStopped(TimelineContext context)
 {
     return(context.State == State.Idle);
 }
Example #33
0
 /// <summary>
 /// Sets up the specified <paramref name="context"/> object with all necessary
 /// values for this timeline.
 /// </summary>
 /// <param name="context">The animation context.</param>
 /// <param name="propertyConfigurations">Data descriptors which were animated by a
 /// predecessor animation, mapped to their original values.
 /// The original value for all data descriptors contained in this map should be
 /// initialized with the mapped value instead of the current value.</param>
 public virtual void Setup(TimelineContext context, IDictionary<IDataDescriptor, object> propertyConfigurations)
 {
   context.State = State.Setup;
 }
Example #34
0
    /// <summary>
    /// Entry method to execute the animation. This method will evaluate all
    /// animation control properties defined in this class, calculate a value for the internal
    /// time counter and delegate to method <see cref="DoAnimation(TimelineContext,uint)"/>.
    /// </summary>
    public void Animate(TimelineContext context, uint timePassed)
    {
      uint passed = (timePassed - context.TimeStarted);

      switch (context.State)
      {
        case State.WaitBegin:
          if (passed >= BeginTime.TotalMilliseconds)
          {
            passed = 0;
            context.TimeStarted = timePassed;
            context.State = State.Running;
            goto case State.Running;
          }
          break;

        case State.Running:
          if (!DurationSet)
          {
            DoAnimation(context, passed);
            if (HasEnded(context)) // Check the state of the children and propagate it to this timeline
              if (FillBehavior == FillBehavior.Stop)
                Stop(context);
              else
                Ended(context);
          }
          else if (passed < Duration.TotalMilliseconds)
          {
            DoAnimation(context, passed);
          }
          else
          {
            if (AutoReverse)
            {
              context.State = State.Reverse;
              context.TimeStarted = timePassed;
              passed = 0;
              goto case State.Reverse;
            }
            if (RepeatBehavior == RepeatBehavior.Forever)
            {
              context.TimeStarted = timePassed;
              DoAnimation(context, timePassed - context.TimeStarted);
            }
            else
            {
              DoAnimation(context, (uint) Duration.TotalMilliseconds);
              if (FillBehavior == FillBehavior.Stop)
                Stop(context);
              else
                Ended(context);
            }
          }
          break;

        case State.Reverse:
          if (!DurationSet)
            Ended(context); // This is an error case - we cannot reverse if we don't know at which point in time
          if (passed < Duration.TotalMilliseconds)
            DoAnimation(context, (uint) (Duration.TotalMilliseconds - passed));
          else
          {
            if (RepeatBehavior == RepeatBehavior.Forever)
            {
              context.State = State.Running;
              context.TimeStarted = timePassed;
              DoAnimation(context, timePassed - context.TimeStarted);
            }
            else
            {
              DoAnimation(context, 0);
              if (FillBehavior == FillBehavior.Stop)
                Stop(context);
              else
                Ended(context);
            }
          }
          break;
        case State.Ended:
          DoAnimation(context, passed);
          break;
      }
    }
    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 distx = (to.X - from.X) / duration;
      distx *= timepassed;
      distx += from.X;

      double disty = (to.X - from.Y) / duration;
      disty *= timepassed;
      disty += from.Y;

      SetValue(context, new Vector2((float) distx, (float) disty));
    }
Example #36
0
 public virtual void Finish(TimelineContext context)
 {
   Ended(context);
 }
 public override void AddAllAnimatedProperties(TimelineContext context,
     IDictionary<IDataDescriptor, object> result)
 {
   PropertyAnimationTimelineContext patc = (PropertyAnimationTimelineContext) context;
   if (patc.DataDescriptor == null)
     return;
   // Morpheus_xx, 2014-11-16: TODO: there can be multiple animations affection same property. This is not yet handled correctly!
   result[patc.DataDescriptor] = patc.OriginalValue;
 }
Example #38
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;
      }

      float progress = timepassed / (float)duration;
      object value = Color.SmoothStep(from, to, 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;
    }
    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 dist = (to - from) / duration;
      dist *= timepassed;
      dist += from;

      patc.DataDescriptor.Value = dist;
    }
    protected Vector2 GetValue(TimelineContext context)
    {
      PropertyAnimationTimelineContext patc = (PropertyAnimationTimelineContext) context;
      if (patc.DataDescriptor == null) return new Vector2(0, 0);
      object o = patc.DataDescriptor.Value;
      if (o.GetType() == typeof(Vector2)) return (Vector2) o;
      if (o.GetType() == typeof(Vector3))
      {
        Vector3 v = (Vector3) o;
        return new Vector2(v.X, v.Y);
      }
      return new Vector2(0, 0);

    }
Example #41
0
 /// <summary>
 /// Gets a value indicating whether this timeline has ended.
 /// This method will will be overridden by composed timelines where the result
 /// will depend on their composition parts.
 /// </summary>
 /// <param name="context">Current animation context.</param>
 /// <returns>
 /// <c>true</c> if this animation has ended; otherwise, <c>false</c>.
 /// </returns>
 public virtual bool HasEnded(TimelineContext context)
 {
     return(context.State == State.Ended);
 }
Example #42
0
 /// <summary>
 /// Starts this animation and initializes the time counter for this animation.
 /// </summary>
 /// <remarks>
 /// For a normal operation, method <see cref="Animate(TimelineContext,uint)"/>
 /// should be called frequently, until method <see cref="IsStopped"/>
 /// returns true. After that, method <see cref="Stop(TimelineContext)"/> has
 /// to be called to correctly restore animation property values and to set the
 /// animation's final state.
 /// </remarks>
 public virtual void Start(TimelineContext context, uint timePassed)
 {
   Started(context, timePassed);
 }
Example #43
0
 /// <summary>
 /// Will be called if this timeline was started.
 /// </summary>
 /// <param name="context">Current animation context.</param>
 /// <param name="timePassed">The time counter for this animation. All further
 /// time values will be relative to this specified time.</param>
 internal virtual void Started(TimelineContext context, uint timePassed)
 {
     context.TimeStarted = timePassed;
     context.State       = State.WaitBegin;
     DoAnimation(context, 0);
 }
Example #44
0
 public virtual void Stop(TimelineContext context)
 {
   Reset(context);
   context.State = State.Idle;
 }
Example #45
0
 /// <summary>
 /// Gets a value indicating whether this timeline was stopped.
 /// </summary>
 /// <param name="context">Current animation context.</param>
 /// <returns>
 /// <c>true</c> if this animation was stopped; otherwise, <c>false</c>.
 /// </returns>
 public bool IsStopped(TimelineContext context)
 {
   return context.State == State.Idle;
 }
Example #46
0
 /// <summary>
 /// Adds the descriptors for all properties which are animated by this animation and
 /// by sub animations mapped to their original value to the specified
 /// <paramref name="result"/> parameter.
 /// </summary>
 /// <param name="context">The animation context.</param>
 /// <param name="result">Dictionary to add all animated properties mapped to their original
 /// values from this animation.</param>
 public abstract void AddAllAnimatedProperties(TimelineContext context, IDictionary<IDataDescriptor, object> result);
Example #47
0
 /// <summary>
 /// Will do the real work of animating the underlaying property.
 /// </summary>
 /// <remarks>
 /// The animation progress should be calculated to the specified relative
 /// time. It is not necessary to evaluate time overflows or to revert
 /// the animation depending on properties; these calculations have been
 /// done before this method will be called and will be reflected in the
 /// <paramref name="reltime"/> parameter.
 /// </remarks>
 /// <param name="context">Current animation context.</param>
 /// <param name="reltime">This parameter holds the relative animation time in
 /// milliseconds from the <see cref="BeginTime"/> on, up to a maximum value
 /// of Duration.Milliseconds.</param>
 internal virtual void DoAnimation(TimelineContext context, uint reltime)
 {
 }
Example #48
0
 /// <summary>
 /// Will restore the original values in all properties which have been animated
 /// by this timeline.
 /// </summary>
 /// <param name="context">Current animation context.</param>
 public virtual void Reset(TimelineContext context)
 { }
Example #49
0
        /// <summary>
        /// Entry method to execute the animation. This method will evaluate all
        /// animation control properties defined in this class, calculate a value for the internal
        /// time counter and delegate to method <see cref="DoAnimation(TimelineContext,uint)"/>.
        /// </summary>
        public void Animate(TimelineContext context, uint timePassed)
        {
            try
            {
                uint passed = (timePassed - context.TimeStarted);

                switch (context.State)
                {
                case State.WaitBegin:
                    if (passed >= BeginTime.TotalMilliseconds)
                    {
                        passed = 0;
                        context.TimeStarted = timePassed;
                        context.State       = State.Running;
                        goto case State.Running;
                    }
                    break;

                case State.Running:
                    if (!DurationSet)
                    {
                        DoAnimation(context, passed);
                        if (HasEnded(context)) // Check the state of the children and propagate it to this timeline
                        {
                            if (FillBehavior == FillBehavior.Stop)
                            {
                                Stop(context);
                            }
                            else
                            {
                                Ended(context);
                            }
                        }
                    }
                    else if (passed < Duration.TotalMilliseconds)
                    {
                        DoAnimation(context, passed);
                    }
                    else
                    {
                        if (AutoReverse)
                        {
                            context.State       = State.Reverse;
                            context.TimeStarted = timePassed;
                            passed = 0;
                            goto case State.Reverse;
                        }
                        if (RepeatBehavior == RepeatBehavior.Forever)
                        {
                            context.TimeStarted = timePassed;
                            DoAnimation(context, timePassed - context.TimeStarted);
                        }
                        else
                        {
                            DoAnimation(context, (uint)Duration.TotalMilliseconds);
                            if (FillBehavior == FillBehavior.Stop)
                            {
                                Stop(context);
                            }
                            else
                            {
                                Ended(context);
                            }
                        }
                    }
                    break;

                case State.Reverse:
                    if (!DurationSet)
                    {
                        Ended(context); // This is an error case - we cannot reverse if we don't know at which point in time
                    }
                    if (passed < Duration.TotalMilliseconds)
                    {
                        DoAnimation(context, (uint)(Duration.TotalMilliseconds - passed));
                    }
                    else
                    {
                        if (RepeatBehavior == RepeatBehavior.Forever)
                        {
                            context.State       = State.Running;
                            context.TimeStarted = timePassed;
                            DoAnimation(context, timePassed - context.TimeStarted);
                        }
                        else
                        {
                            DoAnimation(context, 0);
                            if (FillBehavior == FillBehavior.Stop)
                            {
                                Stop(context);
                            }
                            else
                            {
                                Ended(context);
                            }
                        }
                    }
                    break;

                case State.Ended:
                    DoAnimation(context, passed);
                    break;
                }
            }
            catch (Exception ex)
            {
                ServiceRegistration.Get <ILogger>().Error("Error executing animation", ex);
            }
        }
Example #50
0
 /// <summary>
 /// Will do the real work of animating the underlaying property.
 /// </summary>
 /// <remarks>
 /// The animation progress should be calculated to the specified relative
 /// time. It is not necessary to evaluate time overflows or to revert
 /// the animation depending on properties; these calculations have been
 /// done before this method will be called and will be reflected in the
 /// <paramref name="reltime"/> parameter. 
 /// </remarks>
 /// <param name="context">Current animation context.</param>
 /// <param name="reltime">This parameter holds the relative animation time in
 /// milliseconds from the <see cref="BeginTime"/> on, up to a maximum value
 /// of Duration.Milliseconds.</param>
 internal virtual void DoAnimation(TimelineContext context, uint reltime)
 { }
 public override void AddAllAnimatedProperties(TimelineContext context,
     IDictionary<IDataDescriptor, object> result)
 {
   PropertyAnimationTimelineContext patc = (PropertyAnimationTimelineContext) context;
   if (patc.DataDescriptor == null)
     return;
   result.Add(patc.DataDescriptor, patc.OriginalValue);
 }
Example #52
0
 /// <summary>
 /// Will be called if this timeline has finished or was stopped.
 /// </summary>
 /// <param name="context">Current animation context.</param>
 internal virtual void Ended(TimelineContext context)
 {
   context.State = State.Ended;
 }
Example #53
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 ? Color.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 distA = (to.A - from.A) / duration;
      distA *= timepassed;
      distA += from.A;

      double distR = (to.R - from.R) / duration;
      distR *= timepassed;
      distR += from.R;

      double distG = (to.G - from.G) / duration;
      distG *= timepassed;
      distG += from.G;

      double distB = (to.B - from.B) / duration;
      distB *= timepassed;
      distB += from.B;

      object value = Color.FromArgb((int) distA, (int) distR, (int) distG, (int) distB);
      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;
    }
Example #54
0
 /// <summary>
 /// Gets a value indicating whether this timeline has ended.
 /// This method will will be overridden by composed timelines where the result
 /// will depend on their composition parts.
 /// </summary>
 /// <param name="context">Current animation context.</param>
 /// <returns>
 /// <c>true</c> if this animation has ended; otherwise, <c>false</c>.
 /// </returns>
 public virtual bool HasEnded(TimelineContext context)
 {
   return context.State == State.Ended;
 }
 public override void Reset(TimelineContext context)
 {
   PropertyAnimationTimelineContext patc = (PropertyAnimationTimelineContext) context;
   if (patc.DataDescriptor == null)
     return;
   patc.DataDescriptor.Value = patc.OriginalValue;
 }
Example #56
0
 /// <summary>
 /// Will be called if this timeline has finished or was stopped.
 /// </summary>
 /// <param name="context">Current animation context.</param>
 internal virtual void Ended(TimelineContext context)
 {
     context.State = State.Ended;
 }
 public override void Setup(TimelineContext context,
     IDictionary<IDataDescriptor, object> propertyConfigurations)
 {
   base.Setup(context, propertyConfigurations);
   PropertyAnimationTimelineContext patc = (PropertyAnimationTimelineContext) context;
   if (patc.DataDescriptor == null)
     return;
   object value;
   patc.OriginalValue = propertyConfigurations.TryGetValue(patc.DataDescriptor, out value) ? value :
       patc.DataDescriptor.Value;
   patc.StartValue = patc.DataDescriptor.Value;
 }