Browse Source

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.
Sasha Szpakowski 7 months ago
parent
commit
3d9d162dd6
2 changed files with 44 additions and 4 deletions
  1. 31 0
      src/modules/event/sdl/Event.cpp
  2. 13 4
      src/modules/love/callbacks.lua

+ 31 - 0
src/modules/event/sdl/Event.cpp

@@ -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();
 			}

+ 13 - 4
src/modules/love/callbacks.lua

@@ -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