Browse Source

*Added numerical transition classes.

*Disabled old animations code in CrossFade, PageSlide, CarouselPresenter and ProgressBar.
pull/1461/head
Jumar Macato 9 years ago
parent
commit
fe66f3837e
  1. 11
      src/Avalonia.Animation/Transitions/DoubleTransition.cs
  2. 23
      src/Avalonia.Animation/Transitions/FloatTransition.cs
  3. 26
      src/Avalonia.Animation/Transitions/ITransition.cs
  4. 23
      src/Avalonia.Animation/Transitions/IntegerTransition.cs
  5. 25
      src/Avalonia.Animation/Transitions/Transition.cs
  6. 2
      src/Avalonia.Controls/Presenters/CarouselPresenter.cs
  7. 38
      src/Avalonia.Controls/ProgressBar.cs
  8. 3
      src/Avalonia.Visuals/Animation/CrossFade.cs
  9. 3
      src/Avalonia.Visuals/Animation/PageSlide.cs

11
src/Avalonia.Animation/Transitions/DoubleTransition.cs

@ -8,19 +8,16 @@ using System.Reactive.Linq;
namespace Avalonia.Animation
{
/// <summary>
/// Transitions object that handles properties with <see cref="double"/> types.
/// Transition class that handles <see cref="AvaloniaProperty"/> with <see cref="double"/> types.
/// </summary>
public class DoubleTransition : Transition<double>
{
/// <inheritdocs/>
public override void DoInterpolation(Animatable control, IObservable<double> progress, double oldValue, double newValue)
public override IObservable<double> DoInterpolation(IObservable<double> progress, double oldValue, double newValue)
{
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);
return progress
.Select(p => Easing.Ease(p) * delta + oldValue);
}
}
}

23
src/Avalonia.Animation/Transitions/FloatTransition.cs

@ -0,0 +1,23 @@
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using Avalonia.Metadata;
using System;
using System.Reactive.Linq;
namespace Avalonia.Animation
{
/// <summary>
/// Transition class that handles <see cref="AvaloniaProperty"/> with <see cref="float"/> types.
/// </summary>
public class FloatTransition : Transition<float>
{
/// <inheritdocs/>
public override IObservable<float> DoInterpolation(IObservable<double> progress, float oldValue, float newValue)
{
var delta = newValue - oldValue;
return progress
.Select(p => (float)Easing.Ease(p) * delta + oldValue);
}
}
}

26
src/Avalonia.Animation/Transitions/ITransition.cs

@ -0,0 +1,26 @@
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using Avalonia.Metadata;
using System;
using System.Reactive.Linq;
namespace Avalonia.Animation
{
/// <summary>
/// Interface for <see cref="Transition{T}"/> objects.
/// </summary>
public interface ITransition
{
/// <summary>
/// Applies the transition to the specified <see cref="Animatable"/>.
/// </summary>
IDisposable Apply(Animatable control, object oldValue, object newValue);
/// <summary>
/// Gets the property to be animated.
/// </summary>
AvaloniaProperty Property { get; set; }
}
}

23
src/Avalonia.Animation/Transitions/IntegerTransition.cs

@ -0,0 +1,23 @@
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using Avalonia.Metadata;
using System;
using System.Reactive.Linq;
namespace Avalonia.Animation
{
/// <summary>
/// Transition class that handles <see cref="AvaloniaProperty"/> with <see cref="int"/> types.
/// </summary>
public class IntegerTransition : Transition<int>
{
/// <inheritdocs/>
public override IObservable<int> DoInterpolation(IObservable<double> progress, int oldValue, int newValue)
{
var delta = newValue - oldValue;
return progress
.Select(p => (int)(Easing.Ease(p) * delta + oldValue));
}
}
}

25
src/Avalonia.Animation/Transitions/Transition.cs

@ -3,24 +3,10 @@
using Avalonia.Metadata;
using System;
using System.Reactive.Linq;
namespace Avalonia.Animation
{
public interface ITransition
{
/// <summary>
/// Applies the transition to the specified <see cref="Animatable"/>.
/// </summary>
void Apply(Animatable control, object oldValue, object newValue);
/// <summary>
/// Gets the property to be animated.
/// </summary>
AvaloniaProperty Property { get; set; }
}
/// <summary>
/// Defines how a property should be animated using a transition.
/// </summary>
@ -49,7 +35,7 @@ namespace Avalonia.Animation
{
if (!(typeof(T) == value.PropertyType))
throw new InvalidCastException
($"Invalid property type {typeof(T).Name} for this {GetType().Name}");
($"Invalid property type \"{typeof(T).Name}\" for this {GetType().Name} transition.");
_prop = value;
}
@ -58,12 +44,13 @@ namespace Avalonia.Animation
/// <summary>
/// Apply interpolation to the property.
/// </summary>
public abstract void DoInterpolation(Animatable control, IObservable<double> progress, T oldValue, T newValue);
public abstract IObservable<T> DoInterpolation(IObservable<double> progress, T oldValue, T newValue);
/// <inheritdocs/>
public void Apply(Animatable control, object oldValue, object newValue)
public IDisposable Apply(Animatable control, object oldValue, object newValue)
{
DoInterpolation(control, Timing.GetTimer(Duration), (T)oldValue, (T)newValue);
var transition = DoInterpolation(Timing.GetTimer(Duration), (T)oldValue, (T)newValue).Select(p => (object)p);
return control.Bind(Property, transition, Data.BindingPriority.Animation);
}
}

