Fix error in touchscreen implementation, implement multitouch in hid

This commit is contained in:
emmaus 2018-02-24 10:15:35 +00:00
parent 2ed733b1d5
commit 395c6cb82f
4 changed files with 47 additions and 26 deletions

View file

@ -183,7 +183,7 @@ namespace Ryujinx.Core
Marshal.StructureToPtr(ControllerInputEntry, HidPtr, false);
}
public void SendTouchPoint(HidTouchScreenEntryTouch TouchPoint)
public void SendTouchCoordinates(Touches TouchPoints)
{
uint InnerOffset = (uint)Marshal.SizeOf(typeof(HidSharedMemHeader));
@ -203,21 +203,38 @@ namespace Ryujinx.Core
Marshal.StructureToPtr(TouchScreenHeader, HidPtr, false);
InnerOffset += (uint)Marshal.SizeOf(typeof(HidTouchScreenHeader))
+ (uint)((uint)(OldTouchScreenHeader.LatestEntry) * Marshal.SizeOf(typeof(HidTouchScreenEntry)));
HidPtr = new IntPtr(Ns.Ram.ToInt64() + (uint)SharedMemOffset + InnerOffset);
+ (uint)((uint)(TouchScreenHeader.LatestEntry) * Marshal.SizeOf(typeof(HidTouchScreenEntry)));
HidPtr = new IntPtr(Ns.Ram.ToInt64() + (uint)SharedMemOffset + InnerOffset);
//Truncate number of touches
TouchPoints.NumberOfTouches = TouchPoints.NumberOfTouches > 16 ? 16 : TouchPoints.NumberOfTouches;
HidTouchScreenEntry hidTouchScreenEntry = new HidTouchScreenEntry()
{
Header = new HidTouchScreenEntryHeader()
{
Timestamp = (ulong)Environment.TickCount,
NumTouches = 1
NumTouches = TouchPoints.NumberOfTouches
},
Touches = new HidTouchScreenEntryTouch[16]
};
//Only supports single touch
hidTouchScreenEntry.Touches[0] = TouchPoint;
//Fill the touch buffer.
for (uint index = 0; index < TouchPoints.NumberOfTouches; index++)
{
hidTouchScreenEntry.Touches[index] = new HidTouchScreenEntryTouch()
{
Timestamp = (uint)Environment.TickCount,
X = TouchPoints.XTouches[index],
Y = TouchPoints.YTouches[index],
TouchIndex = index,
//Placeholder values till more data is acquired
DiameterX = 10,
DiameterY = 10,
Angle = 90,
};
}
Marshal.StructureToPtr(hidTouchScreenEntry, HidPtr, false);
}

View file

@ -52,4 +52,11 @@ namespace Ryujinx.Core
public byte[] Padding;
}
public struct Touches
{
public uint[] XTouches;
public uint[] YTouches;
public uint NumberOfTouches;
}
}

View file

@ -52,9 +52,9 @@ namespace Ryujinx.Core
Hid.SendControllerButtons(ControllerId, Layout, Buttons, LeftJoystick, RightJoystick);
}
public void SendTouchScreenEntry(HidTouchScreenEntryTouch TouchPoint)
public void SendTouchCoordinates(Touches TouchPoints)
{
Hid.SendTouchPoint(TouchPoint);
Hid.SendTouchCoordinates(TouchPoints);
}
internal virtual void OnFinish(EventArgs e)

View file

@ -36,6 +36,11 @@ namespace Ryujinx
JoystickPosition LeftJoystick;
JoystickPosition RightJoystick;
Touches CurrentTouchPoints = new Touches()
{
XTouches = new uint[16],
YTouches = new uint[16]
};
if (Keyboard[OpenTK.Input.Key.Escape]) this.Exit();
@ -89,26 +94,18 @@ namespace Ryujinx
//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)
if (Mouse != null)
{
if (Mouse.GetState().LeftButton == OpenTK.Input.ButtonState.Pressed && Focused)
{
HidTouchScreenEntryTouch CurrentPoint = new HidTouchScreenEntryTouch
{
Timestamp = (uint)Environment.TickCount,
X = (uint)Mouse.X,
Y = (uint)Mouse.Y,
//Placeholder values till more data is acquired
DiameterX = 10,
DiameterY = 10,
Angle = 90,
//Only support single touch
TouchIndex = 0,
};
if (Mouse.X > -1 && Mouse.Y > -1)
Ns.SendTouchScreenEntry(CurrentPoint);
CurrentTouchPoints.XTouches[CurrentTouchPoints.NumberOfTouches] = (uint)Mouse.X;
CurrentTouchPoints.YTouches[CurrentTouchPoints.NumberOfTouches] = (uint)Mouse.Y;
CurrentTouchPoints.NumberOfTouches++;
}
}
//Send current touches
Ns.SendTouchCoordinates(CurrentTouchPoints);
//We just need one pair of JoyCon because it's emulate by the keyboard.
Ns.SendControllerButtons(HidControllerID.CONTROLLER_HANDHELD, HidControllerLayouts.Main, CurrentButton, LeftJoystick, RightJoystick);