MouseDevice.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Common;
  2. using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Mouse;
  3. namespace Ryujinx.HLE.HOS.Services.Hid
  4. {
  5. public class MouseDevice : BaseDevice
  6. {
  7. public MouseDevice(Switch device, bool active) : base(device, active) { }
  8. public void Update(int mouseX, int mouseY, uint buttons = 0, int scrollX = 0, int scrollY = 0, bool connected = false)
  9. {
  10. ref RingLifo<MouseState> lifo = ref _device.Hid.SharedMemory.Mouse;
  11. ref MouseState previousEntry = ref lifo.GetCurrentEntryRef();
  12. MouseState newState = new MouseState()
  13. {
  14. SamplingNumber = previousEntry.SamplingNumber + 1,
  15. };
  16. if (Active)
  17. {
  18. newState.Buttons = (MouseButton)buttons;
  19. newState.X = mouseX;
  20. newState.Y = mouseY;
  21. newState.DeltaX = mouseX - previousEntry.DeltaX;
  22. newState.DeltaY = mouseY - previousEntry.DeltaY;
  23. newState.WheelDeltaX = scrollX;
  24. newState.WheelDeltaY = scrollY;
  25. newState.Attributes = connected ? MouseAttribute.IsConnected : MouseAttribute.None;
  26. }
  27. lifo.Write(ref newState);
  28. }
  29. }
  30. }