mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-01-11 07:48:36 -05:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
65 lines
1.8 KiB
C#
65 lines
1.8 KiB
C#
using NativeEngine;
|
|
|
|
namespace Sandbox.UI;
|
|
|
|
/// <summary>
|
|
/// Keyboard (and mouse) key press <see cref="PanelEvent"/>.
|
|
/// </summary>
|
|
public record ButtonEvent
|
|
{
|
|
/// <summary>
|
|
/// The button that triggered the event.
|
|
/// </summary>
|
|
public string Button { get; }
|
|
|
|
/// <summary>
|
|
/// Whether the button was pressed in, or release.
|
|
/// </summary>
|
|
public bool Pressed { get; }
|
|
|
|
|
|
public int VirtualKey { get; }
|
|
|
|
/// <summary>
|
|
/// The keyboard modifier keys that were held down at the moment the event triggered.
|
|
/// </summary>
|
|
public KeyboardModifiers KeyboardModifiers { get; }
|
|
|
|
/// <summary>
|
|
/// Whether <c>Shift</c> key was being held down at the time of the event.
|
|
/// </summary>
|
|
public bool HasShift => KeyboardModifiers.Contains( KeyboardModifiers.Shift );
|
|
|
|
/// <summary>
|
|
/// Whether <c>Control</c> key was being held down at the time of the event.
|
|
/// </summary>
|
|
public bool HasCtrl => KeyboardModifiers.Contains( KeyboardModifiers.Ctrl );
|
|
|
|
/// <summary>
|
|
/// Whether <c>Alt</c> key was being held down at the time of the event.
|
|
/// </summary>
|
|
public bool HasAlt => KeyboardModifiers.Contains( KeyboardModifiers.Alt );
|
|
|
|
/// <summary>
|
|
/// Set to <see langword="true"/> to prevent the event from propagating to the parent panel.
|
|
/// </summary>
|
|
public bool StopPropagation { get; set; }
|
|
|
|
|
|
internal ButtonEvent( ButtonCode button, bool pressed, KeyboardModifiers modifiers )
|
|
{
|
|
Button = InputEventQueue.NormalizeButtonName( button.ToString() );
|
|
Pressed = pressed;
|
|
VirtualKey = InputSystem.ButtonCodeToVirtualKey( button );
|
|
KeyboardModifiers = modifiers;
|
|
}
|
|
|
|
internal ButtonEvent( ButtonCode button, bool pressed )
|
|
{
|
|
Button = InputEventQueue.NormalizeButtonName( button.ToString() );
|
|
Pressed = pressed;
|
|
}
|
|
|
|
public override string ToString() => $"{Button} {(Pressed ? "pressed" : "released")}";
|
|
}
|