diff options
| author | emmauss <emmausssss@gmail.com> | 2021-06-14 06:42:55 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-06-14 08:42:55 +0200 |
| commit | bfcc6a8ad63a0eb0f06968145a310c484a96e8ca (patch) | |
| tree | a3acfa8364d43cd960f5cb559c109f6be863ba2c /Ryujinx.Input/HLE | |
| parent | b898bc84ced7fe5b77e2018ce2ccb7389933b7cf (diff) | |
Add TouchScreen Manager (#2333)
Diffstat (limited to 'Ryujinx.Input/HLE')
| -rw-r--r-- | Ryujinx.Input/HLE/InputManager.cs | 19 | ||||
| -rw-r--r-- | Ryujinx.Input/HLE/TouchScreenManager.cs | 57 |
2 files changed, 76 insertions, 0 deletions
diff --git a/Ryujinx.Input/HLE/InputManager.cs b/Ryujinx.Input/HLE/InputManager.cs index 277e8ec2..699e521d 100644 --- a/Ryujinx.Input/HLE/InputManager.cs +++ b/Ryujinx.Input/HLE/InputManager.cs @@ -6,6 +6,7 @@ namespace Ryujinx.Input.HLE { public IGamepadDriver KeyboardDriver { get; private set; } public IGamepadDriver GamepadDriver { get; private set; } + public IGamepadDriver MouseDriver { get; private set; } public InputManager(IGamepadDriver keyboardDriver, IGamepadDriver gamepadDriver) { @@ -13,10 +14,27 @@ namespace Ryujinx.Input.HLE GamepadDriver = gamepadDriver; } + public void SetMouseDriver(IGamepadDriver mouseDriver) + { + MouseDriver?.Dispose(); + + MouseDriver = mouseDriver; + } + public NpadManager CreateNpadManager() { return new NpadManager(KeyboardDriver, GamepadDriver); } + + public TouchScreenManager CreateTouchScreenManager() + { + if (MouseDriver == null) + { + throw new InvalidOperationException("Mouse Driver has not been initialized."); + } + + return new TouchScreenManager(MouseDriver.GetGamepad("0") as IMouse); + } protected virtual void Dispose(bool disposing) { @@ -24,6 +42,7 @@ namespace Ryujinx.Input.HLE { KeyboardDriver?.Dispose(); GamepadDriver?.Dispose(); + MouseDriver?.Dispose(); } } diff --git a/Ryujinx.Input/HLE/TouchScreenManager.cs b/Ryujinx.Input/HLE/TouchScreenManager.cs new file mode 100644 index 00000000..ffa8eeac --- /dev/null +++ b/Ryujinx.Input/HLE/TouchScreenManager.cs @@ -0,0 +1,57 @@ +using Ryujinx.HLE; +using Ryujinx.HLE.HOS.Services.Hid; +using System; + +namespace Ryujinx.Input.HLE +{ + public class TouchScreenManager : IDisposable + { + private readonly IMouse _mouse; + private Switch _device; + + public TouchScreenManager(IMouse mouse) + { + _mouse = mouse; + } + + public void Initialize(Switch device) + { + _device = device; + } + + public bool Update(bool isFocused, float aspectRatio = 0) + { + if (!isFocused) + { + _device.Hid.Touchscreen.Update(); + + return false; + } + + if (aspectRatio > 0) + { + var snapshot = IMouse.GetMouseStateSnapshot(_mouse); + var touchPosition = IMouse.GetTouchPosition(snapshot.Position, _mouse.ClientSize, aspectRatio); + + TouchPoint currentPoint = new TouchPoint + { + 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); + + return true; + } + + return false; + } + + public void Dispose() { } + } +}
\ No newline at end of file |
