namespace Sandbox.UI;
///
/// Represents a CSS @keyframes rule.
///
public partial class KeyFrames
{
///
/// Name of the @keyframes rule.
///
public string Name { get; set; }
///
/// A keyframe within the animation.
///
public class Block
{
///
/// The position of the keyframe within the overall animation. 0 to 1, where 0 is the start, and 1 is the end of the animation.
///
public float Interval { get; set; }
///
/// The styles that should be applied at this position in the animation.
///
public Styles Styles { get; set; }
}
///
/// List of keyframes with in the @keyframes rule.
///
public List Blocks = new List();
internal void FillStyle( float delta, Styles animStyle )
{
var startBlock = Blocks.First();
var endBlock = startBlock;
animStyle.From( startBlock.Styles );
// Work out previous and next blocks
foreach ( var block in Blocks )
{
endBlock = block;
if ( block.Interval > delta ) break;
startBlock = block;
}
// If startBlock & endBlock intervals are same, difference becomes zero
// which results in division by zero (NaN)
float t;
if ( startBlock.Interval == endBlock.Interval )
t = 0f;
else
t = MathX.LerpInverse( delta, startBlock.Interval, endBlock.Interval, true );
animStyle.FromLerp( startBlock.Styles, endBlock.Styles, t );
}
}