From 49d109aa6bc4c43b8a6c47827944ce34c33d9cf8 Mon Sep 17 00:00:00 2001 From: Areloch Date: Sat, 23 Sep 2017 15:43:09 -0500 Subject: [PATCH] Enables SDL's ability to drag and drop files onto the game window and have it call back into script for handling. --- .../source/windowManager/sdl/sdlWindowMgr.cpp | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/Engine/source/windowManager/sdl/sdlWindowMgr.cpp b/Engine/source/windowManager/sdl/sdlWindowMgr.cpp index 9e5ab437f..68adf002e 100644 --- a/Engine/source/windowManager/sdl/sdlWindowMgr.cpp +++ b/Engine/source/windowManager/sdl/sdlWindowMgr.cpp @@ -230,6 +230,13 @@ PlatformWindow *PlatformWindowManagerSDL::createWindow(GFXDevice *device, const Con::warnf("PlatformWindowManagerSDL::createWindow - created a window with no device!"); } + //Set it up for drag-n-drop events +#ifdef TORQUE_TOOLS + SDL_EventState(SDL_DROPBEGIN, SDL_ENABLE); + SDL_EventState(SDL_DROPFILE, SDL_ENABLE); + SDL_EventState(SDL_DROPCOMPLETE, SDL_ENABLE); +#endif + linkWindow(window); return window; @@ -311,6 +318,39 @@ void PlatformWindowManagerSDL::_process() break; } + case(SDL_DROPBEGIN): + { + if (!Con::isFunction("onDropBegin")) + break; + + Con::executef("onDropBegin"); + } + + case (SDL_DROPFILE): + { + // In case if dropped file + if (!Con::isFunction("onDropFile")) + break; + + char* fileName = evt.drop.file; + + if (!Platform::isFile(fileName)) + break; + + Con::executef("onDropFile", StringTable->insert(fileName)); + + SDL_free(fileName); // Free dropped_filedir memory + break; + } + + case(SDL_DROPCOMPLETE): + { + if (!Con::isFunction("onDropEnd")) + break; + + Con::executef("onDropEnd"); + } + default: { //Con::printf("Event: %d", evt.type);