Skip to content

Commit

Permalink
ADDED: Drop files support to PLATFORM_DESKTOP_SDL
Browse files Browse the repository at this point in the history
  • Loading branch information
raysan5 committed Oct 26, 2023
1 parent d0141bd commit 067dbe8
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/platforms/rcore_desktop_sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 067dbe8

Please sign in to comment.