From: Holger Schemel Date: Wed, 22 May 2024 16:47:55 +0000 (+0200) Subject: added command line option to drop file into program window X-Git-Tag: 4.4.0.0-test-2~23 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=1856b32b9d7b3c80596362cf7a3dd8e032cd83fc;p=rocksndiamonds.git added command line option to drop file into program window --- diff --git a/src/init.c b/src/init.c index 807a9a14..e451d99e 100644 --- a/src/init.c +++ b/src/init.c @@ -6752,6 +6752,9 @@ void OpenAll(void) DrawMainMenu(); + if (options.drop_file != NULL) + PushDropEvent(options.drop_file); + #if 0 Debug("internal:path", "SDL_GetBasePath() == '%s'", SDL_GetBasePath()); diff --git a/src/libgame/misc.c b/src/libgame/misc.c index 5e63c31f..ed4bd5d6 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -1704,6 +1704,7 @@ void GetOptions(int argc, char *argv[], options.player_name = NULL; options.identifier = NULL; options.level_nr = NULL; + options.drop_file = NULL; options.display_nr = 0; @@ -1870,6 +1871,15 @@ void GetOptions(int argc, char *argv[], if (option_arg == next_option) options_left++; } + else if (strncmp(option, "-drop-file", option_len) == 0) + { + if (option_arg == NULL) + FailWithHelp("option '%s' requires an argument", option_str); + + options.drop_file = getStringCopy(option_arg); + if (option_arg == next_option) + options_left++; + } else if (strncmp(option, "-verbose", option_len) == 0) { options.verbose = TRUE; diff --git a/src/libgame/system.c b/src/libgame/system.c index a1f009f7..e77e6fe6 100644 --- a/src/libgame/system.c +++ b/src/libgame/system.c @@ -1843,6 +1843,28 @@ void PushUserEvent(int code, int value1, int value2) SDL_PushEvent((SDL_Event *)&event); } +void PushDropEvent(char *file) +{ + SDL_DropEvent event; + + SDL_memset(&event, 0, sizeof(event)); + + event.type = SDL_DROPBEGIN; + event.file = NULL; + + SDL_PushEvent((SDL_Event *)&event); + + event.type = SDL_DROPFILE; + event.file = getStringCopy(file); + + SDL_PushEvent((SDL_Event *)&event); + + event.type = SDL_DROPCOMPLETE; + event.file = NULL; + + SDL_PushEvent((SDL_Event *)&event); +} + boolean PendingEscapeKeyEvent(void) { if (PendingEvent()) diff --git a/src/libgame/system.h b/src/libgame/system.h index dc6d0f36..51d783b7 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -1063,6 +1063,8 @@ struct OptionInfo char *identifier; char *level_nr; + char *drop_file; + int display_nr; boolean mytapes; @@ -2058,6 +2060,7 @@ KeyMod GetKeyModStateFromEvents(void); void StartTextInput(int, int, int, int); void StopTextInput(void); void PushUserEvent(int, int, int); +void PushDropEvent(char *); boolean PendingEscapeKeyEvent(void); void InitJoysticks(void); diff --git a/src/main.c b/src/main.c index 8ab7313d..973d0c90 100644 --- a/src/main.c +++ b/src/main.c @@ -9062,6 +9062,7 @@ static void print_usage(void) " -g, --graphics DIRECTORY alternative graphics DIRECTORY\n" " -s, --sounds DIRECTORY alternative sounds DIRECTORY\n" " -m, --music DIRECTORY alternative music DIRECTORY\n" + " --drop-file FILE drop FILE into program window\n" " --display NR open program window on display NR\n" " --mytapes use private tapes for tape tests\n" " -n, --network network multiplayer game\n"