using Robust.Client.Input; using Robust.Shared.Input; using Robust.Shared.Map; using Robust.Shared.Maths; using System; using System.Numerics; namespace Robust.Client.UserInterface { public partial class Control { /// /// Invoked when the mouse enters the area of this control / when it hovers over the control. /// public event Action? OnMouseEntered; protected internal virtual void MouseEntered() { OnMouseEntered?.Invoke(new GUIMouseHoverEventArgs(this)); } /// /// Invoked when the mouse exits the area of this control / when it stops hovering over the control. /// public event Action? OnMouseExited; protected internal virtual void MouseExited() { OnMouseExited?.Invoke(new GUIMouseHoverEventArgs(this)); } protected internal virtual void MouseWheel(GUIMouseWheelEventArgs args) { } public event Action? OnKeyBindDown; public event Action? OnKeyBindUp; protected internal virtual void KeyBindDown(GUIBoundKeyEventArgs args) { OnKeyBindDown?.Invoke(args); } protected internal virtual void KeyBindUp(GUIBoundKeyEventArgs args) { OnKeyBindUp?.Invoke(args); } protected internal virtual void MouseMove(GUIMouseMoveEventArgs args) { } protected internal virtual void KeyHeld(GUIKeyEventArgs args) { } protected internal virtual void TextEntered(GUITextEnteredEventArgs args) { } protected internal virtual void TextEditing(GUITextEditingEventArgs args) { } } public sealed class GUIMouseHoverEventArgs : EventArgs { /// /// The control this event originated from. /// public Control SourceControl { get; } public GUIMouseHoverEventArgs(Control sourceControl) { SourceControl = sourceControl; } } public sealed class GUIBoundKeyEventArgs : BoundKeyEventArgs { /// /// Position of the mouse, relative to the current control. /// public Vector2 RelativePosition { get; internal set; } public Vector2 RelativePixelPosition { get; internal set; } public GUIBoundKeyEventArgs(BoundKeyFunction function, BoundKeyState state, ScreenCoordinates pointerLocation, bool canFocus, Vector2 relativePosition, Vector2 relativePixelPosition) : base(function, state, pointerLocation, canFocus) { RelativePosition = relativePosition; RelativePixelPosition = relativePixelPosition; } } public sealed class GUIKeyEventArgs : KeyEventArgs { /// /// The control spawning this event. /// public Control SourceControl { get; } public GUIKeyEventArgs(Control sourceControl, Keyboard.Key key, bool repeat, bool alt, bool control, bool shift, bool system, int scanCode) : base(key, repeat, alt, control, shift, system, scanCode) { SourceControl = sourceControl; } } /// /// Information about text typed on a keyboard-focused UI control. /// /// The control spawning this event. /// Event data for the typed text. public sealed record GUITextEnteredEventArgs(Control SourceControl, TextEnteredEventArgs TextEnteredEvent) { /// /// The text typed by the user. /// public string Text => TextEnteredEvent.Text; } public sealed record GUITextEditingEventArgs(Control SourceControl, TextEditingEventArgs Event); public abstract class GUIMouseEventArgs : InputEventArgs { /// /// The control spawning this event. /// public Control SourceControl { get; internal set; } /// /// Position of the mouse, relative to the screen. /// public Vector2 GlobalPosition { get; } public ScreenCoordinates GlobalPixelPosition { get; } /// /// Position of the mouse, relative to the current control. /// public Vector2 RelativePosition { get; internal set; } public Vector2 RelativePixelPosition { get; internal set; } protected GUIMouseEventArgs(Control sourceControl, Vector2 globalPosition, ScreenCoordinates globalPixelPosition, Vector2 relativePosition, Vector2 relativePixelPosition) { SourceControl = sourceControl; GlobalPosition = globalPosition; RelativePosition = relativePosition; RelativePixelPosition = relativePixelPosition; GlobalPixelPosition = globalPixelPosition; } } public sealed class GUIMouseMoveEventArgs : GUIMouseEventArgs { /// /// The new position relative to the previous position. /// public Vector2 Relative { get; } // ALL the parameters! public GUIMouseMoveEventArgs(Vector2 relative, Control sourceControl, Vector2 globalPosition, ScreenCoordinates globalPixelPosition, Vector2 relativePosition, Vector2 relativePixelPosition) : base(sourceControl, globalPosition, globalPixelPosition, relativePosition, relativePixelPosition) { Relative = relative; } } public sealed class GUIMouseWheelEventArgs : GUIMouseEventArgs { public Vector2 Delta { get; } public GUIMouseWheelEventArgs(Vector2 delta, Control sourceControl, Vector2 globalPosition, ScreenCoordinates globalPixelPosition, Vector2 relativePosition, Vector2 relativePixelPosition) : base(sourceControl, globalPosition, globalPixelPosition, relativePosition, relativePixelPosition) { Delta = delta; } } }