Browse Source

Revert the library split, just transferring the base Animatable class to Avalonia.Visual was good enough.

Apply important changes from my internal test branch
pull/1461/head
Jumar Macato 9 years ago
parent
commit
28e3d73098
  1. 16
      samples/RenderTest/Program.cs
  2. 10
      samples/RenderTest/SideBar.xaml
  3. 45
      src/Avalonia.Animation/AnimationExtensions.cs
  4. 56
      src/Avalonia.Animation/Animation`1.cs
  5. 2
      src/Avalonia.Animation/Avalonia.Animation.csproj
  6. 0
      src/Avalonia.Animation/Easing.cs
  7. 2
      src/Avalonia.Animation/Helpers/DoubleHelper.cs
  8. 25
      src/Avalonia.Animation/Transition.cs
  9. 2
      src/Avalonia.Animation/Transitions/DoubleTransition.cs
  10. 2
      src/Avalonia.Animation/Transitions/FloatTransition.cs
  11. 2
      src/Avalonia.Animation/Transitions/IntegerTransition.cs
  12. 31
      src/Avalonia.Animation/Transitions/PointTransition.cs
  13. 35
      src/Avalonia.Animation/Transitions/ThicknessTransition.cs
  14. 1
      src/Avalonia.Styling/Avalonia.Styling.csproj
  15. 7
      src/Avalonia.Visuals/Animation/Animatable.cs
  16. 0
      src/Avalonia.Visuals/Animation/Animation.cs
  17. 0
      src/Avalonia.Visuals/Animation/IEasing.cs
  18. 0
      src/Avalonia.Visuals/Animation/Timing.cs
  19. 1
      src/Avalonia.Visuals/Avalonia.Visuals.csproj
  20. 2
      src/Avalonia.Visuals/ITransition.cs
  21. 2
      src/Avalonia.Visuals/Transitions.cs

16
samples/RenderTest/Program.cs

@ -10,15 +10,15 @@ namespace RenderTest
{
internal class Program
{
static void Main(string[] args)
{
// TODO: Make this work with GTK/Skia/Cairo depending on command-line args
// again.
AppBuilder.Configure<App>()
// TODO: Make this work with GTK/Skia/Cairo depending on command-line args
// again.
static void Main(string[] args) => BuildAvaloniaApp().Start<MainWindow>();
// App configuration, used by the entry point and previewer
static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
.UseReactiveUI()
.LogToDebug()
.Start<MainWindow>();
}
.LogToDebug();
}
}

10
samples/RenderTest/SideBar.xaml

@ -1,4 +1,6 @@
<Styles xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Styles xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:a="clr-namespace:Avalonia.Media.Animations;assembly=Avalonia.Media.Animations">
<Style Selector="TabControl.sidebar">
<Setter Property="Template">
<ControlTemplate>
@ -32,6 +34,7 @@
<Setter Property="FontSize" Value="14"/>
<Setter Property="Margin" Value="0"/>
<Setter Property="Padding" Value="16"/>
<Setter Property="Opacity" Value="0.5"/>
<Setter Property="Transitions">
<Transitions>
<DoubleTransition Property="Opacity" Easing="CircularEaseIn" Duration="0:0:0.5"/>
@ -40,10 +43,11 @@
</Style>
<Style Selector="TabControl.sidebar TabStripItem:pointerover">
<Setter Property="Opacity" Value="0.5"/>
<Setter Property="Opacity" Value="1"/>
</Style>
<Style Selector="TabControl.sidebar TabStripItem:selected">
<Setter Property="Background" Value="{DynamicResource ThemeAccentBrush2}"/>
<Setter Property="Opacity" Value="1"/>
</Style>
</Styles>

45
src/Avalonia.Animation/AnimationExtensions.cs

@ -1,45 +0,0 @@
// 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 System;
namespace Avalonia.Animation
{
/// <summary>
/// Defines animation extension methods.
/// </summary>
public static class AnimationExtensions
{
///// <summary>
///// Returns a new <see cref="Avalonia.Animation.Transition"/> for the specified
///// <see cref="AvaloniaProperty"/> using linear easing.
///// </summary>
///// <typeparam name="T">The type of the <see cref="AvaloniaProperty"/>.</typeparam>
///// <param name="property">The property to animate.</param>
///// <param name="milliseconds">The animation duration in milliseconds.</param>
///// <returns>
///// A <see cref="Avalonia.Animation.Transition"/> that can be added to the
///// <see cref="Animatable.Transitions"/> collection.
///// </returns>
//public static Transition Transition<T>(this AvaloniaProperty<T> property, int milliseconds)
//{
// return Transition(property, TimeSpan.FromMilliseconds(milliseconds));
//}
///// <summary>
///// Returns a new <see cref="Avalonia.Animation.Transition"/> for the specified
///// <see cref="AvaloniaProperty"/> using linear easing.
///// </summary>
///// <typeparam name="T">The type of the <see cref="AvaloniaProperty"/>.</typeparam>
///// <param name="property">The property to animate.</param>
///// <param name="duration">The animation duration.</param>
///// <returns>
///// A <see cref="Avalonia.Animation.Transition"/> that can be added to the
///// <see cref="Animatable.Transitions"/> collection.
///// </returns>
//public static Transition Transition<T>(this AvaloniaProperty<T> property, TimeSpan duration)
//{
// return new Transition(property, duration, LinearEasing.For<T>());
//}
}
}

56
src/Avalonia.Animation/Animation`1.cs

