mirror of
https://gitee.com/handyorg/HandyControl.git
synced 2024-12-04 21:07:49 +08:00
add EasingGeometryKeyFrame
This commit is contained in:
parent
39a1a084c6
commit
f747e207d1
@ -42,6 +42,7 @@
|
|||||||
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\Commands\CloseWindowCommand.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\Commands\CloseWindowCommand.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\Commands\OpenLinkCommand.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\Commands\OpenLinkCommand.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Media\Animation\DiscreteGeometryKeyFrame.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Media\Animation\DiscreteGeometryKeyFrame.cs" />
|
||||||
|
<Compile Include="$(MSBuildThisFileDirectory)Media\Animation\EasingGeometryKeyFrame.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Media\Animation\GeometryAnimation.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Media\Animation\GeometryAnimation.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Media\Animation\GeometryAnimationBase.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Media\Animation\GeometryAnimationBase.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Media\Animation\GeometryAnimationUsingKeyFrames.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Media\Animation\GeometryAnimationUsingKeyFrames.cs" />
|
||||||
|
@ -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)
|
protected override Geometry InterpolateValueCore(Geometry baseValue, double keyFrameProgress)
|
||||||
{
|
{
|
||||||
@ -44,13 +44,7 @@ namespace HandyControl.Media.Animation
|
|||||||
return AnimationHelper.ComposeGeometry(Strings, Value);
|
return AnimationHelper.ComposeGeometry(Strings, Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
var accumulated = new double[Value.Length];
|
return AnimationHelper.InterpolateGeometry(_baseValues, Value, keyFrameProgress, Strings);
|
||||||
for (var i = 0; i < Value.Length; i++)
|
|
||||||
{
|
|
||||||
accumulated[i] = _baseValues[i] + (Value[i] - _baseValues[i]) * keyFrameProgress;
|
|
||||||
}
|
|
||||||
|
|
||||||
return AnimationHelper.ComposeGeometry(Strings, accumulated);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,5 +66,17 @@ namespace HandyControl.Tools
|
|||||||
|
|
||||||
return Geometry.Parse(builder.ToString());
|
return Geometry.Parse(builder.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static Geometry InterpolateGeometry(double[] from, double[] to, double progress, string[] strings)
|
||||||
|
{
|
||||||
|
var accumulated = new double[to.Length];
|
||||||
|
for (var i = 0; i < to.Length; i++)
|
||||||
|
{
|
||||||
|
var fromValue = from[i];
|
||||||
|
accumulated[i] = fromValue + (to[i] - fromValue) * progress;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ComposeGeometry(strings, accumulated);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user