2021-06-14 08:42:55 +02:00
|
|
|
using Ryujinx.HLE;
|
|
|
|
using Ryujinx.HLE.HOS.Services.Hid;
|
2021-06-23 23:44:09 +02:00
|
|
|
using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.TouchScreen;
|
2021-06-14 08:42:55 +02:00
|
|
|
using System;
|
|
|
|
|
|
|
|
namespace Ryujinx.Input.HLE
|
|
|
|
{
|
|
|
|
public class TouchScreenManager : IDisposable
|
|
|
|
{
|
|
|
|
private readonly IMouse _mouse;
|
|
|
|
private Switch _device;
|
2021-06-23 23:44:09 +02:00
|
|
|
private bool _wasClicking;
|
2021-06-14 08:42:55 +02:00
|
|
|
|
|
|
|
public TouchScreenManager(IMouse mouse)
|
|
|
|
{
|
|
|
|
_mouse = mouse;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Initialize(Switch device)
|
|
|
|
{
|
|
|
|
_device = device;
|
|
|
|
}
|
|
|
|
|
2021-06-23 23:44:09 +02:00
|
|
|
public bool Update(bool isFocused, bool isClicking = false, float aspectRatio = 0)
|
2021-06-14 08:42:55 +02:00
|
|
|
{
|
2021-06-23 23:44:09 +02:00
|
|
|
if (!isFocused || (!_wasClicking && !isClicking))
|
2021-06-14 08:42:55 +02:00
|
|
|
{
|
2021-06-23 23:44:09 +02:00
|
|
|
// In case we lost focus, send the end touch.
|
|
|
|
if (_wasClicking && !isClicking)
|
|
|
|
{
|
|
|
|
MouseStateSnapshot snapshot = IMouse.GetMouseStateSnapshot(_mouse);
|
2021-06-24 02:09:08 +02:00
|
|
|
var touchPosition = IMouse.GetScreenPosition(snapshot.Position, _mouse.ClientSize, aspectRatio);
|
2021-06-23 23:44:09 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2021-06-14 08:42:55 +02:00
|
|
|
_device.Hid.Touchscreen.Update();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aspectRatio > 0)
|
|
|
|
{
|
2021-06-23 23:44:09 +02:00
|
|
|
MouseStateSnapshot snapshot = IMouse.GetMouseStateSnapshot(_mouse);
|
2021-06-24 02:09:08 +02:00
|
|
|
var touchPosition = IMouse.GetScreenPosition(snapshot.Position, _mouse.ClientSize, aspectRatio);
|
2021-06-14 08:42:55 +02:00
|
|
|
|
2021-06-23 23:44:09 +02:00
|
|
|
TouchAttribute attribute = TouchAttribute.None;
|
|
|
|
|
|
|
|
if (!_wasClicking && isClicking)
|
|
|
|
{
|
|
|
|
attribute = TouchAttribute.Start;
|
|
|
|
}
|
|
|
|
else if (_wasClicking && !isClicking)
|
|
|
|
{
|
|
|
|
attribute = TouchAttribute.End;
|
|
|
|
}
|
|
|
|
|
2021-06-14 08:42:55 +02:00
|
|
|
TouchPoint currentPoint = new TouchPoint
|
|
|
|
{
|
2021-06-23 23:44:09 +02:00
|
|
|
Attribute = attribute,
|
|
|
|
|
2021-06-14 08:42:55 +02:00
|
|
|
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);
|
|
|
|
|
2021-06-23 23:44:09 +02:00
|
|
|
_wasClicking = isClicking;
|
|
|
|
|
2021-06-14 08:42:55 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Dispose() { }
|
|
|
|
}
|
|
|
|
}
|