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;
            }
        }
        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 #3
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;
            }
        }
        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;
        }
 public override void Reset(TimelineContext context)
 {
     PropertyAnimationTimelineContext patc = (PropertyAnimationTimelineContext) context;
       if (patc.DataDescriptor == null)
     return;
       patc.DataDescriptor.Value = patc.OriginalValue;
 }
 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 #7
0
        public override TimelineContext CreateTimelineContext(UIElement element)
        {
            PropertyAnimationTimelineContext result = new PropertyAnimationTimelineContext(element)
            {
                DataDescriptor = GetDataDescriptor(element)
            };

            return(result);
        }
 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;
 }
        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 #10
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;
 }
        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 #13
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 TimelineContext CreateTimelineContext(UIElement element)
 {
   PropertyAnimationTimelineContext result = new PropertyAnimationTimelineContext(element)
     {DataDescriptor = GetDataDescriptor(element)};
   return result;
 }