mirror of
https://github.com/love2d/love.git
synced 2026-08-17 11:00:31 +02:00
Added runtime drag-and-drop file and folder support via new love.filedropped and love.directorydropped event callback functions. filedropped has a single File object argument, and directorydropped has a single string argument containing the full path of the directory, which can be used with love.filesystem.mount.
--HG-- branch : minor
This commit is contained in:
@@ -20,6 +20,8 @@
|
||||
|
||||
#include "Event.h"
|
||||
|
||||
#include "filesystem/DroppedFile.h"
|
||||
#include "filesystem/Filesystem.h"
|
||||
#include "keyboard/Keyboard.h"
|
||||
#include "mouse/Mouse.h"
|
||||
#include "joystick/JoystickModule.h"
|
||||
@@ -108,7 +110,8 @@ Message *Event::convert(const SDL_Event &e) const
|
||||
{
|
||||
Message *msg = NULL;
|
||||
|
||||
love::keyboard::Keyboard *kb = 0;
|
||||
love::keyboard::Keyboard *kb = nullptr;
|
||||
love::filesystem::Filesystem *filesystem = nullptr;
|
||||
|
||||
love::keyboard::Keyboard::Key key;
|
||||
love::mouse::Mouse::Button button;
|
||||
@@ -210,6 +213,29 @@ Message *Event::convert(const SDL_Event &e) const
|
||||
msg = convertWindowEvent(e);
|
||||
break;
|
||||
case SDL_DROPFILE:
|
||||
filesystem = Module::getInstance<filesystem::Filesystem>(Module::M_FILESYSTEM);
|
||||
if (filesystem != nullptr)
|
||||
{
|
||||
// Allow mounting any dropped path, so zips or dirs can be mounted.
|
||||
filesystem->allowMountingForPath(e.drop.file);
|
||||
|
||||
if (filesystem->isRealDirectory(e.drop.file))
|
||||
{
|
||||
arg1 = new Variant(e.drop.file, strlen(e.drop.file));
|
||||
msg = new Message("directorydropped", arg1);
|
||||
arg1->release();
|
||||
}
|
||||
else
|
||||
{
|
||||
Proxy proxy;
|
||||
proxy.data = new love::filesystem::DroppedFile(e.drop.file);
|
||||
proxy.flags = FILESYSTEM_DROPPED_FILE_T;
|
||||
arg1 = new Variant(FILESYSTEM_DROPPED_FILE_ID, &proxy);
|
||||
msg = new Message("filedropped", arg1);
|
||||
arg1->release();
|
||||
((Object *) proxy.data)->release();
|
||||
}
|
||||
}
|
||||
SDL_free(e.drop.file);
|
||||
break;
|
||||
case SDL_QUIT:
|
||||
|
||||
Reference in New Issue
Block a user