mirror of
https://github.com/love2d/love.git
synced 2026-08-12 08:30:56 +02:00
Add new drop events, add drop position to file/directorydropped.
Add love.dropbegan(), love.dropmoved(x, y), and love.dropcompleted(x, y). Resolves #1346. Resolves #2019.
This commit is contained in:
@@ -433,6 +433,29 @@ Message *Event::convert(const SDL_Event &e)
|
||||
msg = new Message("displayrotated", vargs);
|
||||
}
|
||||
break;
|
||||
case SDL_EVENT_DROP_BEGIN:
|
||||
msg = new Message("dropbegan", vargs);
|
||||
break;
|
||||
case SDL_EVENT_DROP_COMPLETE:
|
||||
{
|
||||
double x = e.drop.x;
|
||||
double y = e.drop.y;
|
||||
windowToDPICoords(&x, &y);
|
||||
vargs.emplace_back(x);
|
||||
vargs.emplace_back(y);
|
||||
msg = new Message("dropcompleted", vargs);
|
||||
}
|
||||
break;
|
||||
case SDL_EVENT_DROP_POSITION:
|
||||
{
|
||||
double x = e.drop.x;
|
||||
double y = e.drop.y;
|
||||
windowToDPICoords(&x, &y);
|
||||
vargs.emplace_back(x);
|
||||
vargs.emplace_back(y);
|
||||
msg = new Message("dropmoved", vargs);
|
||||
}
|
||||
break;
|
||||
case SDL_EVENT_DROP_FILE:
|
||||
filesystem = Module::getInstance<filesystem::Filesystem>(Module::M_FILESYSTEM);
|
||||
if (filesystem != nullptr)
|
||||
@@ -441,15 +464,23 @@ Message *Event::convert(const SDL_Event &e)
|
||||
// Allow mounting any dropped path, so zips or dirs can be mounted.
|
||||
filesystem->allowMountingForPath(filepath);
|
||||
|
||||
double x = e.drop.x;
|
||||
double y = e.drop.y;
|
||||
windowToDPICoords(&x, &y);
|
||||
|
||||
if (filesystem->isRealDirectory(filepath))
|
||||
{
|
||||
vargs.emplace_back(filepath, strlen(filepath));
|
||||
vargs.emplace_back(x);
|
||||
vargs.emplace_back(y);
|
||||
msg = new Message("directorydropped", vargs);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto *file = new love::filesystem::NativeFile(filepath, love::filesystem::File::MODE_CLOSED);
|
||||
vargs.emplace_back(&love::filesystem::NativeFile::type, file);
|
||||
vargs.emplace_back(x);
|
||||
vargs.emplace_back(y);
|
||||
msg = new Message("filedropped", vargs);
|
||||
file->release();
|
||||
}
|
||||
|
||||
@@ -115,11 +115,20 @@ function love.createhandlers()
|
||||
resize = function (w, h)
|
||||
if love.resize then return love.resize(w, h) end
|
||||
end,
|
||||
filedropped = function (f)
|
||||
if love.filedropped then return love.filedropped(f) end
|
||||
filedropped = function (f, x, y)
|
||||
if love.filedropped then return love.filedropped(f, x, y) end
|
||||
end,
|
||||
directorydropped = function (dir)
|
||||
if love.directorydropped then return love.directorydropped(dir) end
|
||||
directorydropped = function (dir, x, y)
|
||||
if love.directorydropped then return love.directorydropped(dir, x, y) end
|
||||
end,
|
||||
dropbegan = function ()
|
||||
if love.dropbegan then return love.dropbegan() end
|
||||
end,
|
||||
dropmoved = function (x, y)
|
||||
if love.dropmoved then return love.dropmoved(x, y) end
|
||||
end,
|
||||
dropcompleted = function (x, y)
|
||||
if love.dropcompleted then return love.dropcompleted(x, y) end
|
||||
end,
|
||||
lowmemory = function ()
|
||||
if love.lowmemory then love.lowmemory() end
|
||||
|
||||
Reference in New Issue
Block a user