Replace more magic values with actual variables, fix touch screen coordinates on different window sizes

This commit is contained in:
gdkchan 2018-03-02 22:44:08 -03:00
parent 281fdb871d
commit 1119b29427
4 changed files with 78 additions and 19 deletions

View file

@ -92,19 +92,30 @@ namespace Ryujinx.Core.Input
HidControllerType.ControllerType_Handheld |
HidControllerType.ControllerType_JoyconPair;
HidControllerColorDesc ColorDesc =
bool IsHalf = false;
HidControllerColorDesc SingleColorDesc =
HidControllerColorDesc.ColorDesc_ColorsNonexistent;
JoyConColor SingleColorBody = JoyConColor.Black;
JoyConColor SingleColorButtons = JoyConColor.Black;
HidControllerColorDesc SplitColorDesc = 0;
WriteInt32(BaseControllerOffset + 0x0, (int)Type);
WriteInt32(BaseControllerOffset + 0x4, 0);
WriteInt32(BaseControllerOffset + 0x8, (int)ColorDesc);
WriteInt32(BaseControllerOffset + 0xc, 0);
WriteInt32(BaseControllerOffset + 0x10, 0);
WriteInt32(BaseControllerOffset + 0x14, 0);
WriteInt32(BaseControllerOffset + 0x4, IsHalf ? 1 : 0);
WriteInt32(BaseControllerOffset + 0x8, (int)SingleColorDesc);
WriteInt32(BaseControllerOffset + 0xc, (int)SingleColorBody);
WriteInt32(BaseControllerOffset + 0x10, (int)SingleColorButtons);
WriteInt32(BaseControllerOffset + 0x14, (int)SplitColorDesc);
WriteInt32(BaseControllerOffset + 0x18, (int)LeftColorBody);
WriteInt32(BaseControllerOffset + 0x1c, (int)LeftColorButtons);
WriteInt32(BaseControllerOffset + 0x20, (int)RightColorBody);
WriteInt32(BaseControllerOffset + 0x24, (int)RightColorBody);
WriteInt32(BaseControllerOffset + 0x24, (int)RightColorButtons);
}
public void SetJoyconButton(
@ -137,11 +148,15 @@ namespace Ryujinx.Core.Input
WriteInt64(ControllerOffset + 0x0, Timestamp);
WriteInt64(ControllerOffset + 0x8, Timestamp);
WriteInt64(ControllerOffset + 0x10, (uint)Buttons);
WriteInt32(ControllerOffset + 0x18, LeftStick.DX);
WriteInt32(ControllerOffset + 0x1c, LeftStick.DY);
WriteInt64(ControllerOffset + 0x20, RightStick.DX);
WriteInt64(ControllerOffset + 0x24, RightStick.DY);
WriteInt64(ControllerOffset + 0x28,
(uint)HidControllerConnState.Controller_State_Connected |
(uint)HidControllerConnState.Controller_State_Wired);
@ -170,19 +185,21 @@ namespace Ryujinx.Core.Input
TouchEntryOffset += HidTouchEntryHeaderSize;
const int Padding = 0;
int Index = 0;
foreach (HidTouchPoint Point in Points)
{
WriteInt64(TouchEntryOffset + 0x0, Timestamp);
WriteInt32(TouchEntryOffset + 0x8, 0);
WriteInt32(TouchEntryOffset + 0x8, Padding);
WriteInt32(TouchEntryOffset + 0xc, Index++);
WriteInt32(TouchEntryOffset + 0x10, Point.X);
WriteInt32(TouchEntryOffset + 0x14, Point.Y);
WriteInt32(TouchEntryOffset + 0x18, Point.DiameterX);
WriteInt32(TouchEntryOffset + 0x1c, Point.DiameterY);
WriteInt32(TouchEntryOffset + 0x20, Point.Angle);
WriteInt32(TouchEntryOffset + 0x24, 0);
WriteInt32(TouchEntryOffset + 0x24, Padding);
TouchEntryOffset += HidTouchEntryTouchSize;
}

View file

@ -5,6 +5,6 @@ namespace Ryujinx.Core.Input
[Flags]
public enum HidControllerColorDesc
{
ColorDesc_ColorsNonexistent = (1 << 1),
ColorDesc_ColorsNonexistent = (1 << 1)
}
}

View file

@ -2,6 +2,8 @@ namespace Ryujinx.Core.Input
{
public enum JoyConColor //Thanks to CTCaer
{
Black = 0,
Body_Grey = 0x828282,
Body_Neon_Blue = 0x0AB9E6,
Body_Neon_Red = 0xFF3C28,

View file

@ -11,6 +11,12 @@ namespace Ryujinx
{
public class GLScreen : GameWindow
{
private const int TouchScreenWidth = 1280;
private const int TouchScreenHeight = 720;
private const float TouchScreenRatioX = (float)TouchScreenWidth / TouchScreenHeight;
private const float TouchScreenRatioY = (float)TouchScreenHeight / TouchScreenWidth;
private Switch Ns;
private IGalRenderer Renderer;
@ -89,15 +95,45 @@ namespace Ryujinx
DY = RightJoystickDY
};
bool HasTouch = false;
//Get screen touch position from left mouse click
//Opentk always captures mouse events, even if out of focus, so check if window is focused.
if (Mouse != null && Focused)
if (Mouse.GetState().LeftButton == OpenTK.Input.ButtonState.Pressed)
//OpenTK always captures mouse events, even if out of focus, so check if window is focused.
if (Focused && Mouse?.GetState().LeftButton == OpenTK.Input.ButtonState.Pressed)
{
int ScrnWidth = Width;
int ScrnHeight = Height;
if (Width > Height * TouchScreenRatioX)
{
ScrnWidth = (int)(Height * TouchScreenRatioX);
}
else
{
ScrnHeight = (int)(Width * TouchScreenRatioY);
}
int StartX = (Width - ScrnWidth) >> 1;
int StartY = (Height - ScrnHeight) >> 1;
int EndX = StartX + ScrnWidth;
int EndY = StartY + ScrnHeight;
if (Mouse.X >= StartX &&
Mouse.Y >= StartY &&
Mouse.X < EndX &&
Mouse.Y < EndY)
{
int ScrnMouseX = Mouse.X - StartX;
int ScrnMouseY = Mouse.Y - StartY;
int MX = (int)(((float)ScrnMouseX / ScrnWidth) * TouchScreenWidth);
int MY = (int)(((float)ScrnMouseY / ScrnHeight) * TouchScreenHeight);
HidTouchPoint CurrentPoint = new HidTouchPoint
{
X = Mouse.X,
Y = Mouse.Y,
X = MX,
Y = MY,
//Placeholder values till more data is acquired
DiameterX = 10,
@ -105,12 +141,16 @@ namespace Ryujinx
Angle = 90
};
HasTouch = true;
Ns.Hid.SetTouchPoints(CurrentPoint);
}
else
{
Ns.Hid.SetTouchPoints();
}
}
if (!HasTouch)
{
Ns.Hid.SetTouchPoints();
}
Ns.Hid.SetJoyconButton(
HidControllerId.CONTROLLER_HANDHELD,