Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public Scrubber( TimelineView view )
Cursor = CursorShape.SizeH;
Movable = true;
Selectable = true;
HandlePosition = new( 0.5f, 0f );
}

protected override void OnPaint()
Expand Down Expand Up @@ -41,6 +42,7 @@ protected override void OnMousePressed( GraphicsMouseEvent e )
protected override void OnMouseReleased( GraphicsMouseEvent e )
{
base.OnMouseReleased( e );
TimelineView.MoveScrubber( Position.x );
TimelineView.Scrubbing = false;
}

Expand All @@ -49,7 +51,7 @@ protected override void OnMoved()
base.OnMoved();

TimelineView.Scrubbing = true;
TimelineView.MoveScrubber( Position.x, false );
TimelineView.MoveScrubber( Position.x + 0.5f, false );
}
}

Expand Down
29 changes: 17 additions & 12 deletions game/addons/tools/Code/Widgets/SoundPlayer/SoundPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public TimelineView( SoundPlayer parent ) : base( parent )
{
Timeline = parent;
SceneRect = new( 0, Size );
HorizontalScrollbar = ScrollbarMode.On;
HorizontalScrollbar = ScrollbarMode.Auto;
VerticalScrollbar = ScrollbarMode.Off;
Scale = 1;
Time = 0;
Expand All @@ -152,6 +152,7 @@ protected override void DoLayout()

var size = Size;
size.x = MathF.Max( Size.x, PositionFromTime( Duration ) );
size.x -= Width - ContentRect.Width;
SceneRect = new( 0, size );
TimeAxis.Size = new Vector2( size.x, Theme.RowHeight );
Scrubber.Size = new Vector2( 9, size.y );
Expand All @@ -162,7 +163,7 @@ protected override void DoLayout()
WaveForm.SceneRect = r;
WaveForm.Analyse();

Scrubber.Position = Scrubber.Position.WithX( PositionFromTime( Time ) - 3 ).SnapToGrid( 1.0f );
Scrubber.Position = Scrubber.Position.WithX( PositionFromTime( Time ) ).SnapToGrid( 1.0f );
}

protected override void OnResize()
Expand Down Expand Up @@ -191,8 +192,6 @@ public void OnFrame()
SoundHandle = null;
}

VisibleRect = Rect.FromPoints( ToScene( LocalRect.TopLeft ), ToScene( LocalRect.BottomRight ) );

if ( Timeline.Playing && !Scrubbing )
{
var time = Time % Duration;
Expand All @@ -219,27 +218,31 @@ public void OnFrame()
if ( Timeline.Playing && !SoundHandle.IsValid() )
{
SoundHandle = EditorUtility.PlaySound( Sound, Time );
SoundHandle.Time = 0;
SoundHandle.Time = Time;
SoundHandle.Occlusion = false;
SoundHandle.DistanceAttenuation = false;
}

Scrubber.Position = Scrubber.Position.WithX( PositionFromTime( Time ) - 3 ).SnapToGrid( 1.0f );
Time += RealTime.SmoothDelta;
Scrubber.Position = Scrubber.Position.WithX( PositionFromTime( Time ) ).SnapToGrid( 1.0f );
if ( Timeline.Playing )
Time += RealTime.SmoothDelta;
}

if ( SoundHandle.IsValid() )
{
SoundHandle.Paused = Scrubbing;
}

TimeAxis.Update();
WaveForm.Update();

if ( Scrubbing || Timeline.Playing )
{
Translate( 1 );
CenterOn( Scrubber.Position );
}

VisibleRect = Rect.FromPoints( ToScene( LocalRect.TopLeft ), ToScene( LocalRect.BottomRight ) );

TimeAxis.Update();
WaveForm.Update();
}

public float PositionFromTime( float time )
Expand All @@ -261,8 +264,8 @@ public void SetSamples( short[] samples, float duration, string sound )

public void MoveScrubber( float position, bool centreOn = true )
{
Scrubber.Position = Vector2.Right * (position - 4).SnapToGrid( 1.0f );
Time = TimeFromPosition( Scrubber.Position.x + 4 );
Scrubber.Position = Vector2.Right * position.Clamp( 0, SceneRect.Width + 4 ).SnapToGrid( 1.0f );
Time = TimeFromPosition( Scrubber.Position.x );

if ( SoundHandle.IsValid() )
{
Expand All @@ -285,6 +288,8 @@ protected override void OnWheel( WheelEvent e )

DoLayout();

VisibleRect = Rect.FromPoints( ToScene( LocalRect.TopLeft ), ToScene( LocalRect.BottomRight ) );

TimeAxis.Update();
WaveForm.Update();

Expand Down