@ -1,56 +0,0 @@
//// 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 System;
//namespace Avalonia.Animation
//{
// /// <summary>
// /// Tracks the progress of an animation.
// /// </summary>
// /// <typeparam name="T">The type of the value being animated./</typeparam>
// public class Animation<T> : IObservable<T>, IDisposable
// {
// /// <summary>
// /// The animation being tracked.
// /// </summary>
// private readonly IObservable<T> _inner;
// /// <summary>
// /// The disposable used to cancel the animation.
// /// </summary>
// private readonly IDisposable _subscription;
// /// <summary>
// /// Initializes a new instance of the <see cref="Animation{T}"/> class.
// /// </summary>
// /// <param name="inner">The animation observable being tracked.</param>
// /// <param name="subscription">A disposable used to cancel the animation.</param>
// public Animation(IObservable<T> inner, IDisposable subscription)
// {
// _inner = inner;
// _subscription = subscription;
// }
// /// <summary>
// /// Cancels the animation.
// /// </summary>
// public void Dispose()
// {
// _subscription.Dispose();
// }
// /// <summary>
// /// Notifies the provider that an observer is to receive notifications.
// /// </summary>
// /// <param name="observer">The observer.</param>
// /// <returns>
// /// A reference to an interface that allows observers to stop receiving notifications
// /// before the provider has finished sending them.
// /// </returns>
// public IDisposable Subscribe(IObserver<T> observer)
// {
// return _inner.Subscribe(observer);
// }
// }
//}

2
src/Avalonia.Animation/Avalonia.Animation.csproj

@ -32,6 +32,8 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Avalonia.Base\Avalonia.Base.csproj" />
<ProjectReference Include="..\Avalonia.Styling\Avalonia.Styling.csproj" />
<ProjectReference Include="..\Avalonia.Visuals\Avalonia.Visuals.csproj" />
</ItemGroup>
<Import Project="..\..\build\Rx.props" />
</Project>

0
src/Avalonia.Animation/Easing/Easing.cs → src/Avalonia.Animation/Easing.cs

2
src/Avalonia.Animation/Helpers/DoubleHelper.cs

