TouchDevice.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System;
  2. namespace Ryujinx.HLE.HOS.Services.Hid
  3. {
  4. public class TouchDevice : BaseDevice
  5. {
  6. public TouchDevice(Switch device, bool active) : base(device, active) { }
  7. public void Update(params TouchPoint[] points)
  8. {
  9. ref ShMemTouchScreen touchscreen = ref _device.Hid.SharedMemory.TouchScreen;
  10. int currentIndex = UpdateEntriesHeader(ref touchscreen.Header, out int previousIndex);
  11. if (!Active)
  12. {
  13. return;
  14. }
  15. ref TouchScreenState currentEntry = ref touchscreen.Entries[currentIndex];
  16. TouchScreenState previousEntry = touchscreen.Entries[previousIndex];
  17. currentEntry.SampleTimestamp = previousEntry.SampleTimestamp + 1;
  18. currentEntry.SampleTimestamp2 = previousEntry.SampleTimestamp2 + 1;
  19. currentEntry.NumTouches = (ulong)points.Length;
  20. int pointsLength = Math.Min(points.Length, currentEntry.Touches.Length);
  21. for (int i = 0; i < pointsLength; ++i)
  22. {
  23. TouchPoint pi = points[i];
  24. currentEntry.Touches[i] = new TouchScreenStateData
  25. {
  26. SampleTimestamp = currentEntry.SampleTimestamp,
  27. X = pi.X,
  28. Y = pi.Y,
  29. TouchIndex = (uint)i,
  30. DiameterX = pi.DiameterX,
  31. DiameterY = pi.DiameterY,
  32. Angle = pi.Angle
  33. };
  34. }
  35. }
  36. }
  37. }