diff --git a/samples/RenderTest/SideBar.xaml b/samples/RenderTest/SideBar.xaml index 3013c5a80e..f11f37bfa5 100644 --- a/samples/RenderTest/SideBar.xaml +++ b/samples/RenderTest/SideBar.xaml @@ -32,8 +32,17 @@ + + + + + + + diff --git a/src/Avalonia.Animation/Animatable.cs b/src/Avalonia.Animation/Animatable.cs index 1a187a3521..0cc7cc416c 100644 --- a/src/Avalonia.Animation/Animatable.cs +++ b/src/Avalonia.Animation/Animatable.cs @@ -13,35 +13,24 @@ namespace Avalonia.Animation /// public class Animatable : AvaloniaObject { - - private Transitions _transitions; + /// + /// + /// + public static readonly StyledProperty TransitionsProperty = + AvaloniaProperty.Register(nameof(Transitions)); /// /// Gets or sets the property transitions for the control. /// public Transitions Transitions { - get - { - return _transitions ?? (_transitions = new Transitions()); - } - - set - { - SetAndRaise(TransitionsProperty, ref _transitions, value); - } + get { return GetValue(TransitionsProperty); } + set { SetValue(TransitionsProperty, value); } } - /// - /// Gets or sets the property transitions for the control. - /// - public static readonly DirectProperty TransitionsProperty = - AvaloniaProperty.RegisterDirect(nameof(Transitions), o => o.Transitions); - /// /// Reacts to a change in a value in - /// order to animate the change if a - /// is set for the property. + /// order to animate the change if a is set for the property. /// /// The event args. protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs e) @@ -50,65 +39,12 @@ namespace Avalonia.Animation { var match = Transitions.FirstOrDefault(x => x.Property == e.Property); - if (match != null) { - - // //BindAnimateProperty(this, e.Property, e.OldValue, e.NewValue, match.Easing, match.Duration); + match.Apply(this, e.OldValue, e.NewValue); } } } - ///// - ///// Animates a . - ///// - ///// The target object. - ///// The target property. - ///// The value of the property at the start of the animation. - ///// The value of the property at the end of the animation. - ///// The easing function to use. - ///// The duration of the animation. - ///// An that can be used to track or stop the animation. - //public static Animation BindAnimateProperty( - // IAvaloniaObject target, - // AvaloniaProperty property, - // object start, - // object finish, - // IEasing easing, - // TimeSpan duration) - //{ - // var k = start.GetType(); - // if (k == typeof(double)) - // { - // var o = Timing.GetTimer(duration).Select(progress => easing.Ease(progress, start, finish)); - // return new Animation(o, target.Bind(property, o, BindingPriority.Animation)); - // } - // else - // return null; - //} - - ///// - ///// Animates a . - ///// - ///// The property type. - ///// The target object. - ///// The target property. - ///// The value of the property at the start of the animation. - ///// The value of the property at the end of the animation. - ///// The easing function to use. - ///// The duration of the animation. - ///// An that can be used to track or stop the animation. - //public static Animation Property( - // IAvaloniaObject target, - // AvaloniaProperty property, - // T start, - // T finish, - // IEasing easing, - // TimeSpan duration) - //{ - // var o = Timing.GetTimer(duration).Select(progress => easing.Ease(progress, start, finish)); - // return new Animation(o, target.Bind(property, o, BindingPriority.Animation)); - //} - } } diff --git a/src/Avalonia.Animation/Transitions/DoubleTransition.cs b/src/Avalonia.Animation/Transitions/DoubleTransition.cs index fbe164aa90..a4cb255545 100644 --- a/src/Avalonia.Animation/Transitions/DoubleTransition.cs +++ b/src/Avalonia.Animation/Transitions/DoubleTransition.cs @@ -3,6 +3,7 @@ using Avalonia.Metadata; using System; +using System.Reactive.Linq; namespace Avalonia.Animation { @@ -12,21 +13,14 @@ namespace Avalonia.Animation public class DoubleTransition : Transition { /// - public DoubleTransition() : base() + public override void DoInterpolation(Animatable control, IObservable progress, double oldValue, double newValue) { - - } - - /// - public override AvaloniaProperty Property { get; set; } - - /// - public override void Apply(Animatable control) - { - //throw new NotImplementedException(); - - - + var delta = newValue - oldValue; + var transition = progress.Select(p => + { + return Easing.Ease(p) * delta + oldValue; + }); + control.Bind(Property, transition.Select(p=>(object)p), Data.BindingPriority.Animation); } } } diff --git a/src/Avalonia.Animation/Transitions/Transition.cs b/src/Avalonia.Animation/Transitions/Transition.cs index 1a91f4caf0..4232a1214f 100644 --- a/src/Avalonia.Animation/Transitions/Transition.cs +++ b/src/Avalonia.Animation/Transitions/Transition.cs @@ -11,13 +11,14 @@ namespace Avalonia.Animation /// /// Applies the transition to the specified . /// - /// - void Apply(Animatable control); + void Apply(Animatable control, object oldValue, object newValue); /// /// Gets the property to be animated. /// AvaloniaProperty Property { get; set; } + + } /// @@ -29,29 +30,41 @@ namespace Avalonia.Animation /// Gets the duration of the animation. /// public TimeSpan Duration { get; set; } - + /// - /// Instantiates the base abstract class . + /// Gets the easing class to be used. /// - public Transition() + public IEasing Easing { get; set; } + + private AvaloniaProperty _prop; + + /// + public AvaloniaProperty Property { - if(!(typeof(T) == Property.PropertyType)) + get { - throw new InvalidCastException - ($"Invalid property type {typeof(T).Name} for this {this.GetType().Name}"); + return _prop; + } + set + { + if (!(typeof(T) == value.PropertyType)) + throw new InvalidCastException + ($"Invalid property type {typeof(T).Name} for this {GetType().Name}"); + + _prop = value; } } /// - /// Gets the easing class to be used. + /// Apply interpolation to the property. /// - public IEasing Easing { get; set; } + public abstract void DoInterpolation(Animatable control, IObservable progress, T oldValue, T newValue); /// - public abstract AvaloniaProperty Property { get; set; } - - /// - public abstract void Apply(Animatable control); + public void Apply(Animatable control, object oldValue, object newValue) + { + DoInterpolation(control, Timing.GetTimer(Duration), (T)oldValue, (T)newValue); + } } diff --git a/src/Avalonia.Visuals/Animation/PageSlide.cs b/src/Avalonia.Visuals/Animation/PageSlide.cs index 3218ed1e67..483bb2b44d 100644 --- a/src/Avalonia.Visuals/Animation/PageSlide.cs +++ b/src/Avalonia.Visuals/Animation/PageSlide.cs @@ -76,8 +76,8 @@ namespace Avalonia.Animation if (from != null) { - var transform = new TranslateTransform(); - from.RenderTransform = transform; + //var transform = new TranslateTransform(); + //from.RenderTransform = transform; //tasks.Add(Animate.Property( // transform, // translateProperty, @@ -89,8 +89,8 @@ namespace Avalonia.Animation if (to != null) { - var transform = new TranslateTransform(); - to.RenderTransform = transform; + //var transform = new TranslateTransform(); + //to.RenderTransform = transform; to.IsVisible = true; //tasks.Add(Animate.Property( // transform, diff --git a/src/Markup/Avalonia.Markup.Xaml/PortableXaml/AvaloniaDefaultTypeConverters.cs b/src/Markup/Avalonia.Markup.Xaml/PortableXaml/AvaloniaDefaultTypeConverters.cs index bde9a8d766..5f0f8d8d46 100644 --- a/src/Markup/Avalonia.Markup.Xaml/PortableXaml/AvaloniaDefaultTypeConverters.cs +++ b/src/Markup/Avalonia.Markup.Xaml/PortableXaml/AvaloniaDefaultTypeConverters.cs @@ -49,6 +49,7 @@ namespace Avalonia.Markup.Xaml.PortableXaml { typeof(Cursor), typeof(CursorTypeConverter) }, { typeof(WindowIcon), typeof(IconTypeConverter) }, { typeof(Easing), typeof(EasingTypeConverter) }, + { typeof(IEasing), typeof(EasingTypeConverter) }, //{ typeof(FontWeight), typeof(FontWeightConverter) }, };