@ -5,7 +5,7 @@ using System;
using System.Collections.Generic;
using System.Text;
namespace Avalonia.Animation.Helpers
namespace Avalonia.Animation
{
internal static class DoubleHelper
{

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

@ -12,17 +12,28 @@ namespace Avalonia.Animation
/// </summary>
public abstract class Transition<T> : ITransition
{
private AvaloniaProperty _prop;
private IEasing _easing;
/// <summary>
/// Gets the duration of the animation.
/// </summary>
public TimeSpan Duration { get; set; }
/// <summary>
/// Gets the easing class to be used.
/// </summary>
public IEasing Easing { get; set; }
private AvaloniaProperty _prop;
public IEasing Easing
{
get
{
return _easing ?? (_easing = new LinearEasing());
}
set
{
_easing = value;
}
}
/// <inheritdocs/>
public AvaloniaProperty Property
@ -33,7 +44,7 @@ namespace Avalonia.Animation
}
set
{
if (!(typeof(T) == value.PropertyType))
if (!(typeof(T) == value.PropertyType))
throw new InvalidCastException
($"Invalid property type \"{typeof(T).Name}\" for this {GetType().Name} transition.");
@ -44,12 +55,12 @@ namespace Avalonia.Animation
/// <summary>
/// Apply interpolation to the property.
/// </summary>
public abstract IObservable<T> DoInterpolation(IObservable<double> progress, T oldValue, T newValue);
public abstract IObservable<T> DoTransition(IObservable<double> progress, T oldValue, T newValue);
/// <inheritdocs/>
public IDisposable Apply(Animatable control, object oldValue, object newValue)
{
var transition = DoInterpolation(Timing.GetTimer(Duration), (T)oldValue, (T)newValue).Select(p => (object)p);
var transition = DoTransition(Timing.GetTimer(Duration), (T)oldValue, (T)newValue).Select(p => (object)p);
return control.Bind(Property, transition, Data.BindingPriority.Animation);
}

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

@ -13,7 +13,7 @@ namespace Avalonia.Animation
public class DoubleTransition : Transition<double>
{
/// <inheritdocs/>
public override IObservable<double> DoInterpolation(IObservable<double> progress, double oldValue, double newValue)
public override IObservable<double> DoTransition(IObservable<double> progress, double oldValue, double newValue)
{
var delta = newValue - oldValue;
return progress

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

@ -13,7 +13,7 @@ namespace Avalonia.Animation
public class FloatTransition : Transition<float>
{
/// <inheritdocs/>
public override IObservable<float> DoInterpolation(IObservable<double> progress, float oldValue, float newValue)
public override IObservable<float> DoTransition(IObservable<double> progress, float oldValue, float newValue)
{
var delta = newValue - oldValue;
return progress

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

@ -13,7 +13,7 @@ namespace Avalonia.Animation
public class IntegerTransition : Transition<int>
{
/// <inheritdocs/>
public override IObservable<int> DoInterpolation(IObservable<double> progress, int oldValue, int newValue)
public override IObservable<int> DoTransition(IObservable<double> progress, int oldValue, int newValue)
{
var delta = newValue - oldValue;
return progress

31
src/Avalonia.Animation/Transitions/PointTransition.cs

@ -0,0 +1,31 @@
// 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="Point"/> types.
/// </summary>
public class PointTransition : Transition<Point>
{
/// <inheritdocs/>
public override IObservable<Point> DoTransition(IObservable<double> progress, Point oldValue, Point newValue)
{
var deltaX = newValue.X - oldValue.Y;
var deltaY = newValue.X - oldValue.Y;
return progress
.Select(p =>
{
var f = Easing.Ease(p);
var nX = f * deltaX + oldValue.X;
var nY = f * deltaY + oldValue.Y;
return new Point(nX, nY);
});
}
}
}

35
src/Avalonia.Animation/Transitions/ThicknessTransition.cs

@ -0,0 +1,35 @@
// 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="Thickness"/> types.
/// </summary>
public class ThicknessTransition : Transition<Thickness>
{
/// <inheritdocs/>
public override IObservable<Thickness> DoTransition(IObservable<double> progress, Thickness oldValue, Thickness newValue)
{
var deltaL = newValue.Left - oldValue.Left;
var deltaT = newValue.Top - oldValue.Top;
var deltaR = newValue.Right - oldValue.Right;
var deltaB = newValue.Bottom - oldValue.Bottom;
return progress
.Select(p =>
{
var f = Easing.Ease(p);
var nL = f * deltaL + oldValue.Left;
var nT = f * deltaT + oldValue.Right;
var nR = f * deltaR + oldValue.Top;
var nB = f * deltaB + oldValue.Bottom;
return new Thickness(nL, nT, nR, nB);
});
}
}
}

1
src/Avalonia.Styling/Avalonia.Styling.csproj

@ -32,7 +32,6 @@
</Compile>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Avalonia.Animation\Avalonia.Animation.csproj" />
<ProjectReference Include="..\Avalonia.Base\Avalonia.Base.csproj" />
<ProjectReference Include="..\Avalonia.Visuals\Avalonia.Visuals.csproj" />
</ItemGroup>

7
src/Avalonia.Animation/Animatable.cs → src/Avalonia.Visuals/Animation/Animatable.cs

@ -5,6 +5,7 @@ using System.Linq;
using Avalonia.Data;
using System;
using System.Reactive.Linq;
using Avalonia.Collections;
namespace Avalonia.Animation
{
@ -16,13 +17,13 @@ namespace Avalonia.Animation
/// <summary>
///
/// </summary>
public static readonly StyledProperty<Transitions> TransitionsProperty =
AvaloniaProperty.Register<Animatable, Transitions>(nameof(Transitions));
public static readonly StyledProperty<AvaloniaList<ITransition>> TransitionsProperty =
AvaloniaProperty.Register<Animatable, AvaloniaList<ITransition>>(nameof(Transitions));
/// <summary>
/// Gets or sets the property transitions for the control.
/// </summary>
public Transitions Transitions
public AvaloniaList<ITransition> Transitions
{
get { return GetValue(TransitionsProperty); }
set { SetValue(TransitionsProperty, value); }

0
src/Avalonia.Animation/Animation.cs → src/Avalonia.Visuals/Animation/Animation.cs

0
src/Avalonia.Animation/IEasing.cs → src/Avalonia.Visuals/Animation/IEasing.cs

0
src/Avalonia.Animation/Timing.cs → src/Avalonia.Visuals/Animation/Timing.cs

1
src/Avalonia.Visuals/Avalonia.Visuals.csproj

@ -27,7 +27,6 @@
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Avalonia.Animation\Avalonia.Animation.csproj" />
<ProjectReference Include="..\Avalonia.Base\Avalonia.Base.csproj" />
</ItemGroup>
<ItemGroup>

2
src/Avalonia.Animation/Transitions/ITransition.cs → src/Avalonia.Visuals/ITransition.cs

@ -8,7 +8,7 @@ using System.Reactive.Linq;
namespace Avalonia.Animation
{
/// <summary>
/// Interface for <see cref="Transition{T}"/> objects.
/// Interface for Property Transition objects.
/// </summary>
public interface ITransition
{

2
src/Avalonia.Animation/Transitions/Transitions.cs → src/Avalonia.Visuals/Transitions.cs

@ -6,7 +6,7 @@ using Avalonia.Collections;
namespace Avalonia.Animation
{
/// <summary>
/// A collection of <see cref="Transition{T}"/> definitions.
/// A collection of <see cref="ITransition"/> definitions.
/// </summary>
public class Transitions : AvaloniaList<ITransition>
{
Loading…
Cancel
Save