comparison 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
comparison
equal deleted inserted replaced
3:1e9583086e99 4:381095ad0a69
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Windows.Forms;
6 using System.Diagnostics;
7
8 namespace Implab.Fx
9 {
10 public static class AnimationHelpers
11 {
12 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
13 {
14 if (animation == null)
15 throw new ArgumentNullException("animation");
16
17 TVal oldValue = getter(animation.Traget);
18
19 animation.Step += (target, elaped, duration) =>
20 {
21 var value = fx(oldValue, newValue, elaped, duration);
22 setter(target, value);
23 };
24
25 return animation;
26 }
27
28 public static Animation<Form> AnimateTransparency(this Form ctl, float newValue)
29 {
30 var anim = new Animation<Form>(ctl);
31
32 anim.AnimateProperty(
33 (target, value) => target.Opacity = value,
34 target => target.Opacity,
35 newValue,
36 (ov, nv, el, du) => ov + ((float)el / du) * (nv - ov)
37 );
38 return anim;
39 }
40 }
41 }