Mercurial > pub > ImplabNet
view Implab.Fx/AnimationHelpers.cs @ 4:381095ad0a69
Implab.Fx: implemented animation object
Implab.Fx: implemented transparency animation helper
author | cin |
---|---|
date | Tue, 17 Sep 2013 04:27:30 +0400 |
parents | |
children | f2559580b481 |
line wrap: on
line source
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms; using System.Diagnostics; namespace Implab.Fx { public static class AnimationHelpers { public static Animation<TTarget> AnimateProperty<TTarget,TVal>(this Animation<TTarget> animation, Action<TTarget,TVal> setter, Func<TTarget,TVal> getter, TVal newValue, Func<TVal,TVal,int,int,TVal> fx) where TTarget: class { if (animation == null) throw new ArgumentNullException("animation"); TVal oldValue = getter(animation.Traget); animation.Step += (target, elaped, duration) => { var value = fx(oldValue, newValue, elaped, duration); setter(target, value); }; return animation; } public static Animation<Form> AnimateTransparency(this Form ctl, float newValue) { var anim = new Animation<Form>(ctl); anim.AnimateProperty( (target, value) => target.Opacity = value, target => target.Opacity, newValue, (ov, nv, el, du) => ov + ((float)el / du) * (nv - ov) ); return anim; } } }