sdl2-compat: Updated for latest SDL3 changes as of 35c08c828b6b60f4bc10abfb45470098512c984f

From c5ef803c2f8af192827bace1c231ecd8bc37b439 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Mon, 15 Apr 2024 12:41:32 -0700
Subject: [PATCH] Updated for latest SDL3 changes as of
 35c08c828b6b60f4bc10abfb45470098512c984f

---
 src/sdl2_compat.c          | 28 ++++++++++++++++++++++++++++
 src/sdl3_include_wrapper.h | 23 +++++++++--------------
 src/sdl3_syms.h            |  3 +--
 3 files changed, 38 insertions(+), 16 deletions(-)

diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c
index c8b5e11..e929321 100644
--- a/src/sdl2_compat.c
+++ b/src/sdl2_compat.c
@@ -1250,6 +1250,9 @@ static int NumGamepadMappings = 0;
 
 static SDL_TouchID *TouchDevices = NULL;
 static int NumTouchDevices = 0;
+static SDL_TouchID TouchFingersDeviceID = 0;
+static SDL_Finger **TouchFingers = NULL;
+static int NumTouchFingers = 0;
 
 /* Functions! */
 
@@ -2973,6 +2976,27 @@ SDL_GetTouchName(int idx)
     return tid ? SDL3_GetTouchDeviceName(tid) : NULL;
 }
 
+DECLSPEC int SDLCALL
+SDL_GetNumTouchFingers(SDL_TouchID touchID)
+{
+    SDL3_free(TouchFingers);
+    TouchFingersDeviceID = touchID;
+    TouchFingers = SDL3_GetTouchFingers(touchID, &NumTouchFingers);
+    return NumTouchFingers;
+}
+
+DECLSPEC SDL_Finger * SDLCALL
+SDL_GetTouchFinger(SDL_TouchID touchID, int idx)
+{
+    if (touchID != TouchFingersDeviceID) {
+        SDL_GetNumTouchFingers(touchID);
+    }
+    if ((idx < 0) || (idx >= NumTouchFingers)) {
+        SDL3_SetError("Unknown touch finger");
+        return NULL;
+    }
+    return TouchFingers[idx];
+}
 
 /* Touch gestures were removed from SDL3, so this is the SDL2 implementation copied in here, and tweaked a little. */
 
@@ -4559,6 +4583,10 @@ SDL_Quit(void)
     SDL3_free(TouchDevices);
     TouchDevices = NULL;
     NumTouchDevices = 0;
+    TouchFingersDeviceID = 0;
+    SDL3_free(TouchFingers);
+    TouchFingers = NULL;
+    NumTouchFingers = 0;
 
     SDL3_Quit();
 }
diff --git a/src/sdl3_include_wrapper.h b/src/sdl3_include_wrapper.h
index 84237ba..c89f16b 100644
--- a/src/sdl3_include_wrapper.h
+++ b/src/sdl3_include_wrapper.h
@@ -378,7 +378,6 @@
 #define SDL_GetNumJoystickButtons IGNORE_THIS_VERSION_OF_SDL_GetNumJoystickButtons
 #define SDL_GetNumJoystickHats IGNORE_THIS_VERSION_OF_SDL_GetNumJoystickHats
 #define SDL_GetNumRenderDrivers IGNORE_THIS_VERSION_OF_SDL_GetNumRenderDrivers
-#define SDL_GetNumTouchFingers IGNORE_THIS_VERSION_OF_SDL_GetNumTouchFingers
 #define SDL_GetNumVideoDrivers IGNORE_THIS_VERSION_OF_SDL_GetNumVideoDrivers
 #define SDL_GetNumberProperty IGNORE_THIS_VERSION_OF_SDL_GetNumberProperty
 #define SDL_GetOriginalMemoryFunctions IGNORE_THIS_VERSION_OF_SDL_GetOriginalMemoryFunctions
@@ -487,7 +486,7 @@
 #define SDL_GetTouchDeviceName IGNORE_THIS_VERSION_OF_SDL_GetTouchDeviceName
 #define SDL_GetTouchDeviceType IGNORE_THIS_VERSION_OF_SDL_GetTouchDeviceType
 #define SDL_GetTouchDevices IGNORE_THIS_VERSION_OF_SDL_GetTouchDevices
