Ryujinx/src/Ryujinx.Input/HLE/TouchScreenManager.cs
TSRBerry 46b7c905f5
[Ryujinx.Input] Address dotnet-format issues (#5384)
* dotnet format style --severity info

Some changes were manually reverted.

* dotnet format analyzers --serverity info

Some changes have been minimally adapted.

* Restore a few unused methods and variables

* Address dotnet format CA1816 warnings

* Address or silence dotnet format CA1806 and a few CA1854 warnings

* Address most dotnet format whitespace warnings

* Apply dotnet format whitespace formatting

A few of them have been manually reverted and the corresponding warning was silenced

* Add comments to disabled warnings

* Simplify properties and array initialization, Use const when possible, Remove trailing commas

* Revert "Simplify properties and array initialization, Use const when possible, Remove trailing commas"

This reverts commit 9462e4136c0a2100dc28b20cf9542e06790aa67e.

* dotnet format whitespace after rebase

* Remove redundant code, convert to auto-properties and fix naming rule violations

* Remove bogus change

* Address review feedback
2023-06-28 18:23:00 +02:00

103 lines
2.9 KiB
C#

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()
{
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()
{
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()
{
GC.SuppressFinalize(this);
}
}
}