/// <summary> /// Animates the current control with some values. /// </summary> /// <param name="c">The control to animate.</param> /// <param name="properties">The anonymous object with name / value pairs.</param> /// <param name="duration">The duration of the animation.</param> /// <param name="easing">The Easing object to use.</param> /// <param name="complete">The callback method to invoke when the animation is finished.</param> public static void Animate(this Control c, object properties, int duration, Easing easing, Action complete) { var t = new Timer(); t.Interval = 30; var frame = 0; var maxframes = (int)Math.Ceiling(duration / 30.0); var reflection = properties.GetType(); var target = c.GetType(); var props = reflection.GetProperties(); var values = new ReflectionCache[props.Length]; for (int i = 0; i < props.Length; i++) { values[i] = new ReflectionCache(target.GetProperty(props[i].Name)); values[i].SetStart(values[i].Info.GetValue(c, null)); values[i].SetEnd(props[i].GetValue(properties, null)); } t.Tick += (s, e) => { frame++; for (int i = 0; i < values.Length; i++) { values[i].Execute(c, easing, frame, maxframes); } if (frame == maxframes) { t.Stop(); if (complete != null) complete(); } }; t.Start(); }
/// <summary> /// Animates the current control with some values. /// </summary> /// <param name="c">The control to animate.</param> /// <param name="properties">The anonymous object with name / value pairs.</param> /// <param name="duration">The duration of the animation.</param> /// <param name="easing">The Easing object to use.</param> public static void Animate(this Control c, object properties, int duration, Easing easing) { Animate(c, properties, duration, easing, null); }
public void Execute(object c, Easing easing, int frame, int frames) { if (HasItems) { var cp = Activator.CreateInstance(ListType); foreach (var item in SubList) { item.Execute(cp, easing, frame, frames); } Info.SetValue(c, cp, null); } else { var value = easing.CalculateStep(frame, frames, Start, End); this.SetValue(c, value); } }