committed by
GitHub
5 changed files with 227 additions and 19 deletions
@ -0,0 +1,85 @@ |
|||
namespace Avalonia.Animation.Easings |
|||
{ |
|||
/// <summary>
|
|||
/// Eases a <see cref="double"/> value
|
|||
/// using a user-defined cubic bezier curve.
|
|||
/// Good for custom easing functions that doesn't quite
|
|||
/// fit with the built-in ones.
|
|||
/// </summary>
|
|||
public class SplineEasing : Easing |
|||
{ |
|||
/// <summary>
|
|||
/// X coordinate of the first control point
|
|||
/// </summary>
|
|||
public double X1 |
|||
{ |
|||
get => _internalKeySpline.ControlPointX1; |
|||
set |
|||
{ |
|||
_internalKeySpline.ControlPointX1 = value; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Y coordinate of the first control point
|
|||
/// </summary>
|
|||
public double Y1 |
|||
{ |
|||
get => _internalKeySpline.ControlPointY1; |
|||
set |
|||
{ |
|||
_internalKeySpline.ControlPointY1 = value; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// X coordinate of the second control point
|
|||
/// </summary>
|
|||
public double X2 |
|||
{ |
|||
get => _internalKeySpline.ControlPointX2; |
|||
set |
|||
{ |
|||
_internalKeySpline.ControlPointX2 = value; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Y coordinate of the second control point
|
|||
/// </summary>
|
|||
public double Y2 |
|||
{ |
|||
get => _internalKeySpline.ControlPointY2; |
|||
set |
|||
{ |
|||
_internalKeySpline.ControlPointY2 = value; |
|||
} |
|||
} |
|||
|
|||
private readonly KeySpline _internalKeySpline; |
|||
|
|||
public SplineEasing(double x1 = 0d, double y1 = 0d, double x2 = 1d, double y2 = 1d) |
|||
{ |
|||
_internalKeySpline = new KeySpline(); |
|||
|
|||
this.X1 = x1; |
|||
this.Y1 = y1; |
|||
this.X2 = x2; |
|||
this.Y1 = y2; |
|||
} |
|||
|
|||
public SplineEasing(KeySpline keySpline) |
|||
{ |
|||
_internalKeySpline = keySpline; |
|||
} |
|||
|
|||
public SplineEasing() |
|||
{ |
|||
_internalKeySpline = new KeySpline(); |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
public override double Ease(double progress) => |
|||
_internalKeySpline.GetSplineProgress(progress); |
|||
} |
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
using System; |
|||
using System.ComponentModel; |
|||
using System.Globalization; |
|||
|
|||
// Ported from WPF open-source code.
|
|||
// https://github.com/dotnet/wpf/blob/ae1790531c3b993b56eba8b1f0dd395a3ed7de75/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/KeySpline.cs
|
|||
|
|||
namespace Avalonia.Animation |
|||
{ |
|||
/// <summary>
|
|||
/// Converts string values to <see cref="KeySpline"/> values
|
|||
/// </summary>
|
|||
public class KeySplineTypeConverter : TypeConverter |
|||
{ |
|||
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) |
|||
{ |
|||
return sourceType == typeof(string); |
|||
} |
|||
|
|||
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) |
|||
{ |
|||
return KeySpline.Parse((string)value, culture); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue