EasingGeometryKeyFrame.cs 1.7 KB

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