2021-05-02 21:01:30 +01:00
|
|
|
using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Common;
|
|
|
|
using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Mouse;
|
|
|
|
|
2020-04-03 01:10:02 +01:00
|
|
|
namespace Ryujinx.HLE.HOS.Services.Hid
|
|
|
|
{
|
|
|
|
public class MouseDevice : BaseDevice
|
|
|
|
{
|
|
|
|
public MouseDevice(Switch device, bool active) : base(device, active) { }
|
|
|
|
|
2021-06-24 01:09:08 +01:00
|
|
|
public void Update(int mouseX, int mouseY, uint buttons = 0, int scrollX = 0, int scrollY = 0, bool connected = false)
|
2020-04-03 01:10:02 +01:00
|
|
|
{
|
2021-05-02 21:01:30 +01:00
|
|
|
ref RingLifo<MouseState> lifo = ref _device.Hid.SharedMemory.Mouse;
|
2020-04-03 01:10:02 +01:00
|
|
|
|
2021-05-02 21:01:30 +01:00
|
|
|
ref MouseState previousEntry = ref lifo.GetCurrentEntryRef();
|
|
|
|
|
|
|
|
MouseState newState = new MouseState()
|
|
|
|
{
|
|
|
|
SamplingNumber = previousEntry.SamplingNumber + 1,
|
|
|
|
};
|
2020-04-03 01:10:02 +01:00
|
|
|
|
2021-05-02 21:01:30 +01:00
|
|
|
if (Active)
|
2020-04-03 01:10:02 +01:00
|
|
|
{
|
2021-05-02 21:01:30 +01:00
|
|
|
newState.Buttons = (MouseButton)buttons;
|
|
|
|
newState.X = mouseX;
|
|
|
|
newState.Y = mouseY;
|
|
|
|
newState.DeltaX = mouseX - previousEntry.DeltaX;
|
|
|
|
newState.DeltaY = mouseY - previousEntry.DeltaY;
|
|
|
|
newState.WheelDeltaX = scrollX;
|
|
|
|
newState.WheelDeltaY = scrollY;
|
2021-06-24 01:09:08 +01:00
|
|
|
newState.Attributes = connected ? MouseAttribute.IsConnected : MouseAttribute.None;
|
2020-04-03 01:10:02 +01:00
|
|
|
}
|
|
|
|
|
2021-05-02 21:01:30 +01:00
|
|
|
lifo.Write(ref newState);
|
2020-04-03 01:10:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|