-#define SDL_GetTouchFinger IGNORE_THIS_VERSION_OF_SDL_GetTouchFinger
+#define SDL_GetTouchFingers IGNORE_THIS_VERSION_OF_SDL_GetTouchFingers
 #define SDL_GetUserFolder IGNORE_THIS_VERSION_OF_SDL_GetUserFolder
 #define SDL_GetVersion IGNORE_THIS_VERSION_OF_SDL_GetVersion
 #define SDL_GetVideoDriver IGNORE_THIS_VERSION_OF_SDL_GetVideoDriver
@@ -942,8 +941,8 @@
 #define SDL_hid_send_feature_report IGNORE_THIS_VERSION_OF_SDL_hid_send_feature_report
 #define SDL_hid_set_nonblocking IGNORE_THIS_VERSION_OF_SDL_hid_set_nonblocking
 #define SDL_hid_write IGNORE_THIS_VERSION_OF_SDL_hid_write
-#define SDL_iPhoneSetAnimationCallback IGNORE_THIS_VERSION_OF_SDL_iPhoneSetAnimationCallback
-#define SDL_iPhoneSetEventPump IGNORE_THIS_VERSION_OF_SDL_iPhoneSetEventPump
+#define SDL_iOSSetAnimationCallback IGNORE_THIS_VERSION_OF_SDL_iOSSetAnimationCallback
+#define SDL_iOSSetEventPump IGNORE_THIS_VERSION_OF_SDL_iOSSetEventPump
 #define SDL_iconv IGNORE_THIS_VERSION_OF_SDL_iconv
 #define SDL_iconv_close IGNORE_THIS_VERSION_OF_SDL_iconv_close
 #define SDL_iconv_open IGNORE_THIS_VERSION_OF_SDL_iconv_open
@@ -2450,10 +2449,6 @@
 #undef SDL_GetNumRenderDrivers
 #endif
 
-#ifdef SDL_GetNumTouchFingers
-#undef SDL_GetNumTouchFingers
-#endif
-
 #ifdef SDL_GetNumVideoDrivers
 #undef SDL_GetNumVideoDrivers
 #endif
@@ -2886,8 +2881,8 @@
 #undef SDL_GetTouchDevices
 #endif
 
-#ifdef SDL_GetTouchFinger
-#undef SDL_GetTouchFinger
+#ifdef SDL_GetTouchFingers
+#undef SDL_GetTouchFingers
 #endif
 
 #ifdef SDL_GetUserFolder
@@ -4706,12 +4701,12 @@
 #undef SDL_hid_write
 #endif
 
-#ifdef SDL_iPhoneSetAnimationCallback
-#undef SDL_iPhoneSetAnimationCallback
+#ifdef SDL_iOSSetAnimationCallback
+#undef SDL_iOSSetAnimationCallback
 #endif
 
-#ifdef SDL_iPhoneSetEventPump
-#undef SDL_iPhoneSetEventPump
+#ifdef SDL_iOSSetEventPump
+#undef SDL_iOSSetEventPump
 #endif
 
 #ifdef SDL_iconv
diff --git a/src/sdl3_syms.h b/src/sdl3_syms.h
index 4074b01..68e9ebf 100644
--- a/src/sdl3_syms.h
+++ b/src/sdl3_syms.h
@@ -456,8 +456,7 @@ SDL3_SYM_PASSTHROUGH(void,Delay,(Uint32 a),(a),)
 SDL3_SYM_PASSTHROUGH(SDL_TimerID,AddTimer,(Uint32 a, SDL_TimerCallback b, void *c),(a,b,c),return)
 SDL3_SYM_PASSTHROUGH(SDL_bool,RemoveTimer,(SDL_TimerID a),(a),return)
 SDL3_SYM(SDL_TouchID*,GetTouchDevices,(int *a),(a),return)
-SDL3_SYM_PASSTHROUGH(int,GetNumTouchFingers,(SDL_TouchID a),(a),return)
-SDL3_SYM_PASSTHROUGH(SDL_Finger*,GetTouchFinger,(SDL_TouchID a, int b),(a,b),return)
+SDL3_SYM(SDL_Finger**,GetTouchFingers,(SDL_TouchID a, int *b),(a,b),return)
 SDL3_SYM(int,GetVersion,(SDL_Version *a),(a),return)
 SDL3_SYM_PASSTHROUGH(int,GetNumVideoDrivers,(void),(),return)
 SDL3_SYM(const char*,GetVideoDriver,(int a),(a),return)