using System; namespace Artemis.Core.Services; /// /// Represents an interface for an input provider that provides and implementation for sending and receiving device /// input /// public abstract class InputProvider : IDisposable { public InputProvider() { ProviderName = GetType().FullName ?? throw new InvalidOperationException("Input provider must have a type with a name"); } internal string ProviderName { get; set; } /// /// Called when the input service requests a event /// public virtual void OnKeyboardToggleStatusRequested() { } /// /// Occurs when the input provided has received keyboard data /// public event EventHandler? KeyboardDataReceived; /// /// Occurs when the input provider has received new toggle data for keyboards /// public event EventHandler? KeyboardToggleStatusReceived; /// /// Occurs when the input provided has received mouse button data /// public event EventHandler? MouseButtonDataReceived; /// /// Occurs when the input provided has received mouse scroll data /// public event EventHandler? MouseScrollDataReceived; /// /// Occurs when the input provided has received mouse move data /// public event EventHandler? MouseMoveDataReceived; /// /// Occurs when the input provided received a device identifier /// public event EventHandler? IdentifierReceived; /// /// Invokes the event which the listens to as long as /// this provider is registered /// /// The device that triggered the event /// The key that triggered the event /// Whether the key is pressed down protected virtual void OnKeyboardDataReceived(ArtemisDevice? device, KeyboardKey key, bool isDown) { KeyboardDataReceived?.Invoke(this, new InputProviderKeyboardEventArgs(device, key, isDown)); } /// /// Invokes the event which the listens to as long /// as this provider is registered /// /// The device that triggered the event /// The button that triggered the event /// Whether the button is pressed down protected virtual void OnMouseButtonDataReceived(ArtemisDevice? device, MouseButton button, bool isDown) { MouseButtonDataReceived?.Invoke(this, new InputProviderMouseButtonEventArgs(device, button, isDown)); } /// /// Invokes the event which the listens to as long /// as this provider is registered /// /// The device that triggered the event /// The direction in which was scrolled /// The scroll delta (can positive or negative) protected virtual void OnMouseScrollDataReceived(ArtemisDevice? device, MouseScrollDirection direction, int delta) { MouseScrollDataReceived?.Invoke(this, new InputProviderMouseScrollEventArgs(device, direction, delta)); } /// /// Invokes the event which the listens to as long as /// this provider is registered /// /// The device that triggered the event /// The X position of the mouse cursor (not necessarily tied to the specific device) /// The Y position of the mouse cursor (not necessarily tied to the specific device) /// The movement delta in the horizontal direction /// The movement delta in the vertical direction protected virtual void OnMouseMoveDataReceived(ArtemisDevice? device, int cursorX, int cursorY, int deltaX, int deltaY) { MouseMoveDataReceived?.Invoke(this, new InputProviderMouseMoveEventArgs(device, cursorX, cursorY, deltaX, deltaY)); } // TODO: Remove this as the core should handle this in GetDeviceByIdentifier /// /// Invokes the event which the listens to as long as /// this provider is registered /// Except for on mouse movement, call this whenever you have an identifier ready for the core to process /// /// A value that can be used to identify this device /// The type of device this identifier belongs to protected virtual void OnIdentifierReceived(object identifier, InputDeviceType deviceType) { IdentifierReceived?.Invoke(this, new InputProviderIdentifierEventArgs(identifier, deviceType)); } /// /// Invokes the event which the listens to as /// long as /// this provider is registered /// /// The toggle status of the keyboard protected virtual void OnKeyboardToggleStatusReceived(KeyboardToggleStatus keyboardToggleStatus) { KeyboardToggleStatusReceived?.Invoke(this, new InputProviderKeyboardToggleEventArgs(keyboardToggleStatus)); } /// /// Releases the unmanaged resources used by the object and optionally releases the managed resources. /// /// /// to release both managed and unmanaged resources; /// to release only unmanaged resources. /// protected virtual void Dispose(bool disposing) { if (disposing) { } } /// public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } }