Fix Avalonia Native MouseWheel-Support (ryubing/ryujinx!116)

See merge request ryubing/ryujinx!116
This commit is contained in:
MaxLastBreath
2025-08-19 18:46:20 -05:00
committed by GreemDev
parent 37e81481c4
commit 3df6b7c0f5

View File

@@ -1,6 +1,7 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Threading;
using Ryujinx.Input;
using System;
using System.Collections.Generic;
@@ -16,6 +17,8 @@ namespace Ryujinx.Ava.Input
private bool _isDisposed;
private Size _size;
private readonly TopLevel _window;
private DispatcherTimer _scrollStopTimer;
private const int _dispatchTimerMS = 100;
public bool[] PressedButtons { get; }
public Vector2 CurrentPosition { get; private set; }
@@ -39,6 +42,11 @@ namespace Ryujinx.Ava.Input
_window.PointerReleased += Parent_PointerReleasedEvent;
_window.PointerWheelChanged += Parent_PointerWheelChanged;
_scrollStopTimer = new DispatcherTimer
{
Interval = TimeSpan.FromMilliseconds(_dispatchTimerMS)
};
PressedButtons = new bool[(int)MouseButton.Count];
_size = new Size((int)parent.Bounds.Width, (int)parent.Bounds.Height);
@@ -62,10 +70,26 @@ namespace Ryujinx.Ava.Input
{
_size = new Size((int)rect.Width, (int)rect.Height);
}
private void HandleScrollStopped()
{
Scroll = new Vector2(0, 0);
}
private void Parent_PointerWheelChanged(object o, PointerWheelEventArgs args)
{
Scroll = new Vector2((float)args.Delta.X, (float)args.Delta.Y);
_scrollStopTimer?.Stop();
_scrollStopTimer.Tick += (_, __) =>
{
_scrollStopTimer.Stop();
HandleScrollStopped();
};
_scrollStopTimer.Start();
}
private void Parent_PointerReleasedEvent(object o, PointerReleasedEventArgs args)