using System; using System.Numerics; using System.Text; using Robust.Client.Graphics; using Robust.Shared.Map; using Robust.Shared.Maths; namespace Robust.Client.Input { public abstract class InputEventArgs : EventArgs { public bool Handled { get; private set; } /// /// Mark this event as handled. /// public void Handle() { Handled = true; } } /// /// Generic input event that has modifier keys like control. /// public abstract class ModifierInputEventArgs : InputEventArgs { /// /// Whether the alt key (⌥ Option on MacOS) is held. /// public bool Alt { get; } /// /// Whether the control key is held. /// public bool Control { get; } /// /// Whether the shift key is held. /// public bool Shift { get; } /// /// Whether the system key (Windows key, ⌘ Command on MacOS) is held. /// public bool System { get; } protected ModifierInputEventArgs(bool alt, bool control, bool shift, bool system) { Alt = alt; Control = control; Shift = shift; System = system; } } /// /// Information about text that has been typed by the user. /// /// The typed text. public sealed record TextEnteredEventArgs(string Text); /// /// Information about an in-progress IME composition. /// /// /// https://wiki.libsdl.org/Tutorials-TextInput /// /// /// The position in the composition at which the cursor should be placed. This is in runes, not chars. /// This is in runes, not chars. public sealed record TextEditingEventArgs(string Text, int Start, int Length) { /// /// Get but in chars instead of runes. /// public int GetStartChars() { var chars = 0; var count = 0; foreach (var rune in Text.EnumerateRunes()) { if (count >= Start) break; count += 1; chars += rune.Utf16SequenceLength; } return chars; } } [Virtual] public class KeyEventArgs : ModifierInputEventArgs { /// /// The key that got pressed or released. /// public Keyboard.Key Key { get; } /// /// If true, this key is being held down and another key event is being fired by the OS. /// public bool IsRepeat { get; } public int ScanCode { get; } internal ushort RawCode { get; } public KeyEventArgs( Keyboard.Key key, bool repeat, bool alt, bool control, bool shift, bool system, int scanCode, ushort rawCode=0) : base(alt, control, shift, system) { Key = key; IsRepeat = repeat; ScanCode = scanCode; RawCode = rawCode; } } public abstract class MouseEventArgs : InputEventArgs { /// /// Position of the mouse relative to the screen. /// public ScreenCoordinates Position { get; } protected MouseEventArgs(ScreenCoordinates position) { Position = position; } } public sealed class MouseButtonEventArgs : MouseEventArgs { /// /// The mouse button that has been pressed or released. /// public Mouse.Button Button { get; } // ALL the parameters! public MouseButtonEventArgs(Mouse.Button button, ScreenCoordinates position) : base(position) { Button = button; } } public sealed class MouseWheelEventArgs : MouseEventArgs { /// /// The direction the mouse wheel was moved in. /// public Vector2 Delta { get; } // ALL the parameters! public MouseWheelEventArgs(Vector2 delta, ScreenCoordinates position) : base(position) { Delta = delta; } } public sealed class MouseMoveEventArgs : MouseEventArgs { /// /// The new position relative to the previous position. /// public Vector2 Relative { get; } // ALL the parameters! public MouseMoveEventArgs(Vector2 relative, ScreenCoordinates position) : base(position) { Relative = relative; } } public sealed class MouseEnterLeaveEventArgs : EventArgs { public IClydeWindow Window { get; } /// /// True if the mouse ENTERED the window, false if it LEFT the window. /// public bool Entered { get; } // ALL the parameters! public MouseEnterLeaveEventArgs(IClydeWindow window, bool entered) { Window = window; Entered = entered; } } }