Mercurial > pub > ImplabNet
diff Implab.Fx/AnimationHelpers.cs @ 5:f2559580b481
implemented overlay helpers and some animation heplers improvments
author | cin |
---|---|
date | Tue, 24 Sep 2013 03:31:24 +0400 |
parents | 381095ad0a69 |
children | 2fad2d1f4b03 |
line wrap: on
line diff
--- a/Implab.Fx/AnimationHelpers.cs Tue Sep 17 04:27:30 2013 +0400 +++ b/Implab.Fx/AnimationHelpers.cs Tue Sep 24 03:31:24 2013 +0400 @@ -9,7 +9,7 @@ { 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 + 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"); @@ -25,9 +25,9 @@ return animation; } - public static Animation<Form> AnimateTransparency(this Form ctl, float newValue) + public static Animation<T> AnimateTransparency<T>(this T ctl, float newValue) where T : Form { - var anim = new Animation<Form>(ctl); + var anim = new Animation<T>(ctl); anim.AnimateProperty( (target, value) => target.Opacity = value, @@ -37,5 +37,53 @@ ); return anim; } + + public static Promise<T> CloseFadeOut<T>(this T ctl) where T : Form + { + var anim = ctl.AnimateTransparency(0); + + return anim.Play().DispatchToControl(ctl).Then(frm => frm.Close()); + } + + public static Promise<T> OverlayFadeIn<T>(this Form that, T overlay) where T : Form + { + if (that == null) + throw new ArgumentNullException("that"); + if (overlay == null) + throw new ArgumentNullException("overlay"); + + // setup overlay + overlay.Opacity = 0; + overlay.FormBorderStyle = FormBorderStyle.None; + overlay.ShowInTaskbar = false; + + that.AddOwnedForm(overlay); + + EventHandler handler = (object sender, EventArgs args) => + { + overlay.Bounds = that.RectangleToScreen(that.ClientRectangle); + }; + + // attach handlers + that.Move += handler; + that.Resize += handler; + that.Shown += handler; + + // remove handlers to release overlay + overlay.FormClosed += (sender, args) => + { + that.Move -= handler; + that.Resize -= handler; + that.Shown -= handler; + }; + + overlay.Show(that); + overlay.Bounds = that.RectangleToScreen(that.ClientRectangle); + + return overlay + .AnimateTransparency(1) + .Play() + .DispatchToControl(overlay); + } } }