Mercurial > pub > ImplabNet
annotate Implab.Fx/AnimationHelpers.cs @ 74:c4140283575c v2
minor fixes
author | cin |
---|---|
date | Mon, 08 Sep 2014 17:40:46 +0400 |
parents | 2fad2d1f4b03 |
children | d4e38929ce36 |
rev | line source |
---|---|
4 | 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 { | |
5
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
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 |
4 | 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 | |
5
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
28 public static Animation<T> AnimateTransparency<T>(this T ctl, float newValue) where T : Form |
4 | 29 { |
5
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
30 var anim = new Animation<T>(ctl); |
4 | 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 } | |
5
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
40 |
30 | 41 public static IPromise<T> CloseFadeOut<T>(this T ctl) where T : Form |
5
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
42 { |
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
43 var anim = ctl.AnimateTransparency(0); |
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
44 |
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
45 return anim.Play().DispatchToControl(ctl).Then(frm => frm.Close()); |
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
46 } |
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
47 |
30 | 48 public static IPromise<T> OverlayFadeIn<T>(this Form that, T overlay) where T : Form |
5
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
49 { |
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
50 if (that == null) |
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
51 throw new ArgumentNullException("that"); |
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
52 if (overlay == null) |
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
53 throw new ArgumentNullException("overlay"); |
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
54 |
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
55 // setup overlay |
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
56 overlay.Opacity = 0; |
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
57 overlay.FormBorderStyle = FormBorderStyle.None; |
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
58 overlay.ShowInTaskbar = false; |
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
59 |
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
60 that.AddOwnedForm(overlay); |
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
61 |
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
62 EventHandler handler = (object sender, EventArgs args) => |
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
63 { |
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
64 overlay.Bounds = that.RectangleToScreen(that.ClientRectangle); |
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
65 }; |
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
66 |
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
67 // attach handlers |
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
68 that.Move += handler; |
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
69 that.Resize += handler; |
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
70 that.Shown += handler; |
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
71 |
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
72 // remove handlers to release overlay |
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
73 overlay.FormClosed += (sender, args) => |
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
74 { |
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
75 that.Move -= handler; |
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
76 that.Resize -= handler; |
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
77 that.Shown -= handler; |
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
78 }; |
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
79 |
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
80 overlay.Show(that); |
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
81 overlay.Bounds = that.RectangleToScreen(that.ClientRectangle); |
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
82 |
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
83 return overlay |
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
84 .AnimateTransparency(1) |
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
85 .Play() |
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
86 .DispatchToControl(overlay); |
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
87 } |
4 | 88 } |
89 } |