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