Files
sbox-public/game/addons/tools/Code/Widgets/SoundPlayer/SoundPlayer.Scrubber.cs
sboxbot dbdfbff73a Sound preview misc fixes (#3655)
* start sound preview playback at scrubber position instead of 0, only increment time if playing

* Fix SceneRect calculation so that there isnt 4 pixels of extra scroll when zoomed all the way out, only show scroll bar if there's anything to scroll

* clamp scrubber position so it cant be visually dragged outside normal bounds

* use correct offset when setting scrubber position during playback

* update VisibleRect before redrawing waveform, waveform was previously drawing in wrong position (view from last frame)

* clamp on scrubber should be using SceneRect not ContentRect

* no need to update VisibleRect twice

* use correct offset for scrubber in DoLayout too

* update scrubber so it stays nice and stable while playing+zoomed in or scrubbing, use correct offset when manipulating scrubber

* offsetting by 4 everywhere is dumb just set HandlePosition on scrubber

* fix drift on scrubber while zoomed in

---------

Co-authored-by: boxrocket <splatterbiker@gmail.com>
2025-12-22 13:55:12 +00:00

59 lines
1.4 KiB
C#

namespace Editor;
public partial class SoundPlayer
{
public class Scrubber : GraphicsItem
{
private readonly TimelineView TimelineView;
public Scrubber( TimelineView view )
{
TimelineView = view;
ZIndex = -1;
HoverEvents = true;
Cursor = CursorShape.SizeH;
Movable = true;
Selectable = true;
HandlePosition = new( 0.5f, 0f );
}
protected override void OnPaint()
{
base.OnPaint();
Paint.Antialiasing = false;
Paint.ClearPen();
Paint.SetBrush( Theme.Green.WithAlpha( 0.7f ) );
var boxRect = new Rect( new Vector2( 0, (Theme.RowHeight / 2) + 1 ), new Vector2( LocalRect.Width, Theme.RowHeight / 2 ) );
Paint.DrawPolygon( boxRect.TopLeft, boxRect.TopRight, boxRect.BottomRight - new Vector2( 0, 4 ), boxRect.Center.WithY( boxRect.Bottom ), boxRect.BottomLeft - new Vector2( 0, 4 ) );
Paint.SetPen( Theme.Green.WithAlpha( 0.7f ) );
Paint.DrawLine( new Vector2( 4, Theme.RowHeight + 1 ), new Vector2( 4, LocalRect.Bottom ) );
}
protected override void OnMousePressed( GraphicsMouseEvent e )
{
base.OnMousePressed( e );
TimelineView.Scrubbing = true;
}
protected override void OnMouseReleased( GraphicsMouseEvent e )
{
base.OnMouseReleased( e );
TimelineView.MoveScrubber( Position.x );
TimelineView.Scrubbing = false;
}
protected override void OnMoved()
{
base.OnMoved();
TimelineView.Scrubbing = true;
TimelineView.MoveScrubber( Position.x + 0.5f, false );
}
}
}