2
src/Avalonia.Controls/Presenters/CarouselPresenter.cs

@ -39,7 +39,7 @@ namespace Avalonia.Controls.Presenters
Carousel.PageTransitionProperty.AddOwner<CarouselPresenter>();
private int _selectedIndex = -1;
private Task _current;
// private Task _current;
private Task _currentTransition;
private int _queuedTransitionIndex = -1;

38
src/Avalonia.Controls/ProgressBar.cs

@ -105,8 +105,8 @@ namespace Avalonia.Controls
private class IndeterminateAnimation : IDisposable
{
private WeakReference<ProgressBar> _progressBar;
private IDisposable _indeterminateBindSubscription;
private TimeSpan _startTime;
//private IDisposable _indeterminateBindSubscription;
//private TimeSpan _startTime;
private bool _disposed;
public bool Disposed => _disposed;
@ -129,31 +129,31 @@ namespace Avalonia.Controls
private Rect GetAnimationRect(TimeSpan time)
{
if (_progressBar.TryGetTarget(out var progressBar))
{
if (progressBar.Orientation == Orientation.Horizontal)
return new Rect(-progressBar._indicator.Width - 5 + (time - _startTime).TotalSeconds / 4.0 * (progressBar.Bounds.Width + progressBar._indicator.Width + 10), 0, progressBar._indicator.Bounds.Width, progressBar._indicator.Bounds.Height);
else
return new Rect(0, progressBar.Bounds.Height + 5 - (time - _startTime).TotalSeconds / 4.0 * (progressBar.Bounds.Height + progressBar._indicator.Height + 10), progressBar._indicator.Bounds.Width, progressBar._indicator.Bounds.Height);
}
else
{
_indeterminateBindSubscription.Dispose();
return Rect.Empty;
}
//if (_progressBar.TryGetTarget(out var progressBar))
//{
// if (progressBar.Orientation == Orientation.Horizontal)
// return new Rect(-progressBar._indicator.Width - 5 + (time - _startTime).TotalSeconds / 4.0 * (progressBar.Bounds.Width + progressBar._indicator.Width + 10), 0, progressBar._indicator.Bounds.Width, progressBar._indicator.Bounds.Height);
// else
// return new Rect(0, progressBar.Bounds.Height + 5 - (time - _startTime).TotalSeconds / 4.0 * (progressBar.Bounds.Height + progressBar._indicator.Height + 10), progressBar._indicator.Bounds.Width, progressBar._indicator.Bounds.Height);
//}
//else
//{
// _indeterminateBindSubscription.Dispose();
return Rect.Empty;
//}
}
private void AnimationTick(Rect rect)
{
if (_progressBar.TryGetTarget(out var progressBar))
progressBar._indicator.Arrange(rect);
else
_indeterminateBindSubscription.Dispose();
//if (_progressBar.TryGetTarget(out var progressBar))
// progressBar._indicator.Arrange(rect);
//else
// _indeterminateBindSubscription.Dispose();
}
public void Dispose()
{
_indeterminateBindSubscription?.Dispose();
//_indeterminateBindSubscription?.Dispose();
_disposed = true;
}
}

3
src/Avalonia.Visuals/Animation/CrossFade.cs

@ -83,6 +83,9 @@ namespace Avalonia.Animation
//await Task.WhenAll(tasks.ToArray());
// FIXME: This is temporary until animations are fixed.
await Task.Delay(1);
if (from != null)
{
from.IsVisible = false;

3
src/Avalonia.Visuals/Animation/PageSlide.cs

@ -103,6 +103,9 @@ namespace Avalonia.Animation
//await Task.WhenAll(tasks.ToArray());
// FIXME: This is temporary until animations are fixed.
await Task.Delay(1);
if (from != null)
{
from.IsVisible = false;

Loading…
Cancel
Save