Skip to content

Commit

Permalink
Fix touch under SDL3
Browse files Browse the repository at this point in the history
  • Loading branch information
M. P. Halpin authored and M. P. Halpin committed Oct 16, 2024
1 parent 1bfdc8c commit c9485a5
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions src/FNAPlatform/SDL3_FNAPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1325,7 +1325,7 @@ out ButtonState x2
{
/* This is inaccurate, but what can you do... */
flags = SDL.SDL_GetMouseState(out fx, out fy);

}
// FIXME SDL3: Should this be rounded?
x = (int) fx;
Expand Down Expand Up @@ -2196,7 +2196,7 @@ public static TouchPanelCapabilities GetTouchCapabilities()
* -caleb
*/
int numDevices;
SDL.SDL_GetTouchDevices(out numDevices);
SDL.SDL_free(SDL.SDL_GetTouchDevices(out numDevices));
bool touchDeviceExists = numDevices > 0;
return new TouchPanelCapabilities(
touchDeviceExists,
Expand All @@ -2206,19 +2206,20 @@ public static TouchPanelCapabilities GetTouchCapabilities()

public static unsafe void UpdateTouchPanelState()
{
/* FIXME SDL3: Touch
// Poll the touch device for all active fingers
long touchDevice = SDL.SDL_GetTouchDevice(0);
IntPtr fingerArray = SDL.SDL_GetTouchFingers(GetTouchDeviceId(0), out int fingers);

for (int i = 0; i < TouchPanel.MAX_TOUCHES; i += 1)
{
SDL.SDL_Finger* finger = (SDL.SDL_Finger*) SDL.SDL_GetTouchFinger(touchDevice, i);
if (finger == null)
if (i >= fingers)
{
// No finger found at this index
TouchPanel.SetFinger(i, TouchPanel.NO_FINGER, Vector2.Zero);
continue;
}

SDL.SDL_Finger* finger = ((SDL.SDL_Finger**) fingerArray)[i];

// Send the finger data to the TouchPanel
TouchPanel.SetFinger(
i,
Expand All @@ -2229,17 +2230,22 @@ public static unsafe void UpdateTouchPanelState()
)
);
}
*/

SDL.SDL_free(fingerArray);
}

public static int GetNumTouchFingers()
{
/* FIXME SDL3: Touch
return SDL.SDL_GetNumTouchFingers(
SDL.SDL_GetTouchDevice(0)
);
*/
return 0;
SDL.SDL_free(SDL.SDL_GetTouchFingers(GetTouchDeviceId(0), out int fingers));
return fingers;
}

private static unsafe ulong GetTouchDeviceId(int index)
{
IntPtr touchDeviceIDs = SDL.SDL_GetTouchDevices(out int touchDeviceCount);
ulong result = index >= 0 && index < touchDeviceCount ? ((ulong*) touchDeviceIDs)[index] : 0;
SDL.SDL_free(touchDeviceIDs);
return result;
}

#endregion
Expand Down

0 comments on commit c9485a5

Please sign in to comment.