Files
sbox-public/game/addons/tools/Code/Scene/SceneView/EditorToolButton.cs
Antoine Pilote 850f54d922 add shortcut on tooltip of Play/Stop, pause and eject (#5282)
* add shortcut on tooltip of Play/Stop, pause and eject
* Update keybinds when they change
2026-07-08 09:01:42 -07:00

89 lines
1.6 KiB
C#

namespace Editor;
internal class EditorToolButton : Widget
{
public Action Action { get; set; }
public Func<bool> IsActive { get; set; }
public Func<string> GetIcon { get; set; } = null!;
public new bool Enabled
{
get => base.Enabled;
set
{
base.Enabled = value;
Cursor = value ? CursorShape.Finger : CursorShape.Arrow;
}
}
public Color Color { get; set; } = Theme.TextLight;
public EditorToolButton()
{
Cursor = CursorShape.Finger;
MinimumWidth = Theme.RowHeight;
}
protected override Vector2 SizeHint()
{
return new Vector2( Theme.ControlHeight );
}
protected override void OnDoubleClick( MouseEvent e )
{
// e.Accepted = false;
}
protected override void OnMousePress( MouseEvent e )
{
if ( !Enabled )
return;
if ( e.LeftMouseButton )
{
Action?.Invoke();
e.Accepted = true;
}
}
protected override void OnPaint()
{
Paint.Antialiasing = true;
Paint.TextAntialiasing = true;
bool active = IsActive?.Invoke() ?? false;
if ( active )
{
Paint.ClearPen();
Paint.SetBrush( Theme.Blue );
Paint.DrawRect( LocalRect, Theme.ControlRadius );
Paint.Pen = Theme.Text;
}
else
{
Paint.ClearPen();
Paint.SetPen( Color );
if ( Paint.HasMouseOver )
{
Paint.SetPen( Color.Lighten( 0.8f ) );
}
}
if ( !Enabled )
{
Paint.SetPen( Color.Darken( 0.2f ).WithAlpha( 0.5f ) );
}
Paint.DrawIcon( LocalRect, GetIcon(), HeaderBarStyle.IconSize, TextFlag.Center );
}
public void UpdateState()
{
SetContentHash( HashCode.Combine( IsActive?.Invoke() ?? false, Color ), 0.1f );
}
}