diff --git a/game/addons/tools/Code/Widgets/SoundPlayer/SoundPlayer.Scrubber.cs b/game/addons/tools/Code/Widgets/SoundPlayer/SoundPlayer.Scrubber.cs index 62b015fc..2f113e5a 100644 --- a/game/addons/tools/Code/Widgets/SoundPlayer/SoundPlayer.Scrubber.cs +++ b/game/addons/tools/Code/Widgets/SoundPlayer/SoundPlayer.Scrubber.cs @@ -14,6 +14,7 @@ public partial class SoundPlayer Cursor = CursorShape.SizeH; Movable = true; Selectable = true; + HandlePosition = new( 0.5f, 0f ); } protected override void OnPaint() @@ -41,6 +42,7 @@ public partial class SoundPlayer protected override void OnMouseReleased( GraphicsMouseEvent e ) { base.OnMouseReleased( e ); + TimelineView.MoveScrubber( Position.x ); TimelineView.Scrubbing = false; } @@ -49,7 +51,7 @@ public partial class SoundPlayer base.OnMoved(); TimelineView.Scrubbing = true; - TimelineView.MoveScrubber( Position.x, false ); + TimelineView.MoveScrubber( Position.x + 0.5f, false ); } } diff --git a/game/addons/tools/Code/Widgets/SoundPlayer/SoundPlayer.cs b/game/addons/tools/Code/Widgets/SoundPlayer/SoundPlayer.cs index 2ae98920..a17e0504 100644 --- a/game/addons/tools/Code/Widgets/SoundPlayer/SoundPlayer.cs +++ b/game/addons/tools/Code/Widgets/SoundPlayer/SoundPlayer.cs @@ -129,7 +129,7 @@ public partial class SoundPlayer : Widget { Timeline = parent; SceneRect = new( 0, Size ); - HorizontalScrollbar = ScrollbarMode.On; + HorizontalScrollbar = ScrollbarMode.Auto; VerticalScrollbar = ScrollbarMode.Off; Scale = 1; Time = 0; @@ -152,6 +152,7 @@ public partial class SoundPlayer : Widget 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 ); @@ -162,7 +163,7 @@ public partial class SoundPlayer : Widget 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() @@ -191,8 +192,6 @@ public partial class SoundPlayer : Widget SoundHandle = null; } - VisibleRect = Rect.FromPoints( ToScene( LocalRect.TopLeft ), ToScene( LocalRect.BottomRight ) ); - if ( Timeline.Playing && !Scrubbing ) { var time = Time % Duration; @@ -219,13 +218,14 @@ public partial class SoundPlayer : Widget 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() ) @@ -233,13 +233,16 @@ public partial class SoundPlayer : Widget 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 ) @@ -261,8 +264,8 @@ public partial class SoundPlayer : Widget 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() ) { @@ -285,6 +288,8 @@ public partial class SoundPlayer : Widget DoLayout(); + VisibleRect = Rect.FromPoints( ToScene( LocalRect.TopLeft ), ToScene( LocalRect.BottomRight ) ); + TimeAxis.Update(); WaveForm.Update();