add EasingGeometryKeyFrame
This commit is contained in:
1 parent
39a1a084c6
commit
f747e207d1
4 files changed
+85
-8
No files matched your search
@@ -0,0 +1,70 @@
|
||||
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 EasingGeometryKeyFrame : GeometryKeyFrame
|
||||
{
|
||||
private double[] _baseValues;
|
||||
|
||||
public EasingGeometryKeyFrame()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public EasingGeometryKeyFrame(Geometry value) : base(value)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public EasingGeometryKeyFrame(Geometry value, KeyTime keyTime) : base(value, keyTime)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public EasingGeometryKeyFrame(Geometry value, KeyTime keyTime, IEasingFunction easingFunction) : base(value, keyTime)
|
||||
{
|
||||
EasingFunction = easingFunction;
|
||||
}
|
||||
|
||||
protected override Freezable CreateInstanceCore() => new EasingGeometryKeyFrame();
|
||||
|
||||
protected override Geometry InterpolateValueCore(Geometry baseValue, double keyFrameProgress)
|
||||
{
|
||||
if (_baseValues == null)
|
||||
{
|
||||
AnimationHelper.DecomposeGeometryStr(baseValue.ToString(), out _baseValues);
|
||||
}
|
||||
|
||||
var easingFunction = EasingFunction;
|
||||
if (easingFunction != null)
|
||||
{
|
||||
keyFrameProgress = easingFunction.Ease(keyFrameProgress);
|
||||
}
|
||||
|
||||
if (MathHelper.IsVerySmall(keyFrameProgress))
|
||||
{
|
||||
return baseValue;
|
||||
}
|
||||
|
||||
if (MathHelper.AreClose(keyFrameProgress, 1))
|
||||
{
|
||||
return AnimationHelper.ComposeGeometry(Strings, Value);
|
||||
}
|
||||
|
||||
return AnimationHelper.InterpolateGeometry(_baseValues, Value, keyFrameProgress, Strings);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty EasingFunctionProperty = DependencyProperty.Register(
|
||||
"EasingFunction", typeof(IEasingFunction), typeof(EasingGeometryKeyFrame), new PropertyMetadata(default(IEasingFunction)));
|
||||
|
||||
public IEasingFunction EasingFunction
|
||||
{
|
||||
get => (IEasingFunction) GetValue(EasingFunctionProperty);
|
||||
set => SetValue(EasingFunctionProperty, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@ namespace HandyControl.Media.Animation
|
||||
|
||||
}
|
||||
|
||||
protected override Freezable CreateInstanceCore() => new LinearDoubleKeyFrame();
|
||||
protected override Freezable CreateInstanceCore() => new LinearGeometryKeyFrame();
|
||||
|
||||
protected override Geometry InterpolateValueCore(Geometry baseValue, double keyFrameProgress)
|
||||
{
|
||||
@@ -44,13 +44,7 @@ namespace HandyControl.Media.Animation
|
||||
return AnimationHelper.ComposeGeometry(Strings, Value);
|
||||
}
|
||||
|
||||
var accumulated = new double[Value.Length];
|
||||
for (var i = 0; i < Value.Length; i++)
|
||||
{
|
||||
accumulated[i] = _baseValues[i] + (Value[i] - _baseValues[i]) * keyFrameProgress;
|
||||
}
|
||||
|
||||
return AnimationHelper.ComposeGeometry(Strings, accumulated);
|
||||
return AnimationHelper.InterpolateGeometry(_baseValues, Value, keyFrameProgress, Strings);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user