TouchDevice.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Common;
  2. using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.TouchScreen;
  3. using System;
  4. namespace Ryujinx.HLE.HOS.Services.Hid
  5. {
  6. public class TouchDevice : BaseDevice
  7. {
  8. public TouchDevice(Switch device, bool active) : base(device, active) { }
  9. public void Update(params TouchPoint[] points)
  10. {
  11. ref RingLifo<TouchScreenState> lifo = ref _device.Hid.SharedMemory.TouchScreen;
  12. ref TouchScreenState previousEntry = ref lifo.GetCurrentEntryRef();
  13. TouchScreenState newState = new TouchScreenState
  14. {
  15. SamplingNumber = previousEntry.SamplingNumber + 1
  16. };
  17. if (Active)
  18. {
  19. newState.TouchesCount = points.Length;
  20. int pointsLength = Math.Min(points.Length, newState.Touches.Length);
  21. for (int i = 0; i < pointsLength; ++i)
  22. {
  23. TouchPoint pi = points[i];
  24. newState.Touches[i] = new TouchState
  25. {
  26. DeltaTime = newState.SamplingNumber,
  27. Attribute = pi.Attribute,
  28. X = pi.X,
  29. Y = pi.Y,
  30. FingerId = (uint)i,
  31. DiameterX = pi.DiameterX,
  32. DiameterY = pi.DiameterY,
  33. RotationAngle = pi.Angle
  34. };
  35. }
  36. }
  37. lifo.Write(ref newState);
  38. }
  39. }
  40. }