##// END OF EJS Templates
Implab.Fx: implemented animation object...
Implab.Fx: implemented animation object Implab.Fx: implemented transparency animation helper

File last commit:

r4:381095ad0a69 default
r4:381095ad0a69 default
Show More
AnimationHelpers.cs
41 lines | 1.3 KiB | text/x-csharp | CSharpLexer
cin
Implab.Fx: implemented animation object...
r4 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;
}
}
}