Skip to content

Commit

Permalink
Add new drop events, add drop position to file/directorydropped.
Browse files Browse the repository at this point in the history
Add love.dropbegan(), love.dropmoved(x, y), and love.dropcompleted(x, y).

Resolves #1346.
Resolves #2019.
  • Loading branch information
slime73 committed Dec 25, 2024
1 parent 639580c commit 3d9d162
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
31 changes: 31 additions & 0 deletions src/modules/event/sdl/Event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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();
}
Expand Down
17 changes: 13 additions & 4 deletions src/modules/love/callbacks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3d9d162

Please sign in to comment.