summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorRay <[email protected]>2023-10-26 23:57:07 +0200
committerRay <[email protected]>2023-10-26 23:57:07 +0200
commit067dbe8657436e4778a91ea69c260f5beba48ec6 (patch)
tree1097f20ba7369eb1587791a3ecc2582c294d99d4 /src
parentd0141bd105b491fbef9ea5fb8c3ba26ba0432717 (diff)
downloadraylib-067dbe8657436e4778a91ea69c260f5beba48ec6.tar.gz
raylib-067dbe8657436e4778a91ea69c260f5beba48ec6.zip
ADDED: Drop files support to `PLATFORM_DESKTOP_SDL`
Diffstat (limited to 'src')
-rw-r--r--src/platforms/rcore_desktop_sdl.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/platforms/rcore_desktop_sdl.c b/src/platforms/rcore_desktop_sdl.c
index ccc2acf0..8543c751 100644
--- a/src/platforms/rcore_desktop_sdl.c
+++ b/src/platforms/rcore_desktop_sdl.c
@@ -998,6 +998,33 @@ void PollInputEvents(void)
switch (event.type)
{
case SDL_QUIT: CORE.Window.shouldClose = true; break;
+
+ case SDL_DROPFILE: // Dropped file
+ {
+ if (CORE.Window.dropFileCount == 0)
+ {
+ // When a new file is dropped, we reserve a fixed number of slots for all possible dropped files
+ // at the moment we limit the number of drops at once to 1024 files but this behaviour should probably be reviewed
+ // TODO: Pointers should probably be reallocated for any new file added...
+ CORE.Window.dropFilepaths = (char **)RL_CALLOC(1024, sizeof(char *));
+
+ CORE.Window.dropFilepaths[CORE.Window.dropFileCount] = (char *)RL_CALLOC(MAX_FILEPATH_LENGTH, sizeof(char));
+ strcpy(CORE.Window.dropFilepaths[CORE.Window.dropFileCount], event.drop.file);
+ SDL_free(event.drop.file);
+
+ CORE.Window.dropFileCount++;
+ }
+ else if (CORE.Window.dropFileCount < 1024)
+ {
+ CORE.Window.dropFilepaths[CORE.Window.dropFileCount] = (char *)RL_CALLOC(MAX_FILEPATH_LENGTH, sizeof(char));
+ strcpy(CORE.Window.dropFilepaths[CORE.Window.dropFileCount], event.drop.file);
+ SDL_free(event.drop.file);
+
+ CORE.Window.dropFileCount++;
+ }
+ else TRACELOG(LOG_WARNING, "FILE: Maximum drag and drop files at once is limited to 1024 files!");
+
+ } break;
// Window events are also polled (Minimized, maximized, close...)
case SDL_WINDOWEVENT:
@@ -1247,6 +1274,8 @@ int InitPlatform(void)
SDL_Joystick *gamepad = SDL_JoystickOpen(0);
//if (SDL_Joystick *gamepad == NULL) SDL_Log("WARNING: Unable to open game controller! SDL Error: %s\n", SDL_GetError());
}
+
+ SDL_EventState(SDL_DROPFILE, SDL_ENABLE);
//----------------------------------------------------------------------------
// Initialize timming system