Browse Source

Add parser for spline easing

pull/4180/head
Jumar Macato 6 years ago
parent
commit
82f3c2f0c0
No known key found for this signature in database GPG Key ID: B19884DAC3A5BF3F
  1. 32
      src/Avalonia.Animation/Easing/Easing.cs

32
src/Avalonia.Animation/Easing/Easing.cs

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
namespace Avalonia.Animation.Easings
@ -25,6 +26,37 @@ namespace Avalonia.Animation.Easings
/// <returns>Returns the instance of the parsed type.</returns>
public static Easing Parse(string e)
{
if (e.Contains(','))
{
var k = e.Split(',');
if (k.Count() != 4)
throw new FormatException($"SplineEasing only accepts exactly 4 arguments.");
var splineEase = new SplineEasing();
if (double.TryParse(k[0], NumberStyles.Any, CultureInfo.InvariantCulture, out var x1))
splineEase.X1 = x1;
else
throw new FormatException($"Invalid SplineEasing control point X1 value: {k[0]}");
if (double.TryParse(k[1], NumberStyles.Any, CultureInfo.InvariantCulture, out var y1))
splineEase.Y1 = y1;
else
throw new FormatException($"Invalid SplineEasing control point Y1 value: {k[1]}");
if (double.TryParse(k[2], NumberStyles.Any, CultureInfo.InvariantCulture, out var x2))
splineEase.X2 = x2;
else
throw new FormatException($"Invalid SplineEasing control point Y1 value: {k[2]}");
if (double.TryParse(k[3], NumberStyles.Any, CultureInfo.InvariantCulture, out var y2))
splineEase.Y2 = y2;
else
throw new FormatException($"Invalid SplineEasing control point Y1 value: {k[3]}");
return splineEase;
}
if (_easingTypes == null)
{
_easingTypes = new Dictionary<string, Type>();

Loading…
Cancel
Save