aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/MouseDevice.cs
blob: 2e62d206b5aa91e485cee32f66bc77216815b95a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Common;
using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Mouse;

namespace Ryujinx.HLE.HOS.Services.Hid
{
    public class MouseDevice : BaseDevice
    {
        public MouseDevice(Switch device, bool active) : base(device, active) { }

        public void Update(int mouseX, int mouseY, uint buttons = 0, int scrollX = 0, int scrollY = 0, bool connected = false)
        {
            ref RingLifo<MouseState> lifo = ref _device.Hid.SharedMemory.Mouse;

            ref MouseState previousEntry = ref lifo.GetCurrentEntryRef();

            MouseState newState = new()
            {
                SamplingNumber = previousEntry.SamplingNumber + 1,
            };

            if (Active)
            {
                newState.Buttons = (MouseButton)buttons;
                newState.X = mouseX;
                newState.Y = mouseY;
                newState.DeltaX = mouseX - previousEntry.X;
                newState.DeltaY = mouseY - previousEntry.Y;
                newState.WheelDeltaX = scrollX;
                newState.WheelDeltaY = scrollY;
                newState.Attributes = connected ? MouseAttribute.IsConnected : MouseAttribute.None;
            }

            lifo.Write(ref newState);
        }
    }
}