浏览代码

ADDED: Drop files support to `PLATFORM_DESKTOP_SDL`

pull/3472/head
Ray 1年前
父节点
当前提交
067dbe8657
共有 1 个文件被更改,包括 29 次插入0 次删除
  1. +29
    -0
      src/platforms/rcore_desktop_sdl.c

+ 29
- 0
src/platforms/rcore_desktop_sdl.c 查看文件

@ -998,6 +998,33 @@ void PollInputEvents(void)
switch (event.type) switch (event.type)
{ {
case SDL_QUIT: CORE.Window.shouldClose = true; break; 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...) // Window events are also polled (Minimized, maximized, close...)
case SDL_WINDOWEVENT: case SDL_WINDOWEVENT:
@ -1247,6 +1274,8 @@ int InitPlatform(void)
SDL_Joystick *gamepad = SDL_JoystickOpen(0); 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()); //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 // Initialize timming system

正在加载...
取消
保存