diff --git a/src/Shared/HandyControl_Shared/HandyControl_Shared.projitems b/src/Shared/HandyControl_Shared/HandyControl_Shared.projitems index aa3143e8..82d0c876 100644 --- a/src/Shared/HandyControl_Shared/HandyControl_Shared.projitems +++ b/src/Shared/HandyControl_Shared/HandyControl_Shared.projitems @@ -49,6 +49,7 @@ + diff --git a/src/Shared/HandyControl_Shared/Media/Animation/SplineGeometryKeyFrame.cs b/src/Shared/HandyControl_Shared/Media/Animation/SplineGeometryKeyFrame.cs new file mode 100644 index 00000000..d501c2db --- /dev/null +++ b/src/Shared/HandyControl_Shared/Media/Animation/SplineGeometryKeyFrame.cs @@ -0,0 +1,66 @@ +using System; +using System.Windows; +using System.Windows.Media; +using System.Windows.Media.Animation; +using HandyControl.Expression.Drawing; +using HandyControl.Tools; + +namespace HandyControl.Media.Animation +{ + public class SplineGeometryKeyFrame : GeometryKeyFrame + { + private double[] _baseValues; + + public SplineGeometryKeyFrame() + { + + } + + public SplineGeometryKeyFrame(Geometry value) : base(value) + { + + } + + public SplineGeometryKeyFrame(Geometry value, KeyTime keyTime) : base(value, keyTime) + { + + } + + public SplineGeometryKeyFrame(Geometry value, KeyTime keyTime, KeySpline keySpline) : base(value, keyTime) + { + KeySpline = keySpline ?? throw new ArgumentNullException(nameof(keySpline)); + } + + protected override Freezable CreateInstanceCore() => new SplineGeometryKeyFrame(); + + protected override Geometry InterpolateValueCore(Geometry baseValue, double keyFrameProgress) + { + if (_baseValues == null) + { + AnimationHelper.DecomposeGeometryStr(baseValue.ToString(), out _baseValues); + } + + if (MathHelper.IsVerySmall(keyFrameProgress)) + { + return baseValue; + } + + if (MathHelper.AreClose(keyFrameProgress, 1)) + { + return AnimationHelper.ComposeGeometry(Strings, Value); + } + + var splineProgress = KeySpline.GetSplineProgress(keyFrameProgress); + return AnimationHelper.InterpolateGeometry(_baseValues, Value, splineProgress, Strings); + } + + public static readonly DependencyProperty KeySplineProperty = DependencyProperty.Register( + "KeySpline", typeof(KeySpline), typeof(SplineGeometryKeyFrame), new PropertyMetadata(new KeySpline())); + + public KeySpline KeySpline + { + get => (KeySpline) GetValue(KeySplineProperty); + set => SetValue(KeySplineProperty, value); + } + } +}