SplineGeometryKeyFrame.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using System.Windows;
  3. using System.Windows.Media;
  4. using System.Windows.Media.Animation;
  5. using HandyControl.Expression.Drawing;
  6. using HandyControl.Tools;
  7. namespace HandyControl.Media.Animation;
  8. public class SplineGeometryKeyFrame : GeometryKeyFrame
  9. {
  10. public SplineGeometryKeyFrame()
  11. {
  12. }
  13. public SplineGeometryKeyFrame(Geometry value) : base(value)
  14. {
  15. }
  16. public SplineGeometryKeyFrame(Geometry value, KeyTime keyTime) : base(value, keyTime)
  17. {
  18. }
  19. public SplineGeometryKeyFrame(Geometry value, KeyTime keyTime, KeySpline keySpline) : base(value, keyTime)
  20. {
  21. KeySpline = keySpline ?? throw new ArgumentNullException(nameof(keySpline));
  22. }
  23. protected override Freezable CreateInstanceCore() => new SplineGeometryKeyFrame();
  24. protected override double[] InterpolateValueCore(double[] baseValue, double keyFrameProgress)
  25. {
  26. if (MathHelper.IsVerySmall(keyFrameProgress))
  27. {
  28. return baseValue;
  29. }
  30. if (MathHelper.AreClose(keyFrameProgress, 1))
  31. {
  32. return Numbers;
  33. }
  34. var splineProgress = KeySpline.GetSplineProgress(keyFrameProgress);
  35. return AnimationHelper.InterpolateGeometryValue(baseValue, Numbers, splineProgress);
  36. }
  37. public static readonly DependencyProperty KeySplineProperty = DependencyProperty.Register(
  38. nameof(KeySpline), typeof(KeySpline), typeof(SplineGeometryKeyFrame), new PropertyMetadata(new KeySpline()));
  39. public KeySpline KeySpline
  40. {
  41. get => (KeySpline) GetValue(KeySplineProperty);
  42. set => SetValue(KeySplineProperty, value);
  43. }
  44. }