Files
sbox-public/game/editor/MovieMaker/Code/Modifications/Stretch.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

42 lines
1.3 KiB
C#

using System.Linq;
using Sandbox.MovieMaker;
namespace Editor.MovieMaker;
#nullable enable
// [MovieModification( "Stretch", Icon = "width_full" )]
file sealed class StretchModification() : PerTrackModification<StretchOptions>( StretchOptions.Default, true )
{
public override void Start( TimeSelection selection )
{
Options = Options with { SourceDuration = selection.TotalTimeRange.Duration };
}
protected override ITrackModification<TValue> OnCreateModification<TValue>( IPropertyTrack<TValue> track ) =>
new StretchTrackModification<TValue>();
}
file sealed record StretchOptions( MovieTime SourceDuration = default ) : IModificationOptions
{
public static StretchOptions Default => new();
}
file sealed class StretchTrackModification<T> : ITrackModification<T, StretchOptions>
{
public IEnumerable<PropertyBlock<T>> Apply( IReadOnlyList<PropertyBlock<T>> original,
TimeSelection selection, StretchOptions options )
{
return options.SourceDuration > 0 && options.SourceDuration != selection.TotalTimeRange
? original.Select( x => Stretch( x, selection, options ) )
: original;
}
private PropertyBlock<T> Stretch( PropertyBlock<T> original, TimeSelection selection, StretchOptions options )
{
var signal = original.Signal.SlidingStretch( options.SourceDuration, selection );
return new PropertyBlock<T>( signal, original.TimeRange );
}
}