diff options
| author | TSR Berry <20988865+TSRBerry@users.noreply.github.com> | 2023-04-08 01:22:00 +0200 |
|---|---|---|
| committer | Mary <thog@protonmail.com> | 2023-04-27 23:51:14 +0200 |
| commit | cee712105850ac3385cd0091a923438167433f9f (patch) | |
| tree | 4a5274b21d8b7f938c0d0ce18736d3f2993b11b1 /src/Ryujinx.Input/HLE/TouchScreenManager.cs | |
| parent | cd124bda587ef09668a971fa1cac1c3f0cfc9f21 (diff) | |
Move solution and projects to src
Diffstat (limited to 'src/Ryujinx.Input/HLE/TouchScreenManager.cs')
| -rw-r--r-- | src/Ryujinx.Input/HLE/TouchScreenManager.cs | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/src/Ryujinx.Input/HLE/TouchScreenManager.cs b/src/Ryujinx.Input/HLE/TouchScreenManager.cs new file mode 100644 index 00000000..e4b0f8fc --- /dev/null +++ b/src/Ryujinx.Input/HLE/TouchScreenManager.cs @@ -0,0 +1,99 @@ +using Ryujinx.HLE; +using Ryujinx.HLE.HOS.Services.Hid; +using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.TouchScreen; +using System; + +namespace Ryujinx.Input.HLE +{ + public class TouchScreenManager : IDisposable + { + private readonly IMouse _mouse; + private Switch _device; + private bool _wasClicking; + + public TouchScreenManager(IMouse mouse) + { + _mouse = mouse; + } + + public void Initialize(Switch device) + { + _device = device; + } + + public bool Update(bool isFocused, bool isClicking = false, float aspectRatio = 0) + { + if (!isFocused || (!_wasClicking && !isClicking)) + { + // In case we lost focus, send the end touch. + if (_wasClicking && !isClicking) + { + MouseStateSnapshot snapshot = IMouse.GetMouseStateSnapshot(_mouse); + var touchPosition = IMouse.GetScreenPosition(snapshot.Position, _mouse.ClientSize, aspectRatio); + + TouchPoint currentPoint = new TouchPoint + { + Attribute = TouchAttribute.End, + + X = (uint)touchPosition.X, + Y = (uint)touchPosition.Y, + + // Placeholder values till more data is acquired + DiameterX = 10, + DiameterY = 10, + Angle = 90 + }; + + _device.Hid.Touchscreen.Update(currentPoint); + + } + + _wasClicking = false; + + _device.Hid.Touchscreen.Update(); + + return false; + } + + if (aspectRatio > 0) + { + MouseStateSnapshot snapshot = IMouse.GetMouseStateSnapshot(_mouse); + var touchPosition = IMouse.GetScreenPosition(snapshot.Position, _mouse.ClientSize, aspectRatio); + + TouchAttribute attribute = TouchAttribute.None; + + if (!_wasClicking && isClicking) + { + attribute = TouchAttribute.Start; + } + else if (_wasClicking && !isClicking) + { + attribute = TouchAttribute.End; + } + + TouchPoint currentPoint = new TouchPoint + { + Attribute = attribute, + + X = (uint)touchPosition.X, + Y = (uint)touchPosition.Y, + + // Placeholder values till more data is acquired + DiameterX = 10, + DiameterY = 10, + Angle = 90 + }; + + _device.Hid.Touchscreen.Update(currentPoint); + + _wasClicking = isClicking; + + return true; + } + + return false; + } + + public void Dispose() { } + } +}
\ No newline at end of file |
