SDL_image: Only go into image drag-n-drop mode if we aren't showing files from the command line

From 4a762bdfb7b43dae7a8a818567847881e49bdab4 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Fri, 31 Jan 2025 16:41:21 -0800
Subject: [PATCH] Only go into image drag-n-drop mode if we aren't showing
 files from the command line

---
 examples/showimage.c | 99 +++++++++++++++++++++++---------------------
 1 file changed, 51 insertions(+), 48 deletions(-)

diff --git a/examples/showimage.c b/examples/showimage.c
index b156c18f..94ec6f73 100644
--- a/examples/showimage.c
+++ b/examples/showimage.c
@@ -63,6 +63,7 @@ int main(int argc, char *argv[])
     SDL_Event event;
     const char *tonemap = NULL;
     const char *saveFile = NULL;
+    int attempted = 0;
     int result = 0;
 
     (void)argc;
@@ -137,6 +138,7 @@ int main(int argc, char *argv[])
         }
 
         /* Open the image file */
+        ++attempted;
         if (tonemap) {
             SDL_Surface *surface, *temp;
 
@@ -255,63 +257,64 @@ int main(int argc, char *argv[])
         texture = NULL;
     }
 
-    /* Show the window if needed */
-    SDL_SetWindowTitle(window, "showimage");
-    w = 640.0f;
-    h = 480.0f;
-    SDL_SetWindowSize(window, (int)w, (int)h);
-    SDL_ShowWindow(window);
-
-    done = quit;
-    while ( !done ) {
-        while ( SDL_PollEvent(&event) ) {
-            switch (event.type) {
-                case SDL_EVENT_DROP_FILE:
-                    {
-                        const char *file = event.drop.data;
-
-                        SDL_DestroyTexture(texture);
-
-                        SDL_Log("Loading %s\n", file);
-                        texture = IMG_LoadTexture(renderer, file);
-                        if (!texture) {
-                            SDL_Log("Couldn't load %s: %s\n", file, SDL_GetError());
+    if (attempted == 0 && !quit) {
+        /* Show the window if needed */
+        SDL_SetWindowTitle(window, "showimage");
+        w = 640.0f;
+        h = 480.0f;
+        SDL_SetWindowSize(window, (int)w, (int)h);
+        SDL_ShowWindow(window);
+
+        while ( !done ) {
+            while ( SDL_PollEvent(&event) ) {
+                switch (event.type) {
+                    case SDL_EVENT_DROP_FILE:
+                        {
+                            const char *file = event.drop.data;
+
+                            SDL_DestroyTexture(texture);
+
+                            SDL_Log("Loading %s\n", file);
+                            texture = IMG_LoadTexture(renderer, file);
+                            if (!texture) {
+                                SDL_Log("Couldn't load %s: %s\n", file, SDL_GetError());
+                                break;
+                            }
+                            SDL_SetWindowTitle(window, file);
+                            SDL_GetTextureSize(texture, &w, &h);
+                            SDL_SetWindowSize(window, (int)w, (int)h);
+                        }
+                        break;
+                    case SDL_EVENT_KEY_UP:
+                        switch (event.key.key) {
+                        case SDLK_ESCAPE:
+                        case SDLK_Q:
+                            done = 1;
                             break;
                         }
-                        SDL_SetWindowTitle(window, file);
-                        SDL_GetTextureSize(texture, &w, &h);
-                        SDL_SetWindowSize(window, (int)w, (int)h);
-                    }
-                    break;
-                case SDL_EVENT_KEY_UP:
-                    switch (event.key.key) {
-                    case SDLK_ESCAPE:
-                    case SDLK_Q:
+                        break;
+                    case SDL_EVENT_MOUSE_BUTTON_DOWN:
+                        done = 1;
+                        break;
+                    case SDL_EVENT_QUIT:
                         done = 1;
                         break;
-                    }
-                    break;
-                case SDL_EVENT_MOUSE_BUTTON_DOWN:
-                    done = 1;
-                    break;
-                case SDL_EVENT_QUIT:
-                    done = 1;
-                    break;
-                default:
-                    break;
+                    default:
+                        break;
+                }
             }
-        }
 
-        /* Draw a background pattern in case the image has transparency */
-        draw_background(renderer, (int)w, (int)h);
+            /* Draw a background pattern in case the image has transparency */
+            draw_background(renderer, (int)w, (int)h);
 
-        /* Display the image */
-        SDL_RenderTexture(renderer, texture, NULL, NULL);
-        SDL_RenderPresent(renderer);
+            /* Display the image */
+            SDL_RenderTexture(renderer, texture, NULL, NULL);
+            SDL_RenderPresent(renderer);
 
-        SDL_Delay(100);
+            SDL_Delay(100);
+        }
+        SDL_DestroyTexture(texture);
     }
-    SDL_DestroyTexture(texture);
 
     /* We're done! */
 done: