Mercurial > pub > ImplabNet
annotate Implab.Fx/AnimationHelpers.cs @ 223:27ea7f07e2e4 default
Слияние
| author | cin |
|---|---|
| date | Tue, 22 Aug 2017 09:35:54 +0300 |
| parents | d4e38929ce36 |
| children |
| 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 |
| 106 | 45 return anim |
| 46 .Play() | |
| 47 .DispatchToControl(ctl) | |
| 48 .Then(frm => { | |
| 49 frm.Close(); | |
| 50 return frm; | |
| 51 }); | |
|
5
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
52 } |
|
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
53 |
| 30 | 54 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
|
55 { |
|
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
56 if (that == null) |
|
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
57 throw new ArgumentNullException("that"); |
|
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
58 if (overlay == null) |
|
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
59 throw new ArgumentNullException("overlay"); |
|
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
60 |
|
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
61 // setup overlay |
|
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
62 overlay.Opacity = 0; |
|
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
63 overlay.FormBorderStyle = FormBorderStyle.None; |
|
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
64 overlay.ShowInTaskbar = false; |
|
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 that.AddOwnedForm(overlay); |
|
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
67 |
|
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
68 EventHandler handler = (object sender, EventArgs args) => |
|
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
69 { |
|
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
70 overlay.Bounds = that.RectangleToScreen(that.ClientRectangle); |
|
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 |
|
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
73 // attach handlers |
|
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
74 that.Move += handler; |
|
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
75 that.Resize += handler; |
|
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
76 that.Shown += handler; |
|
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
77 |
|
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
78 // remove handlers to release overlay |
|
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
79 overlay.FormClosed += (sender, args) => |
|
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
80 { |
|
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
81 that.Move -= handler; |
|
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
82 that.Resize -= handler; |
|
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
83 that.Shown -= handler; |
|
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
84 }; |
|
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
85 |
|
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
86 overlay.Show(that); |
|
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
87 overlay.Bounds = that.RectangleToScreen(that.ClientRectangle); |
|
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
88 |
|
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
89 return overlay |
|
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
90 .AnimateTransparency(1) |
|
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
91 .Play() |
|
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
92 .DispatchToControl(overlay); |
|
f2559580b481
implemented overlay helpers and some animation heplers improvments
cin
parents:
4
diff
changeset
|
93 } |
| 4 | 94 } |
| 95 } |
