Files
sbox-public/engine/Sandbox.Engine/Systems/UI/Animation/KeyFrames.cs
s&box team 71f266059a Open source release
This commit imports the C# engine code and game files, excluding C++ source code.

[Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
2025-11-24 09:05:18 +00:00

60 lines
1.5 KiB
C#

namespace Sandbox.UI;
/// <summary>
/// Represents a CSS <c>@keyframes</c> rule.
/// </summary>
public partial class KeyFrames
{
/// <summary>
/// Name of the <c>@keyframes</c> rule.
/// </summary>
public string Name { get; set; }
/// <summary>
/// A keyframe within the animation.
/// </summary>
public class Block
{
/// <summary>
/// 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.
/// </summary>
public float Interval { get; set; }
/// <summary>
/// The styles that should be applied at this position in the animation.
/// </summary>
public Styles Styles { get; set; }
}
/// <summary>
/// List of keyframes with in the <c>@keyframes</c> rule.
/// </summary>
public List<Block> Blocks = new List<Block>();
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 );
}
}