MouseDevice.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. namespace Ryujinx.HLE.HOS.Services.Hid
  2. {
  3. public class MouseDevice : BaseDevice
  4. {
  5. public MouseDevice(Switch device, bool active) : base(device, active) { }
  6. public void Update(int mouseX, int mouseY, int buttons = 0, int scrollX = 0, int scrollY = 0)
  7. {
  8. ref ShMemMouse mouse = ref _device.Hid.SharedMemory.Mouse;
  9. int currentIndex = UpdateEntriesHeader(ref mouse.Header, out int previousIndex);
  10. if (!Active)
  11. {
  12. return;
  13. }
  14. ref MouseState currentEntry = ref mouse.Entries[currentIndex];
  15. MouseState previousEntry = mouse.Entries[previousIndex];
  16. currentEntry.SampleTimestamp = previousEntry.SampleTimestamp + 1;
  17. currentEntry.SampleTimestamp2 = previousEntry.SampleTimestamp2 + 1;
  18. currentEntry.Buttons = (ulong)buttons;
  19. currentEntry.Position = new MousePosition
  20. {
  21. X = mouseX,
  22. Y = mouseY,
  23. VelocityX = mouseX - previousEntry.Position.X,
  24. VelocityY = mouseY - previousEntry.Position.Y,
  25. ScrollVelocityX = scrollX,
  26. ScrollVelocityY = scrollY
  27. };
  28. }
  29. }
  30. }