From 2372c194f10d8f9ef7ea2dc415aa1613fbfc078a Mon Sep 17 00:00:00 2001 From: Ac_K Date: Tue, 6 Dec 2022 16:32:14 +0100 Subject: ava: Cleanup Input classes (#4042) * ava: Cleanup Input classes This PR just cleanup all Input classes for consistencies. * Addresses TSRBerry's feedback --- Ryujinx.Ava/Input/AvaloniaKeyboard.cs | 98 ++++++----- Ryujinx.Ava/Input/AvaloniaKeyboardDriver.cs | 34 ++-- Ryujinx.Ava/Input/AvaloniaKeyboardMappingHelper.cs | 186 ++++++++++++++++++++ Ryujinx.Ava/Input/AvaloniaMappingHelper.cs | 188 --------------------- Ryujinx.Ava/Input/AvaloniaMouse.cs | 11 +- Ryujinx.Ava/Input/AvaloniaMouseDriver.cs | 75 ++++---- .../Ui/Applet/AvaloniaDynamicTextInputHandler.cs | 4 +- Ryujinx.Ava/Ui/ViewModels/MainWindowViewModel.cs | 6 +- 8 files changed, 293 insertions(+), 309 deletions(-) create mode 100644 Ryujinx.Ava/Input/AvaloniaKeyboardMappingHelper.cs delete mode 100644 Ryujinx.Ava/Input/AvaloniaMappingHelper.cs diff --git a/Ryujinx.Ava/Input/AvaloniaKeyboard.cs b/Ryujinx.Ava/Input/AvaloniaKeyboard.cs index 5b888bf5..d40ebbd2 100644 --- a/Ryujinx.Ava/Input/AvaloniaKeyboard.cs +++ b/Ryujinx.Ava/Input/AvaloniaKeyboard.cs @@ -4,7 +4,6 @@ using Ryujinx.Input; using System; using System.Collections.Generic; using System.Numerics; - using ConfigKey = Ryujinx.Common.Configuration.Hid.Key; using Key = Ryujinx.Input.Key; @@ -13,30 +12,37 @@ namespace Ryujinx.Ava.Input internal class AvaloniaKeyboard : IKeyboard { private readonly List _buttonsUserMapping; - private readonly AvaloniaKeyboardDriver _driver; + private readonly AvaloniaKeyboardDriver _driver; + private StandardKeyboardInputConfig _configuration; private readonly object _userMappingLock = new(); - private StandardKeyboardInputConfig _configuration; - - private bool HasConfiguration => _configuration != null; - - public string Id { get; } + public string Id { get; } public string Name { get; } - public bool IsConnected => true; + public bool IsConnected => true; + public GamepadFeaturesFlag Features => GamepadFeaturesFlag.None; + + private class ButtonMappingEntry + { + public readonly Key From; + public readonly GamepadButtonInputId To; - public GamepadFeaturesFlag Features => GamepadFeaturesFlag.None; + public ButtonMappingEntry(GamepadButtonInputId to, Key from) + { + To = to; + From = from; + } + } public AvaloniaKeyboard(AvaloniaKeyboardDriver driver, string id, string name) { - _driver = driver; - Id = id; - Name = name; _buttonsUserMapping = new List(); - } - public void Dispose() { } + _driver = driver; + Id = id; + Name = name; + } public KeyboardStateSnapshot GetKeyboardStateSnapshot() { @@ -46,11 +52,11 @@ namespace Ryujinx.Ava.Input public GamepadStateSnapshot GetMappedStateSnapshot() { KeyboardStateSnapshot rawState = GetKeyboardStateSnapshot(); - GamepadStateSnapshot result = default; + GamepadStateSnapshot result = default; lock (_userMappingLock) { - if (!HasConfiguration) + if (_configuration == null) { return result; } @@ -62,17 +68,17 @@ namespace Ryujinx.Ava.Input continue; } - // Do not touch state of the button already pressed + // NOTE: Do not touch state of the button already pressed. if (!result.IsPressed(entry.To)) { result.SetPressed(entry.To, rawState.IsPressed(entry.From)); } } - (short leftStickX, short leftStickY) = GetStickValues(ref rawState, _configuration.LeftJoyconStick); + (short leftStickX, short leftStickY) = GetStickValues(ref rawState, _configuration.LeftJoyconStick); (short rightStickX, short rightStickY) = GetStickValues(ref rawState, _configuration.RightJoyconStick); - result.SetStick(StickInputId.Left, ConvertRawStickValue(leftStickX), ConvertRawStickValue(leftStickY)); + result.SetStick(StickInputId.Left, ConvertRawStickValue(leftStickX), ConvertRawStickValue(leftStickY)); result.SetStick(StickInputId.Right, ConvertRawStickValue(rightStickX), ConvertRawStickValue(rightStickY)); } @@ -114,29 +120,29 @@ namespace Ryujinx.Ava.Input _buttonsUserMapping.Clear(); - // Left joycon - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.LeftStick, (Key)_configuration.LeftJoyconStick.StickButton)); - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.DpadUp, (Key)_configuration.LeftJoycon.DpadUp)); - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.DpadDown, (Key)_configuration.LeftJoycon.DpadDown)); - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.DpadLeft, (Key)_configuration.LeftJoycon.DpadLeft)); - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.DpadRight, (Key)_configuration.LeftJoycon.DpadRight)); - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.Minus, (Key)_configuration.LeftJoycon.ButtonMinus)); - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.LeftShoulder, (Key)_configuration.LeftJoycon.ButtonL)); - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.LeftTrigger, (Key)_configuration.LeftJoycon.ButtonZl)); + // Left JoyCon + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.LeftStick, (Key)_configuration.LeftJoyconStick.StickButton)); + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.DpadUp, (Key)_configuration.LeftJoycon.DpadUp)); + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.DpadDown, (Key)_configuration.LeftJoycon.DpadDown)); + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.DpadLeft, (Key)_configuration.LeftJoycon.DpadLeft)); + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.DpadRight, (Key)_configuration.LeftJoycon.DpadRight)); + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.Minus, (Key)_configuration.LeftJoycon.ButtonMinus)); + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.LeftShoulder, (Key)_configuration.LeftJoycon.ButtonL)); + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.LeftTrigger, (Key)_configuration.LeftJoycon.ButtonZl)); _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.SingleRightTrigger0, (Key)_configuration.LeftJoycon.ButtonSr)); - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.SingleLeftTrigger0, (Key)_configuration.LeftJoycon.ButtonSl)); - - // Finally right joycon - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.RightStick, (Key)_configuration.RightJoyconStick.StickButton)); - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.A, (Key)_configuration.RightJoycon.ButtonA)); - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.B, (Key)_configuration.RightJoycon.ButtonB)); - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.X, (Key)_configuration.RightJoycon.ButtonX)); - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.Y, (Key)_configuration.RightJoycon.ButtonY)); - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.Plus, (Key)_configuration.RightJoycon.ButtonPlus)); - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.RightShoulder, (Key)_configuration.RightJoycon.ButtonR)); - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.RightTrigger, (Key)_configuration.RightJoycon.ButtonZr)); + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.SingleLeftTrigger0, (Key)_configuration.LeftJoycon.ButtonSl)); + + // Right JoyCon + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.RightStick, (Key)_configuration.RightJoyconStick.StickButton)); + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.A, (Key)_configuration.RightJoycon.ButtonA)); + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.B, (Key)_configuration.RightJoycon.ButtonB)); + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.X, (Key)_configuration.RightJoycon.ButtonX)); + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.Y, (Key)_configuration.RightJoycon.ButtonY)); + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.Plus, (Key)_configuration.RightJoycon.ButtonPlus)); + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.RightShoulder, (Key)_configuration.RightJoycon.ButtonR)); + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.RightTrigger, (Key)_configuration.RightJoycon.ButtonZr)); _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.SingleRightTrigger1, (Key)_configuration.RightJoycon.ButtonSr)); - _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.SingleLeftTrigger1, (Key)_configuration.RightJoycon.ButtonSl)); + _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.SingleLeftTrigger1, (Key)_configuration.RightJoycon.ButtonSl)); } } @@ -190,16 +196,6 @@ namespace Ryujinx.Ava.Input _driver?.ResetKeys(); } - private class ButtonMappingEntry - { - public readonly Key From; - public readonly GamepadButtonInputId To; - - public ButtonMappingEntry(GamepadButtonInputId to, Key from) - { - To = to; - From = from; - } - } + public void Dispose() { } } } \ No newline at end of file diff --git a/Ryujinx.Ava/Input/AvaloniaKeyboardDriver.cs b/Ryujinx.Ava/Input/AvaloniaKeyboardDriver.cs index 910de186..31a53c32 100644 --- a/Ryujinx.Ava/Input/AvaloniaKeyboardDriver.cs +++ b/Ryujinx.Ava/Input/AvaloniaKeyboardDriver.cs @@ -4,7 +4,6 @@ using Ryujinx.Ava.Common.Locale; using Ryujinx.Input; using System; using System.Collections.Generic; - using AvaKey = Avalonia.Input.Key; using Key = Ryujinx.Input.Key; @@ -13,24 +12,23 @@ namespace Ryujinx.Ava.Input internal class AvaloniaKeyboardDriver : IGamepadDriver { private static readonly string[] _keyboardIdentifers = new string[1] { "0" }; - private readonly Control _control; + private readonly Control _control; private readonly HashSet _pressedKeys; public event EventHandler KeyPressed; public event EventHandler KeyRelease; - public event EventHandler TextInput; - - public string DriverName => "Avalonia"; + public event EventHandler TextInput; + public string DriverName => "AvaloniaKeyboardDriver"; public ReadOnlySpan GamepadsIds => _keyboardIdentifers; public AvaloniaKeyboardDriver(Control control) { - _control = control; + _control = control; _pressedKeys = new HashSet(); - _control.KeyDown += OnKeyPress; - _control.KeyUp += OnKeyRelease; + _control.KeyDown += OnKeyPress; + _control.KeyUp += OnKeyRelease; _control.TextInput += Control_TextInput; } @@ -41,21 +39,16 @@ namespace Ryujinx.Ava.Input public event Action OnGamepadConnected { - add { } + add { } remove { } } public event Action OnGamepadDisconnected { - add { } + add { } remove { } } - public void Dispose() - { - Dispose(true); - } - public IGamepad GetGamepad(string id) { if (!_keyboardIdentifers[0].Equals(id)) @@ -70,15 +63,13 @@ namespace Ryujinx.Ava.Input { if (disposing) { - _control.KeyUp -= OnKeyPress; + _control.KeyUp -= OnKeyPress; _control.KeyDown -= OnKeyRelease; } } protected void OnKeyPress(object sender, KeyEventArgs args) { - AvaKey key = args.Key; - _pressedKeys.Add(args.Key); KeyPressed?.Invoke(this, args); @@ -98,7 +89,7 @@ namespace Ryujinx.Ava.Input return false; } - AvaloniaMappingHelper.TryGetAvaKey(key, out var nativeKey); + AvaloniaKeyboardMappingHelper.TryGetAvaKey(key, out var nativeKey); return _pressedKeys.Contains(nativeKey); } @@ -107,5 +98,10 @@ namespace Ryujinx.Ava.Input { _pressedKeys.Clear(); } + + public void Dispose() + { + Dispose(true); + } } } \ No newline at end of file diff --git a/Ryujinx.Ava/Input/AvaloniaKeyboardMappingHelper.cs b/Ryujinx.Ava/Input/AvaloniaKeyboardMappingHelper.cs new file mode 100644 index 00000000..8400ddad --- /dev/null +++ b/Ryujinx.Ava/Input/AvaloniaKeyboardMappingHelper.cs @@ -0,0 +1,186 @@ +using Ryujinx.Input; +using System; +using System.Collections.Generic; +using AvaKey = Avalonia.Input.Key; + +namespace Ryujinx.Ava.Input +{ + internal static class AvaloniaKeyboardMappingHelper + { + private static readonly AvaKey[] _keyMapping = new AvaKey[(int)Key.Count] + { + // NOTE: Invalid + AvaKey.None, + + AvaKey.LeftShift, + AvaKey.RightShift, + AvaKey.LeftCtrl, + AvaKey.RightCtrl, + AvaKey.LeftAlt, + AvaKey.RightAlt, + AvaKey.LWin, + AvaKey.RWin, + AvaKey.Apps, + AvaKey.F1, + AvaKey.F2, + AvaKey.F3, + AvaKey.F4, + AvaKey.F5, + AvaKey.F6, + AvaKey.F7, + AvaKey.F8, + AvaKey.F9, + AvaKey.F10, + AvaKey.F11, + AvaKey.F12, + AvaKey.F13, + AvaKey.F14, + AvaKey.F15, + AvaKey.F16, + AvaKey.F17, + AvaKey.F18, + AvaKey.F19, + AvaKey.F20, + AvaKey.F21, + AvaKey.F22, + AvaKey.F23, + AvaKey.F24, + + AvaKey.None, + AvaKey.None, + AvaKey.None, + AvaKey.None, + AvaKey.None, + AvaKey.None, + AvaKey.None, + AvaKey.None, + AvaKey.None, + AvaKey.None, + AvaKey.None, + + AvaKey.Up, + AvaKey.Down, + AvaKey.Left, + AvaKey.Right, + AvaKey.Return, + AvaKey.Escape, + AvaKey.Space, + AvaKey.Tab, + AvaKey.Back, + AvaKey.Insert, + AvaKey.Delete, + AvaKey.PageUp, + AvaKey.PageDown, + AvaKey.Home, + AvaKey.End, + AvaKey.CapsLock, + AvaKey.Scroll, + AvaKey.Print, + AvaKey.Pause, + AvaKey.NumLock, + AvaKey.Clear, + AvaKey.NumPad0, + AvaKey.NumPad1, + AvaKey.NumPad2, + AvaKey.NumPad3, + AvaKey.NumPad4, + AvaKey.NumPad5, + AvaKey.NumPad6, + AvaKey.NumPad7, + AvaKey.NumPad8, + AvaKey.NumPad9, + AvaKey.Divide, + AvaKey.Multiply, + AvaKey.Subtract, + AvaKey.Add, + AvaKey.Decimal, + AvaKey.Enter, + AvaKey.A, + AvaKey.B, + AvaKey.C, + AvaKey.D, + AvaKey.E, + AvaKey.F, + AvaKey.G, + AvaKey.H, + AvaKey.I, + AvaKey.J, + AvaKey.K, + AvaKey.L, + AvaKey.M, + AvaKey.N, + AvaKey.O, + AvaKey.P, + AvaKey.Q, + AvaKey.R, + AvaKey.S, + AvaKey.T, + AvaKey.U, + AvaKey.V, + AvaKey.W, + AvaKey.X, + AvaKey.Y, + AvaKey.Z, + AvaKey.D0, + AvaKey.D1, + AvaKey.D2, + AvaKey.D3, + AvaKey.D4, + AvaKey.D5, + AvaKey.D6, + AvaKey.D7, + AvaKey.D8, + AvaKey.D9, + AvaKey.OemTilde, + AvaKey.OemTilde,AvaKey.OemMinus, + AvaKey.OemPlus, + AvaKey.OemOpenBrackets, + AvaKey.OemCloseBrackets, + AvaKey.OemSemicolon, + AvaKey.OemQuotes, + AvaKey.OemComma, + AvaKey.OemPeriod, + AvaKey.OemQuestion, + AvaKey.OemBackslash, + + // NOTE: invalid + AvaKey.None + }; + + private static readonly Dictionary _avaKeyMapping; + + static AvaloniaKeyboardMappingHelper() + { + var inputKeys = Enum.GetValues(typeof(Key)); + + // NOTE: Avalonia.Input.Key is not contiguous and quite large, so use a dictionary instead of an array. + _avaKeyMapping = new Dictionary(); + + foreach (var key in inputKeys) + { + if (TryGetAvaKey((Key)key, out var index)) + { + _avaKeyMapping[index] = (Key)key; + } + } + } + + public static bool TryGetAvaKey(Key key, out AvaKey avaKey) + { + avaKey = AvaKey.None; + + bool keyExist = (int)key < _keyMapping.Length; + if (keyExist) + { + avaKey = _keyMapping[(int)key]; + } + + return keyExist; + } + + public static Key ToInputKey(AvaKey key) + { + return _avaKeyMapping.GetValueOrDefault(key, Key.Unknown); + } + } +} \ No newline at end of file diff --git a/Ryujinx.Ava/Input/AvaloniaMappingHelper.cs b/Ryujinx.Ava/Input/AvaloniaMappingHelper.cs deleted file mode 100644 index e1ef3ebc..00000000 --- a/Ryujinx.Ava/Input/AvaloniaMappingHelper.cs +++ /dev/null @@ -1,188 +0,0 @@ -using Ryujinx.Input; -using System; -using System.Collections.Generic; -using AvaKey = Avalonia.Input.Key; - -namespace Ryujinx.Ava.Input -{ - internal static class AvaloniaMappingHelper - { - private static readonly AvaKey[] _keyMapping = new AvaKey[(int)Key.Count] - { - // NOTE: Invalid - AvaKey.None, - - AvaKey.LeftShift, - AvaKey.RightShift, - AvaKey.LeftCtrl, - AvaKey.RightCtrl, - AvaKey.LeftAlt, - AvaKey.RightAlt, - AvaKey.LWin, - AvaKey.RWin, - AvaKey.Apps, - AvaKey.F1, - AvaKey.F2, - AvaKey.F3, - AvaKey.F4, - AvaKey.F5, - AvaKey.F6, - AvaKey.F7, - AvaKey.F8, - AvaKey.F9, - AvaKey.F10, - AvaKey.F11, - AvaKey.F12, - AvaKey.F13, - AvaKey.F14, - AvaKey.F15, - AvaKey.F16, - AvaKey.F17, - AvaKey.F18, - AvaKey.F19, - AvaKey.F20, - AvaKey.F21, - AvaKey.F22, - AvaKey.F23, - AvaKey.F24, - - AvaKey.None, - AvaKey.None, - AvaKey.None, - AvaKey.None, - AvaKey.None, - AvaKey.None, - AvaKey.None, - AvaKey.None, - AvaKey.None, - AvaKey.None, - AvaKey.None, - - AvaKey.Up, - AvaKey.Down, - AvaKey.Left, - AvaKey.Right, - AvaKey.Return, - AvaKey.Escape, - AvaKey.Space, - AvaKey.Tab, - AvaKey.Back, - AvaKey.Insert, - AvaKey.Delete, - AvaKey.PageUp, - AvaKey.PageDown, - AvaKey.Home, - AvaKey.End, - AvaKey.CapsLock, - AvaKey.Scroll, - AvaKey.Print, - AvaKey.Pause, - AvaKey.NumLock, - AvaKey.Clear, - AvaKey.NumPad0, - AvaKey.NumPad1, - AvaKey.NumPad2, - AvaKey.NumPad3, - AvaKey.NumPad4, - AvaKey.NumPad5, - AvaKey.NumPad6, - AvaKey.NumPad7, - AvaKey.NumPad8, - AvaKey.NumPad9, - AvaKey.Divide, - AvaKey.Multiply, - AvaKey.Subtract, - AvaKey.Add, - AvaKey.Decimal, - AvaKey.Enter, - AvaKey.A, - AvaKey.B, - AvaKey.C, - AvaKey.D, - AvaKey.E, - AvaKey.F, - AvaKey.G, - AvaKey.H, - AvaKey.I, - AvaKey.J, - AvaKey.K, - AvaKey.L, - AvaKey.M, - AvaKey.N, - AvaKey.O, - AvaKey.P, - AvaKey.Q, - AvaKey.R, - AvaKey.S, - AvaKey.T, - AvaKey.U, - AvaKey.V, - AvaKey.W, - AvaKey.X, - AvaKey.Y, - AvaKey.Z, - AvaKey.D0, - AvaKey.D1, - AvaKey.D2, - AvaKey.D3, - AvaKey.D4, - AvaKey.D5, - AvaKey.D6, - AvaKey.D7, - AvaKey.D8, - AvaKey.D9, - AvaKey.OemTilde, - AvaKey.OemTilde,AvaKey.OemMinus, - AvaKey.OemPlus, - AvaKey.OemOpenBrackets, - AvaKey.OemCloseBrackets, - AvaKey.OemSemicolon, - AvaKey.OemQuotes, - AvaKey.OemComma, - AvaKey.OemPeriod, - AvaKey.OemQuestion, - AvaKey.OemBackslash, - - // NOTE: invalid - AvaKey.None - }; - - private static readonly Dictionary _avaKeyMapping; - - static AvaloniaMappingHelper() - { - var inputKeys = Enum.GetValues(typeof(Key)); - - // Avalonia.Input.Key is not contiguous and quite large, so use a dictionary instead of an array. - _avaKeyMapping = new Dictionary(); - - foreach (var key in inputKeys) - { - if (TryGetAvaKey((Key)key, out var index)) - { - _avaKeyMapping[index] = (Key)key; - } - } - } - - public static bool TryGetAvaKey(Key key, out AvaKey avaKey) - { - var keyExist = (int)key < _keyMapping.Length; - if (keyExist) - { - avaKey = _keyMapping[(int)key]; - } - else - { - avaKey = AvaKey.None; - } - - return keyExist; - } - - public static Key ToInputKey(AvaKey key) - { - return _avaKeyMapping.GetValueOrDefault(key, Key.Unknown); - } - } -} \ No newline at end of file diff --git a/Ryujinx.Ava/Input/AvaloniaMouse.cs b/Ryujinx.Ava/Input/AvaloniaMouse.cs index a3ca2ff8..3a9c91c0 100644 --- a/Ryujinx.Ava/Input/AvaloniaMouse.cs +++ b/Ryujinx.Ava/Input/AvaloniaMouse.cs @@ -10,15 +10,12 @@ namespace Ryujinx.Ava.Input { private AvaloniaMouseDriver _driver; - public GamepadFeaturesFlag Features => throw new NotImplementedException(); - - public string Id => "0"; - + public string Id => "0"; public string Name => "AvaloniaMouse"; - public bool IsConnected => true; - - public bool[] Buttons => _driver.PressedButtons; + public bool IsConnected => true; + public GamepadFeaturesFlag Features => throw new NotImplementedException(); + public bool[] Buttons => _driver.PressedButtons; public AvaloniaMouse(AvaloniaMouseDriver driver) { diff --git a/Ryujinx.Ava/Input/AvaloniaMouseDriver.cs b/Ryujinx.Ava/Input/AvaloniaMouseDriver.cs index 9ad0310a..eb58752c 100644 --- a/Ryujinx.Ava/Input/AvaloniaMouseDriver.cs +++ b/Ryujinx.Ava/Input/AvaloniaMouseDriver.cs @@ -11,35 +11,50 @@ namespace Ryujinx.Ava.Input { internal class AvaloniaMouseDriver : IGamepadDriver { - private Control _widget; - private bool _isDisposed; - private Size _size; + private Control _widget; + private bool _isDisposed; + private Size _size; private readonly Window _window; - public bool[] PressedButtons { get; } - + public bool[] PressedButtons { get; } public Vector2 CurrentPosition { get; private set; } - public Vector2 Scroll { get; private set; } + public Vector2 Scroll { get; private set; } + + public string DriverName => "AvaloniaMouseDriver"; + public ReadOnlySpan GamepadsIds => new[] { "0" }; public AvaloniaMouseDriver(Window window, Control parent) { _widget = parent; _window = window; - _widget.PointerMoved += Parent_PointerMovedEvent; - _widget.PointerPressed += Parent_PointerPressEvent; - _widget.PointerReleased += Parent_PointerReleaseEvent; + _widget.PointerMoved += Parent_PointerMovedEvent; + _widget.PointerPressed += Parent_PointerPressEvent; + _widget.PointerReleased += Parent_PointerReleaseEvent; _widget.PointerWheelChanged += Parent_ScrollEvent; - _window.PointerMoved += Parent_PointerMovedEvent; - _window.PointerPressed += Parent_PointerPressEvent; - _window.PointerReleased += Parent_PointerReleaseEvent; + _window.PointerMoved += Parent_PointerMovedEvent; + _window.PointerPressed += Parent_PointerPressEvent; + _window.PointerReleased += Parent_PointerReleaseEvent; _window.PointerWheelChanged += Parent_ScrollEvent; PressedButtons = new bool[(int)MouseButton.Count]; _size = new Size((int)parent.Bounds.Width, (int)parent.Bounds.Height); - parent.GetObservable(Control.BoundsProperty).Subscribe(Resized); + + parent.GetObservable(Visual.BoundsProperty).Subscribe(Resized); + } + + public event Action OnGamepadConnected + { + add { } + remove { } + } + + public event Action OnGamepadDisconnected + { + add { } + remove { } } private void Resized(Rect rect) @@ -59,14 +74,12 @@ namespace Ryujinx.Ava.Input private void Parent_PointerPressEvent(object o, PointerPressedEventArgs args) { - var pointerProperties = args.GetCurrentPoint(_widget).Properties; - - PressedButtons[(int)pointerProperties.PointerUpdateKind] = true; + PressedButtons[(int)args.GetCurrentPoint(_widget).Properties.PointerUpdateKind] = true; } private void Parent_PointerMovedEvent(object o, PointerEventArgs args) { - var position = args.GetPosition(_widget); + Point position = args.GetPosition(_widget); CurrentPosition = new Vector2((float)position.X, (float)position.Y); } @@ -96,22 +109,6 @@ namespace Ryujinx.Ava.Input return _size; } - public string DriverName => "Avalonia"; - - public event Action OnGamepadConnected - { - add { } - remove { } - } - - public event Action OnGamepadDisconnected - { - add { } - remove { } - } - - public ReadOnlySpan GamepadsIds => new[] { "0" }; - public IGamepad GetGamepad(string id) { return new AvaloniaMouse(this); @@ -126,14 +123,14 @@ namespace Ryujinx.Ava.Input _isDisposed = true; - _widget.PointerMoved -= Parent_PointerMovedEvent; - _widget.PointerPressed -= Parent_PointerPressEvent; - _widget.PointerReleased -= Parent_PointerReleaseEvent; + _widget.PointerMoved -= Parent_PointerMovedEvent; + _widget.PointerPressed -= Parent_PointerPressEvent; + _widget.PointerReleased -= Parent_PointerReleaseEvent; _widget.PointerWheelChanged -= Parent_ScrollEvent; - _window.PointerMoved -= Parent_PointerMovedEvent; - _window.PointerPressed -= Parent_PointerPressEvent; - _window.PointerReleased -= Parent_PointerReleaseEvent; + _window.PointerMoved -= Parent_PointerMovedEvent; + _window.PointerPressed -= Parent_PointerPressEvent; + _window.PointerReleased -= Parent_PointerReleaseEvent; _window.PointerWheelChanged -= Parent_ScrollEvent; _widget = null; diff --git a/Ryujinx.Ava/Ui/Applet/AvaloniaDynamicTextInputHandler.cs b/Ryujinx.Ava/Ui/Applet/AvaloniaDynamicTextInputHandler.cs index 02a99c1d..ee0d435b 100644 --- a/Ryujinx.Ava/Ui/Applet/AvaloniaDynamicTextInputHandler.cs +++ b/Ryujinx.Ava/Ui/Applet/AvaloniaDynamicTextInputHandler.cs @@ -68,7 +68,7 @@ namespace Ryujinx.Ava.Ui.Applet private void AvaloniaDynamicTextInputHandler_KeyRelease(object sender, Avalonia.Input.KeyEventArgs e) { - var key = (HidKey)AvaloniaMappingHelper.ToInputKey(e.Key); + var key = (HidKey)AvaloniaKeyboardMappingHelper.ToInputKey(e.Key); if (!(KeyReleasedEvent?.Invoke(key)).GetValueOrDefault(true)) { @@ -88,7 +88,7 @@ namespace Ryujinx.Ava.Ui.Applet private void AvaloniaDynamicTextInputHandler_KeyPressed(object sender, KeyEventArgs e) { - var key = (HidKey)AvaloniaMappingHelper.ToInputKey(e.Key); + var key = (HidKey)AvaloniaKeyboardMappingHelper.ToInputKey(e.Key); if (!(KeyPressedEvent?.Invoke(key)).GetValueOrDefault(true)) { diff --git a/Ryujinx.Ava/Ui/ViewModels/MainWindowViewModel.cs b/Ryujinx.Ava/Ui/ViewModels/MainWindowViewModel.cs index f81afd2e..06513e37 100644 --- a/Ryujinx.Ava/Ui/ViewModels/MainWindowViewModel.cs +++ b/Ryujinx.Ava/Ui/ViewModels/MainWindowViewModel.cs @@ -883,17 +883,17 @@ namespace Ryujinx.Ava.Ui.ViewModels public void LoadConfigurableHotKeys() { - if (AvaloniaMappingHelper.TryGetAvaKey((Ryujinx.Input.Key)ConfigurationState.Instance.Hid.Hotkeys.Value.ShowUi, out var showUiKey)) + if (AvaloniaKeyboardMappingHelper.TryGetAvaKey((Ryujinx.Input.Key)ConfigurationState.Instance.Hid.Hotkeys.Value.ShowUi, out var showUiKey)) { ShowUiKey = new KeyGesture(showUiKey, KeyModifiers.None); } - if (AvaloniaMappingHelper.TryGetAvaKey((Ryujinx.Input.Key)ConfigurationState.Instance.Hid.Hotkeys.Value.Screenshot, out var screenshotKey)) + if (AvaloniaKeyboardMappingHelper.TryGetAvaKey((Ryujinx.Input.Key)ConfigurationState.Instance.Hid.Hotkeys.Value.Screenshot, out var screenshotKey)) { ScreenshotKey = new KeyGesture(screenshotKey, KeyModifiers.None); } - if (AvaloniaMappingHelper.TryGetAvaKey((Ryujinx.Input.Key)ConfigurationState.Instance.Hid.Hotkeys.Value.Pause, out var pauseKey)) + if (AvaloniaKeyboardMappingHelper.TryGetAvaKey((Ryujinx.Input.Key)ConfigurationState.Instance.Hid.Hotkeys.Value.Pause, out var pauseKey)) { PauseKey = new KeyGesture(pauseKey, KeyModifiers.None); } -- cgit v1.2.3