aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.Ava/Input
diff options
context:
space:
mode:
authorMary Guillemard <mary@mary.zone>2024-03-02 12:51:05 +0100
committerGitHub <noreply@github.com>2024-03-02 12:51:05 +0100
commitec6cb0abb4b7669895b6e96fd7581c93b5abd691 (patch)
tree128c862ff5faea0b219467656d4023bee7faefb5 /src/Ryujinx.Ava/Input
parent53b5985da6b9d7b281d9fc25b93bfd1d1918a107 (diff)
infra: Make Avalonia the default UI (#6375)
* misc: Move Ryujinx project to Ryujinx.Gtk3 This breaks release CI for now but that's fine. Signed-off-by: Mary Guillemard <mary@mary.zone> * misc: Move Ryujinx.Ava project to Ryujinx This breaks CI for now, but it's fine. Signed-off-by: Mary Guillemard <mary@mary.zone> * infra: Make Avalonia the default UI Should fix CI after the previous changes. GTK3 isn't build by the release job anymore, only by PR CI. This also ensure that the test-ava update package is still generated to allow update from the old testing channel. Signed-off-by: Mary Guillemard <mary@mary.zone> * Fix missing copy in create_app_bundle.sh Signed-off-by: Mary Guillemard <mary@mary.zone> * Fix syntax error Signed-off-by: Mary Guillemard <mary@mary.zone> --------- Signed-off-by: Mary Guillemard <mary@mary.zone>
Diffstat (limited to 'src/Ryujinx.Ava/Input')
-rw-r--r--src/Ryujinx.Ava/Input/AvaloniaKeyboard.cs203
-rw-r--r--src/Ryujinx.Ava/Input/AvaloniaKeyboardDriver.cs107
-rw-r--r--src/Ryujinx.Ava/Input/AvaloniaKeyboardMappingHelper.cs185
-rw-r--r--src/Ryujinx.Ava/Input/AvaloniaMouse.cs87
-rw-r--r--src/Ryujinx.Ava/Input/AvaloniaMouseDriver.cs159
5 files changed, 0 insertions, 741 deletions
diff --git a/src/Ryujinx.Ava/Input/AvaloniaKeyboard.cs b/src/Ryujinx.Ava/Input/AvaloniaKeyboard.cs
deleted file mode 100644
index fbaaaaba..00000000
--- a/src/Ryujinx.Ava/Input/AvaloniaKeyboard.cs
+++ /dev/null
@@ -1,203 +0,0 @@
-using Ryujinx.Common.Configuration.Hid;
-using Ryujinx.Common.Configuration.Hid.Keyboard;
-using Ryujinx.Input;
-using System;
-using System.Collections.Generic;
-using System.Numerics;
-using ConfigKey = Ryujinx.Common.Configuration.Hid.Key;
-using Key = Ryujinx.Input.Key;
-
-namespace Ryujinx.Ava.Input
-{
- internal class AvaloniaKeyboard : IKeyboard
- {
- private readonly List<ButtonMappingEntry> _buttonsUserMapping;
- private readonly AvaloniaKeyboardDriver _driver;
- private StandardKeyboardInputConfig _configuration;
-
- private readonly object _userMappingLock = new();
-
- public string Id { get; }
- public string Name { get; }
-
- public bool IsConnected => true;
- public GamepadFeaturesFlag Features => GamepadFeaturesFlag.None;
-
- private class ButtonMappingEntry
- {
- public readonly Key From;
- public readonly GamepadButtonInputId To;
-
- public ButtonMappingEntry(GamepadButtonInputId to, Key from)
- {
- To = to;
- From = from;
- }
- }
-
- public AvaloniaKeyboard(AvaloniaKeyboardDriver driver, string id, string name)
- {
- _buttonsUserMapping = new List<ButtonMappingEntry>();
-
- _driver = driver;
- Id = id;
- Name = name;
- }
-
- public KeyboardStateSnapshot GetKeyboardStateSnapshot()
- {
- return IKeyboard.GetStateSnapshot(this);
- }
-
- public GamepadStateSnapshot GetMappedStateSnapshot()
- {
- KeyboardStateSnapshot rawState = GetKeyboardStateSnapshot();
- GamepadStateSnapshot result = default;
-
- lock (_userMappingLock)
- {
- if (_configuration == null)
- {
- return result;
- }
-
- foreach (ButtonMappingEntry entry in _buttonsUserMapping)
- {
- if (entry.From == Key.Unknown || entry.From == Key.Unbound || entry.To == GamepadButtonInputId.Unbound)
- {
- continue;
- }
-
- // 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 rightStickX, short rightStickY) = GetStickValues(ref rawState, _configuration.RightJoyconStick);
-
- result.SetStick(StickInputId.Left, ConvertRawStickValue(leftStickX), ConvertRawStickValue(leftStickY));
- result.SetStick(StickInputId.Right, ConvertRawStickValue(rightStickX), ConvertRawStickValue(rightStickY));
- }
-
- return result;
- }
-
- public GamepadStateSnapshot GetStateSnapshot()
- {
- throw new NotSupportedException();
- }
-
- public (float, float) GetStick(StickInputId inputId)
- {
- throw new NotSupportedException();
- }
-
- public bool IsPressed(GamepadButtonInputId inputId)
- {
- throw new NotSupportedException();
- }
-
- public bool IsPressed(Key key)
- {
- try
- {
- return _driver.IsPressed(key);
- }
- catch
- {
- return false;
- }
- }
-
- public void SetConfiguration(InputConfig configuration)
- {
- lock (_userMappingLock)
- {
- _configuration = (StandardKeyboardInputConfig)configuration;
-
- _buttonsUserMapping.Clear();
-
-#pragma warning disable IDE0055 // Disable formatting
- // 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));
-
- // 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));
-#pragma warning restore IDE0055
- }
- }
-
- public void SetTriggerThreshold(float triggerThreshold) { }
-
- public void Rumble(float lowFrequency, float highFrequency, uint durationMs) { }
-
- public Vector3 GetMotionData(MotionInputId inputId) => Vector3.Zero;
-
- private static float ConvertRawStickValue(short value)
- {
- const float ConvertRate = 1.0f / (short.MaxValue + 0.5f);
-
- return value * ConvertRate;
- }
-
- private static (short, short) GetStickValues(ref KeyboardStateSnapshot snapshot, JoyconConfigKeyboardStick<ConfigKey> stickConfig)
- {
- short stickX = 0;
- short stickY = 0;
-
- if (snapshot.IsPressed((Key)stickConfig.StickUp))
- {
- stickY += 1;
- }
-
- if (snapshot.IsPressed((Key)stickConfig.StickDown))
- {
- stickY -= 1;
- }
-
- if (snapshot.IsPressed((Key)stickConfig.StickRight))
- {
- stickX += 1;
- }
-
- if (snapshot.IsPressed((Key)stickConfig.StickLeft))
- {
- stickX -= 1;
- }
-
- Vector2 stick = new(stickX, stickY);
-
- stick = Vector2.Normalize(stick);
-
- return ((short)(stick.X * short.MaxValue), (short)(stick.Y * short.MaxValue));
- }
-
- public void Clear()
- {
- _driver?.ResetKeys();
- }
-
- public void Dispose() { }
- }
-}
diff --git a/src/Ryujinx.Ava/Input/AvaloniaKeyboardDriver.cs b/src/Ryujinx.Ava/Input/AvaloniaKeyboardDriver.cs
deleted file mode 100644
index e9e71b99..00000000
--- a/src/Ryujinx.Ava/Input/AvaloniaKeyboardDriver.cs
+++ /dev/null
@@ -1,107 +0,0 @@
-using Avalonia.Controls;
-using Avalonia.Input;
-using Ryujinx.Ava.Common.Locale;
-using Ryujinx.Input;
-using System;
-using System.Collections.Generic;
-using AvaKey = Avalonia.Input.Key;
-using Key = Ryujinx.Input.Key;
-
-namespace Ryujinx.Ava.Input
-{
- internal class AvaloniaKeyboardDriver : IGamepadDriver
- {
- private static readonly string[] _keyboardIdentifers = new string[1] { "0" };
- private readonly Control _control;
- private readonly HashSet<AvaKey> _pressedKeys;
-
- public event EventHandler<KeyEventArgs> KeyPressed;
- public event EventHandler<KeyEventArgs> KeyRelease;
- public event EventHandler<string> TextInput;
-
- public string DriverName => "AvaloniaKeyboardDriver";
- public ReadOnlySpan<string> GamepadsIds => _keyboardIdentifers;
-
- public AvaloniaKeyboardDriver(Control control)
- {
- _control = control;
- _pressedKeys = new HashSet<AvaKey>();
-
- _control.KeyDown += OnKeyPress;
- _control.KeyUp += OnKeyRelease;
- _control.TextInput += Control_TextInput;
- }
-
- private void Control_TextInput(object sender, TextInputEventArgs e)
- {
- TextInput?.Invoke(this, e.Text);
- }
-
- public event Action<string> OnGamepadConnected
- {
- add { }
- remove { }
- }
-
- public event Action<string> OnGamepadDisconnected
- {
- add { }
- remove { }
- }
-
- public IGamepad GetGamepad(string id)
- {
- if (!_keyboardIdentifers[0].Equals(id))
- {
- return null;
- }
-
- return new AvaloniaKeyboard(this, _keyboardIdentifers[0], LocaleManager.Instance[LocaleKeys.AllKeyboards]);
- }
-
- protected virtual void Dispose(bool disposing)
- {
- if (disposing)
- {
- _control.KeyUp -= OnKeyPress;
- _control.KeyDown -= OnKeyRelease;
- }
- }
-
- protected void OnKeyPress(object sender, KeyEventArgs args)
- {
- _pressedKeys.Add(args.Key);
-
- KeyPressed?.Invoke(this, args);
- }
-
- protected void OnKeyRelease(object sender, KeyEventArgs args)
- {
- _pressedKeys.Remove(args.Key);
-
- KeyRelease?.Invoke(this, args);
- }
-
- internal bool IsPressed(Key key)
- {
- if (key == Key.Unbound || key == Key.Unknown)
- {
- return false;
- }
-
- AvaloniaKeyboardMappingHelper.TryGetAvaKey(key, out var nativeKey);
-
- return _pressedKeys.Contains(nativeKey);
- }
-
- public void ResetKeys()
- {
- _pressedKeys.Clear();
- }
-
- public void Dispose()
- {
- Dispose(true);
- }
- }
-}
diff --git a/src/Ryujinx.Ava/Input/AvaloniaKeyboardMappingHelper.cs b/src/Ryujinx.Ava/Input/AvaloniaKeyboardMappingHelper.cs
deleted file mode 100644
index 97ebd721..00000000
--- a/src/Ryujinx.Ava/Input/AvaloniaKeyboardMappingHelper.cs
+++ /dev/null
@@ -1,185 +0,0 @@
-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 = {
- // 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<AvaKey, Key> _avaKeyMapping;
-
- static AvaloniaKeyboardMappingHelper()
- {
- var inputKeys = Enum.GetValues<Key>();
-
- // NOTE: Avalonia.Input.Key is not contiguous and quite large, so use a dictionary instead of an array.
- _avaKeyMapping = new Dictionary<AvaKey, Key>();
-
- foreach (var key in inputKeys)
- {
- if (TryGetAvaKey(key, out var index))
- {
- _avaKeyMapping[index] = 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);
- }
- }
-}
diff --git a/src/Ryujinx.Ava/Input/AvaloniaMouse.cs b/src/Ryujinx.Ava/Input/AvaloniaMouse.cs
deleted file mode 100644
index 1aa2d586..00000000
--- a/src/Ryujinx.Ava/Input/AvaloniaMouse.cs
+++ /dev/null
@@ -1,87 +0,0 @@
-using Ryujinx.Common.Configuration.Hid;
-using Ryujinx.Input;
-using System;
-using System.Drawing;
-using System.Numerics;
-
-namespace Ryujinx.Ava.Input
-{
- internal class AvaloniaMouse : IMouse
- {
- private AvaloniaMouseDriver _driver;
-
- public string Id => "0";
- public string Name => "AvaloniaMouse";
-
- public bool IsConnected => true;
- public GamepadFeaturesFlag Features => throw new NotImplementedException();
- public bool[] Buttons => _driver.PressedButtons;
-
- public AvaloniaMouse(AvaloniaMouseDriver driver)
- {
- _driver = driver;
- }
-
- public Size ClientSize => _driver.GetClientSize();
-
- public Vector2 GetPosition()
- {
- return _driver.CurrentPosition;
- }
-
- public Vector2 GetScroll()
- {
- return _driver.Scroll;
- }
-
- public GamepadStateSnapshot GetMappedStateSnapshot()
- {
- throw new NotImplementedException();
- }
-
- public Vector3 GetMotionData(MotionInputId inputId)
- {
- throw new NotImplementedException();
- }
-
- public GamepadStateSnapshot GetStateSnapshot()
- {
- throw new NotImplementedException();
- }
-
- public (float, float) GetStick(StickInputId inputId)
- {
- throw new NotImplementedException();
- }
-
- public bool IsButtonPressed(MouseButton button)
- {
- return _driver.IsButtonPressed(button);
- }
-
- public bool IsPressed(GamepadButtonInputId inputId)
- {
- throw new NotImplementedException();
- }
-
- public void Rumble(float lowFrequency, float highFrequency, uint durationMs)
- {
- throw new NotImplementedException();
- }
-
- public void SetConfiguration(InputConfig configuration)
- {
- throw new NotImplementedException();
- }
-
- public void SetTriggerThreshold(float triggerThreshold)
- {
- throw new NotImplementedException();
- }
-
- public void Dispose()
- {
- _driver = null;
- }
- }
-}
diff --git a/src/Ryujinx.Ava/Input/AvaloniaMouseDriver.cs b/src/Ryujinx.Ava/Input/AvaloniaMouseDriver.cs
deleted file mode 100644
index e71bbf64..00000000
--- a/src/Ryujinx.Ava/Input/AvaloniaMouseDriver.cs
+++ /dev/null
@@ -1,159 +0,0 @@
-using Avalonia;
-using Avalonia.Controls;
-using Avalonia.Input;
-using Ryujinx.Input;
-using System;
-using System.Numerics;
-using MouseButton = Ryujinx.Input.MouseButton;
-using Size = System.Drawing.Size;
-
-namespace Ryujinx.Ava.Input
-{
- internal class AvaloniaMouseDriver : IGamepadDriver
- {
- private Control _widget;
- private bool _isDisposed;
- private Size _size;
- private readonly TopLevel _window;
-
- public bool[] PressedButtons { get; }
- public Vector2 CurrentPosition { get; private set; }
- public Vector2 Scroll { get; private set; }
-
- public string DriverName => "AvaloniaMouseDriver";
- public ReadOnlySpan<string> GamepadsIds => new[] { "0" };
-
- public AvaloniaMouseDriver(TopLevel window, Control parent)
- {
- _widget = parent;
- _window = window;
-
- _widget.PointerMoved += Parent_PointerMovedEvent;
- _widget.PointerPressed += Parent_PointerPressedEvent;
- _widget.PointerReleased += Parent_PointerReleasedEvent;
- _widget.PointerWheelChanged += Parent_PointerWheelChanged;
-
- _window.PointerMoved += Parent_PointerMovedEvent;
- _window.PointerPressed += Parent_PointerPressedEvent;
- _window.PointerReleased += Parent_PointerReleasedEvent;
- _window.PointerWheelChanged += Parent_PointerWheelChanged;
-
- PressedButtons = new bool[(int)MouseButton.Count];
-
- _size = new Size((int)parent.Bounds.Width, (int)parent.Bounds.Height);
-
- parent.GetObservable(Visual.BoundsProperty).Subscribe(Resized);
- }
-
- public event Action<string> OnGamepadConnected
- {
- add { }
- remove { }
- }
-
- public event Action<string> OnGamepadDisconnected
- {
- add { }
- remove { }
- }
-
- private void Resized(Rect rect)
- {
- _size = new Size((int)rect.Width, (int)rect.Height);
- }
-
- private void Parent_PointerWheelChanged(object o, PointerWheelEventArgs args)
- {
- Scroll = new Vector2((float)args.Delta.X, (float)args.Delta.Y);
- }
-
- private void Parent_PointerReleasedEvent(object o, PointerReleasedEventArgs args)
- {
- uint button = (uint)args.InitialPressMouseButton - 1;
-
- if ((uint)PressedButtons.Length > button)
- {
- PressedButtons[button] = false;
- }
- }
- private void Parent_PointerPressedEvent(object o, PointerPressedEventArgs args)
- {
- uint button = (uint)args.GetCurrentPoint(_widget).Properties.PointerUpdateKind;
-
- if ((uint)PressedButtons.Length > button)
- {
- PressedButtons[button] = true;
- }
- }
-
- private void Parent_PointerMovedEvent(object o, PointerEventArgs args)
- {
- Point position = args.GetPosition(_widget);
-
- CurrentPosition = new Vector2((float)position.X, (float)position.Y);
- }
-
- public void SetMousePressed(MouseButton button)
- {
- if ((uint)PressedButtons.Length > (uint)button)
- {
- PressedButtons[(uint)button] = true;
- }
- }
-
- public void SetMouseReleased(MouseButton button)
- {
- if ((uint)PressedButtons.Length > (uint)button)
- {
- PressedButtons[(uint)button] = false;
- }
- }
-
- public void SetPosition(double x, double y)
- {
- CurrentPosition = new Vector2((float)x, (float)y);
- }
-
- public bool IsButtonPressed(MouseButton button)
- {
- if ((uint)PressedButtons.Length > (uint)button)
- {
- return PressedButtons[(uint)button];
- }
-
- return false;
- }
-
- public Size GetClientSize()
- {
- return _size;
- }
-
- public IGamepad GetGamepad(string id)
- {
- return new AvaloniaMouse(this);
- }
-
- public void Dispose()
- {
- if (_isDisposed)
- {
- return;
- }
-
- _isDisposed = true;
-
- _widget.PointerMoved -= Parent_PointerMovedEvent;
- _widget.PointerPressed -= Parent_PointerPressedEvent;
- _widget.PointerReleased -= Parent_PointerReleasedEvent;
- _widget.PointerWheelChanged -= Parent_PointerWheelChanged;
-
- _window.PointerMoved -= Parent_PointerMovedEvent;
- _window.PointerPressed -= Parent_PointerPressedEvent;
- _window.PointerReleased -= Parent_PointerReleasedEvent;
- _window.PointerWheelChanged -= Parent_PointerWheelChanged;
-
- _widget = null;
- }
- }
-}