SDL_image: showimage: added a -cursor command line option

From 3c766d7f9385f0033a4715604e6327250f5c29c2 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sun, 19 Oct 2025 23:12:44 -0700
Subject: [PATCH] showimage: added a -cursor command line option

---
 examples/showimage.c | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/examples/showimage.c b/examples/showimage.c
index 7488ebc6..bfd89725 100644
--- a/examples/showimage.c
+++ b/examples/showimage.c
@@ -50,6 +50,20 @@ static void draw_background(SDL_Renderer *renderer, int w, int h)
     }
 }
 
+static void set_cursor(const char *cursor_file)
+{
+    IMG_Animation *anim = IMG_LoadAnimation(cursor_file);
+    if (anim) {
+        SDL_Cursor *cursor = IMG_CreateAnimatedCursor(anim, 0, 0);
+        if (cursor) {
+            SDL_SetCursor(cursor);
+        } else {
+            SDL_Log("Couldn't create cursor with %s: %s", cursor_file, SDL_GetError());
+        }
+        IMG_FreeAnimation(anim);
+    }
+}
+
 int main(int argc, char *argv[])
 {
     SDL_Window *window = NULL;
@@ -78,8 +92,8 @@ int main(int argc, char *argv[])
 #endif
 
     flags = SDL_WINDOW_HIDDEN;
-    for ( i=1; argv[i]; ++i ) {
-        if ( SDL_strcmp(argv[i], "-fullscreen") == 0 ) {
+    for (i = 1; argv[i]; ++i) {
+        if (SDL_strcmp(argv[i], "-fullscreen") == 0) {
             SDL_HideCursor();
             flags |= SDL_WINDOW_FULLSCREEN;
         }
@@ -137,6 +151,12 @@ int main(int argc, char *argv[])
             continue;
         }
 
+        if (SDL_strcmp(argv[i], "-cursor") == 0 && argv[i + 1]) {
+            ++i;
+            set_cursor(argv[i]);
+            continue;
+        }
+
         /* Open the image file */
         ++attempted;
         if (tonemap) {