mirror of
https://git.naxdy.org/Mirror/Ryujinx.git
synced 2024-12-26 18:43:04 +00:00
Simplfy clamping and fix bug on window close.
This commit is contained in:
parent
249b3597a5
commit
11a2ea4843
2 changed files with 18 additions and 66 deletions
|
@ -111,69 +111,10 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
|
|||
public int UiCanvasSize => DrawStickCanvasSize;
|
||||
public int UiStickBorderSize => DrawStickBorderSize;
|
||||
|
||||
public float UiStickLeftX
|
||||
{
|
||||
get
|
||||
{
|
||||
_vectorMultiplier = 1;
|
||||
_vectorLength = GetVectorLength(UiStickLeft);
|
||||
|
||||
if (_vectorLength > MaxVectorLength)
|
||||
{
|
||||
_vectorMultiplier = MaxVectorLength / _vectorLength;
|
||||
}
|
||||
|
||||
return (UiStickLeft.Item1 * _vectorMultiplier) + DrawStickCanvasCenter;
|
||||
}
|
||||
}
|
||||
|
||||
public float UiStickLeftY
|
||||
{
|
||||
get
|
||||
{
|
||||
_vectorMultiplier = 1;
|
||||
_vectorLength = GetVectorLength(UiStickLeft);
|
||||
|
||||
if (_vectorLength > MaxVectorLength)
|
||||
{
|
||||
_vectorMultiplier = MaxVectorLength / _vectorLength;
|
||||
}
|
||||
|
||||
return (UiStickLeft.Item2 * _vectorMultiplier) + DrawStickCanvasCenter;
|
||||
}
|
||||
}
|
||||
|
||||
public float UiStickRightX
|
||||
{
|
||||
get
|
||||
{
|
||||
_vectorMultiplier = 1;
|
||||
_vectorLength = GetVectorLength(UiStickRight);
|
||||
|
||||
if (_vectorLength > MaxVectorLength)
|
||||
{
|
||||
_vectorMultiplier = MaxVectorLength / _vectorLength;
|
||||
}
|
||||
|
||||
return (UiStickRight.Item1 * _vectorMultiplier) + DrawStickCanvasCenter;
|
||||
}
|
||||
}
|
||||
|
||||
public float UiStickRightY
|
||||
{
|
||||
get
|
||||
{
|
||||
_vectorMultiplier = 1;
|
||||
_vectorLength = GetVectorLength(UiStickRight);
|
||||
|
||||
if (_vectorLength > MaxVectorLength)
|
||||
{
|
||||
_vectorMultiplier = MaxVectorLength / _vectorLength;
|
||||
}
|
||||
|
||||
return (UiStickRight.Item2 * _vectorMultiplier) + DrawStickCanvasCenter;
|
||||
}
|
||||
}
|
||||
public float UiStickLeftX => ClampVector(UiStickLeft).Item1;
|
||||
public float UiStickLeftY => ClampVector(UiStickLeft).Item2;
|
||||
public float UiStickRightX => ClampVector(UiStickRight).Item1;
|
||||
public float UiStickRightY => ClampVector(UiStickRight).Item2;
|
||||
|
||||
public float UiDeadzoneLeft => Config.DeadzoneLeft * DrawStickCanvasSize - DrawStickCircumference;
|
||||
public float UiDeadzoneRight => Config.DeadzoneRight * DrawStickCanvasSize - DrawStickCircumference;
|
||||
|
@ -221,9 +162,20 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
|
|||
_pollTokenSource.Dispose();
|
||||
}
|
||||
|
||||
private float GetVectorLength((float, float) raw)
|
||||
private (float, float) ClampVector((float, float) vect)
|
||||
{
|
||||
return (float)Math.Sqrt((raw.Item1 * raw.Item1) + (raw.Item2 * raw.Item2));
|
||||
_vectorMultiplier = 1;
|
||||
_vectorLength = MathF.Sqrt((vect.Item1 * vect.Item1) + (vect.Item2 * vect.Item2));
|
||||
|
||||
if (_vectorLength > MaxVectorLength)
|
||||
{
|
||||
_vectorMultiplier = MaxVectorLength / _vectorLength;
|
||||
}
|
||||
|
||||
vect.Item1 = vect.Item1 * _vectorMultiplier + DrawStickCanvasCenter;
|
||||
vect.Item2 = vect.Item2 * _vectorMultiplier + DrawStickCanvasCenter;
|
||||
|
||||
return vect;
|
||||
}
|
||||
|
||||
public void OnParentModelChanged()
|
||||
|
|
|
@ -879,7 +879,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
|
|||
_mainWindow.InputManager.GamepadDriver.OnGamepadConnected -= HandleOnGamepadConnected;
|
||||
_mainWindow.InputManager.GamepadDriver.OnGamepadDisconnected -= HandleOnGamepadDisconnected;
|
||||
|
||||
(ConfigViewModel as ControllerInputViewModel)._pollTokenSource?.Cancel();
|
||||
(ConfigViewModel as ControllerInputViewModel)?._pollTokenSource.Cancel();
|
||||
|
||||
_mainWindow.ViewModel.AppHost?.NpadManager.UnblockInputUpdates();
|
||||
|
||||
|
|
Loading…
Reference in a new issue