@ -52,52 +52,72 @@ namespace Avalonia.Animation
/// (i.e., the normalized time between the selected keyframes, relative to the
/// time parameter).
/// </summary>
/// <param name="t">The time parameter, relative to the total animation time</param>
protected ( double IntraKFTime , KeyFramePair < T > KFPair ) GetKFPairAndIntraKFTime ( double t )
/// <param name="anima tionTime ">The time parameter, relative to the total animation time</param>
protected ( double IntraKFTime , KeyFramePair < T > KFPair ) GetKFPairAndIntraKFTime ( double anima tionTime )
{
AnimatorKeyFrame firstCue , lastCu e ;
AnimatorKeyFrame firstKeyframe , lastKeyfram e ;
int kvCount = _ convertedKeyframes . Count ;
if ( kvCount > 2 )
{
if ( t < = 0.0 )
if ( anima tionTime < = 0.0 )
{
firstCu e = _ convertedKeyframes [ 0 ] ;
lastCu e = _ convertedKeyframes [ 1 ] ;
firstKeyfram e = _ convertedKeyframes [ 0 ] ;
lastKeyfram e = _ convertedKeyframes [ 1 ] ;
}
else if ( t > = 1.0 )
else if ( anima tionTime > = 1.0 )
{
firstCu e = _ convertedKeyframes [ _ convertedKeyframes . Count - 2 ] ;
lastCu e = _ convertedKeyframes [ _ convertedKeyframes . Count - 1 ] ;
firstKeyfram e = _ convertedKeyframes [ _ convertedKeyframes . Count - 2 ] ;
lastKeyfram e = _ convertedKeyframes [ _ convertedKeyframes . Count - 1 ] ;
}
else
{
( double time , int index ) maxval = ( 0.0d , 0 ) ;
for ( int i = 0 ; i < _ convertedKeyframes . Count ; i + + )
{
var comp = _ convertedKeyframes [ i ] . Cue . CueValue ;
if ( t > = comp )
{
maxval = ( comp , i ) ;
}
}
firstCue = _ convertedKeyframes [ maxval . index ] ;
lastCue = _ convertedKeyframes [ maxval . index + 1 ] ;
int index = FindClosestBeforeKeyFrame ( animationTime ) ;
firstKeyframe = _ convertedKeyframes [ index ] ;
lastKeyframe = _ convertedKeyframes [ index + 1 ] ;
}
}
else
{
firstCu e = _ convertedKeyframes [ 0 ] ;
lastCu e = _ convertedKeyframes [ 1 ] ;
firstKeyframe = _ convertedKeyframes [ 0 ] ;
lastKeyframe = _ convertedKeyframes [ 1 ] ;
}
double t0 = firstCu e . Cue . CueValue ;
double t1 = lastCu e . Cue . CueValue ;
var intraframeTime = ( t - t0 ) / ( t1 - t0 ) ;
var firstFrameData = ( firstCu e . GetTypedValue < T > ( ) , firstCu e . isNeutral ) ;
var lastFrameData = ( lastCu e . GetTypedValue < T > ( ) , lastCu e . isNeutral ) ;
double t0 = firstKeyfram e . Cue . CueValue ;
double t1 = lastKeyfram e . Cue . CueValue ;
var intraframeTime = ( anima tionTime - t0 ) / ( t1 - t0 ) ;
var firstFrameData = ( firstKeyfram e . GetTypedValue < T > ( ) , firstKeyfram e . isNeutral ) ;
var lastFrameData = ( lastKeyfram e . GetTypedValue < T > ( ) , lastKeyfram e . isNeutral ) ;
return ( intraframeTime , new KeyFramePair < T > ( firstFrameData , lastFrameData ) ) ;
}
private int FindClosestBeforeKeyFrame ( double time )
{
int FindClosestBeforeKeyFrame ( int startIndex , int length )
{
if ( length = = 0 | | length = = 1 )
{
return startIndex ;
}
int middle = startIndex + ( length / 2 ) ;
if ( _ convertedKeyframes [ middle ] . Cue . CueValue < time )
{
return FindClosestBeforeKeyFrame ( middle , length - middle ) ;
}
else if ( _ convertedKeyframes [ middle ] . Cue . CueValue > time )
{
return FindClosestBeforeKeyFrame ( startIndex , middle - startIndex ) ;
}
else
{
return middle ;
}
}
return FindClosestBeforeKeyFrame ( 0 , _ convertedKeyframes . Count ) ;
}
/// <summary>
/// Runs the KeyFrames Animation.
/// </summary>
@ -130,14 +150,6 @@ namespace Avalonia.Animation
AddNeutralKeyFramesIfNeeded ( ) ;
var copy = _ convertedKeyframes . ToList ( ) . OrderBy ( p = > p . Cue . CueValue ) ;
_ convertedKeyframes . Clear ( ) ;
foreach ( AnimatorKeyFrame keyframe in copy )
{
_ convertedKeyframes . Add ( keyframe ) ;
}
_ isVerifiedAndConverted = true ;
}
@ -167,7 +179,7 @@ namespace Avalonia.Animation
{
if ( ! hasStartKey )
{
_ convertedKeyframes . Add ( new AnimatorKeyFrame ( null , new Cue ( 0.0d ) ) { Value = default ( T ) , isNeutral = true } ) ;
_ convertedKeyframes . Insert ( 0 , new AnimatorKeyFrame ( null , new Cue ( 0.0d ) ) { Value = default ( T ) , isNeutral = true } ) ;
}
if ( ! hasEndKey )