Editor/AudioScrubber.cs
using Editor;
using Sandbox;
namespace Ardi;
public class AudioScrubber : GraphicsItem
{
private readonly AudioTimelineView TimelineView;
public AudioScrubber( AudioTimelineView view ) : base( null )
{
TimelineView = view;
ZIndex = -1f;
HoverEvents = true;
Cursor = CursorShape.OpenHand;
Movable = true;
Selectable = true;
}
protected override void OnPaint()
{
base.OnPaint();
Paint.Antialiasing = false;
Paint.ClearPen();
var color = Theme.Green.WithAlpha( 0.7f );
Paint.SetBrush( color );
var top = new Vector2( 0f, Theme.RowHeight / 2f + 1f );
var size = new Vector2( LocalRect.Width, Theme.RowHeight / 2f );
var rect = new Rect( top, size );
var polygon = new Vector2[]
{
rect.TopLeft,
rect.TopRight,
rect.BottomRight - new Vector2( 0f, 4f ),
rect.Center.WithY( rect.Bottom ),
rect.BottomLeft - new Vector2( 0f, 4f )
};
Paint.DrawPolygon( polygon );
color = Theme.Green.WithAlpha( 0.7f );
Paint.SetPen( color );
var lineStart = new Vector2( 4f, Theme.RowHeight + 1f );
var lineEnd = new Vector2( 4f, LocalRect.Bottom );
Paint.DrawLine( lineStart, lineEnd );
}
protected override void OnMousePressed( GraphicsMouseEvent e )
{
base.OnMousePressed( e );
TimelineView.Scrubbing = true;
}
protected override void OnMouseReleased( GraphicsMouseEvent e )
{
base.OnMouseReleased( e );
TimelineView.Scrubbing = false;
}
protected override void OnMoved()
{
base.OnMoved();
TimelineView.Scrubbing = true;
TimelineView.MoveScrubber( Position.x, centreOn: false );
}
}