TouchScreenManager.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using Ryujinx.HLE;
  2. using Ryujinx.HLE.HOS.Services.Hid;
  3. using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.TouchScreen;
  4. using System;
  5. namespace Ryujinx.Input.HLE
  6. {
  7. public class TouchScreenManager : IDisposable
  8. {
  9. private readonly IMouse _mouse;
  10. private Switch _device;
  11. private bool _wasClicking;
  12. public TouchScreenManager(IMouse mouse)
  13. {
  14. _mouse = mouse;
  15. }
  16. public void Initialize(Switch device)
  17. {
  18. _device = device;
  19. }
  20. public bool Update(bool isFocused, bool isClicking = false, float aspectRatio = 0)
  21. {
  22. if (!isFocused || (!_wasClicking && !isClicking))
  23. {
  24. // In case we lost focus, send the end touch.
  25. if (_wasClicking && !isClicking)
  26. {
  27. MouseStateSnapshot snapshot = IMouse.GetMouseStateSnapshot(_mouse);
  28. var touchPosition = IMouse.GetScreenPosition(snapshot.Position, _mouse.ClientSize, aspectRatio);
  29. TouchPoint currentPoint = new TouchPoint
  30. {
  31. Attribute = TouchAttribute.End,
  32. X = (uint)touchPosition.X,
  33. Y = (uint)touchPosition.Y,
  34. // Placeholder values till more data is acquired
  35. DiameterX = 10,
  36. DiameterY = 10,
  37. Angle = 90
  38. };
  39. _device.Hid.Touchscreen.Update(currentPoint);
  40. }
  41. _wasClicking = false;
  42. _device.Hid.Touchscreen.Update();
  43. return false;
  44. }
  45. if (aspectRatio > 0)
  46. {
  47. MouseStateSnapshot snapshot = IMouse.GetMouseStateSnapshot(_mouse);
  48. var touchPosition = IMouse.GetScreenPosition(snapshot.Position, _mouse.ClientSize, aspectRatio);
  49. TouchAttribute attribute = TouchAttribute.None;
  50. if (!_wasClicking && isClicking)
  51. {
  52. attribute = TouchAttribute.Start;
  53. }
  54. else if (_wasClicking && !isClicking)
  55. {
  56. attribute = TouchAttribute.End;
  57. }
  58. TouchPoint currentPoint = new TouchPoint
  59. {
  60. Attribute = attribute,
  61. X = (uint)touchPosition.X,
  62. Y = (uint)touchPosition.Y,
  63. // Placeholder values till more data is acquired
  64. DiameterX = 10,
  65. DiameterY = 10,
  66. Angle = 90
  67. };
  68. _device.Hid.Touchscreen.Update(currentPoint);
  69. _wasClicking = isClicking;
  70. return true;
  71. }
  72. return false;
  73. }
  74. public void Dispose() { }
  75. }
  76. }