mirror of
https://git.naxdy.org/Mirror/Ryujinx.git
synced 2025-02-06 01:29:44 +00:00
Fix error in touchscreen implementation, implement multitouch in hid
This commit is contained in:
parent
2ed733b1d5
commit
395c6cb82f
4 changed files with 47 additions and 26 deletions
|
@ -183,7 +183,7 @@ namespace Ryujinx.Core
|
||||||
Marshal.StructureToPtr(ControllerInputEntry, HidPtr, false);
|
Marshal.StructureToPtr(ControllerInputEntry, HidPtr, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SendTouchPoint(HidTouchScreenEntryTouch TouchPoint)
|
public void SendTouchCoordinates(Touches TouchPoints)
|
||||||
{
|
{
|
||||||
uint InnerOffset = (uint)Marshal.SizeOf(typeof(HidSharedMemHeader));
|
uint InnerOffset = (uint)Marshal.SizeOf(typeof(HidSharedMemHeader));
|
||||||
|
|
||||||
|
@ -203,21 +203,38 @@ namespace Ryujinx.Core
|
||||||
Marshal.StructureToPtr(TouchScreenHeader, HidPtr, false);
|
Marshal.StructureToPtr(TouchScreenHeader, HidPtr, false);
|
||||||
|
|
||||||
InnerOffset += (uint)Marshal.SizeOf(typeof(HidTouchScreenHeader))
|
InnerOffset += (uint)Marshal.SizeOf(typeof(HidTouchScreenHeader))
|
||||||
+ (uint)((uint)(OldTouchScreenHeader.LatestEntry) * Marshal.SizeOf(typeof(HidTouchScreenEntry)));
|
+ (uint)((uint)(TouchScreenHeader.LatestEntry) * Marshal.SizeOf(typeof(HidTouchScreenEntry)));
|
||||||
HidPtr = new IntPtr(Ns.Ram.ToInt64() + (uint)SharedMemOffset + InnerOffset);
|
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()
|
HidTouchScreenEntry hidTouchScreenEntry = new HidTouchScreenEntry()
|
||||||
{
|
{
|
||||||
Header = new HidTouchScreenEntryHeader()
|
Header = new HidTouchScreenEntryHeader()
|
||||||
{
|
{
|
||||||
Timestamp = (ulong)Environment.TickCount,
|
Timestamp = (ulong)Environment.TickCount,
|
||||||
NumTouches = 1
|
NumTouches = TouchPoints.NumberOfTouches
|
||||||
},
|
},
|
||||||
Touches = new HidTouchScreenEntryTouch[16]
|
Touches = new HidTouchScreenEntryTouch[16]
|
||||||
};
|
};
|
||||||
|
|
||||||
//Only supports single touch
|
//Fill the touch buffer.
|
||||||
hidTouchScreenEntry.Touches[0] = TouchPoint;
|
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);
|
Marshal.StructureToPtr(hidTouchScreenEntry, HidPtr, false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,4 +52,11 @@ namespace Ryujinx.Core
|
||||||
public byte[] Padding;
|
public byte[] Padding;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public struct Touches
|
||||||
|
{
|
||||||
|
public uint[] XTouches;
|
||||||
|
public uint[] YTouches;
|
||||||
|
public uint NumberOfTouches;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -52,9 +52,9 @@ namespace Ryujinx.Core
|
||||||
Hid.SendControllerButtons(ControllerId, Layout, Buttons, LeftJoystick, RightJoystick);
|
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)
|
internal virtual void OnFinish(EventArgs e)
|
||||||
|
|
|
@ -36,6 +36,11 @@ namespace Ryujinx
|
||||||
JoystickPosition LeftJoystick;
|
JoystickPosition LeftJoystick;
|
||||||
JoystickPosition RightJoystick;
|
JoystickPosition RightJoystick;
|
||||||
|
|
||||||
|
Touches CurrentTouchPoints = new Touches()
|
||||||
|
{
|
||||||
|
XTouches = new uint[16],
|
||||||
|
YTouches = new uint[16]
|
||||||
|
};
|
||||||
|
|
||||||
if (Keyboard[OpenTK.Input.Key.Escape]) this.Exit();
|
if (Keyboard[OpenTK.Input.Key.Escape]) this.Exit();
|
||||||
|
|
||||||
|
@ -89,26 +94,18 @@ namespace Ryujinx
|
||||||
|
|
||||||
//Get screen touch position from left mouse click
|
//Get screen touch position from left mouse click
|
||||||
//Opentk always captures mouse events, even if out of focus, so check if window is focused.
|
//Opentk always captures mouse events, even if out of focus, so check if window is focused.
|
||||||
if (Mouse != null && Focused)
|
if (Mouse != null)
|
||||||
if (Mouse.GetState().LeftButton == OpenTK.Input.ButtonState.Pressed)
|
|
||||||
{
|
{
|
||||||
HidTouchScreenEntryTouch CurrentPoint = new HidTouchScreenEntryTouch
|
if (Mouse.GetState().LeftButton == OpenTK.Input.ButtonState.Pressed && Focused)
|
||||||
{
|
{
|
||||||
Timestamp = (uint)Environment.TickCount,
|
CurrentTouchPoints.XTouches[CurrentTouchPoints.NumberOfTouches] = (uint)Mouse.X;
|
||||||
X = (uint)Mouse.X,
|
CurrentTouchPoints.YTouches[CurrentTouchPoints.NumberOfTouches] = (uint)Mouse.Y;
|
||||||
Y = (uint)Mouse.Y,
|
CurrentTouchPoints.NumberOfTouches++;
|
||||||
|
|
||||||
//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);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Send current touches
|
||||||
|
Ns.SendTouchCoordinates(CurrentTouchPoints);
|
||||||
|
|
||||||
//We just need one pair of JoyCon because it's emulate by the keyboard.
|
//We just need one pair of JoyCon because it's emulate by the keyboard.
|
||||||
Ns.SendControllerButtons(HidControllerID.CONTROLLER_HANDHELD, HidControllerLayouts.Main, CurrentButton, LeftJoystick, RightJoystick);
|
Ns.SendControllerButtons(HidControllerID.CONTROLLER_HANDHELD, HidControllerLayouts.Main, CurrentButton, LeftJoystick, RightJoystick);
|
||||||
|
|
Loading…
Reference in a new issue