Implement onDropStart, onDropEnd for file dropping (#1583)

* native side

* Theoretically, things should work

* brurh forgot a letter

* another quick cpp fix

* everything works now

* onDropText isnt fully supported

* Fix typo.

* Remove accidental cSpell addition to settings.json

* Dispatch `onDropStart` and `onDropEnd` events in HTML5.

---------

Co-authored-by: player-03 <player3.14@gmail.com>
This commit is contained in:
Shahar Marcus
2024-06-04 20:46:24 +03:00
committed by GitHub
parent e4782cb1b2
commit ead4402d5f
6 changed files with 54 additions and 10 deletions

View File

@@ -507,10 +507,12 @@ class HTML5Window
// TODO: Create a formal API that supports HTML5 file objects
if (event.dataTransfer != null && event.dataTransfer.files.length > 0)
{
parent.onDropStart.dispatch();
for (file in event.dataTransfer.files)
{
parent.onDropFile.dispatch(URL.createObjectURL(file));
}
parent.onDropEnd.dispatch();
event.preventDefault();
return false;
}

View File

@@ -188,7 +188,12 @@ class NativeApplication
{
for (window in parent.windows)
{
window.onDropFile.dispatch(CFFI.stringValue(dropEventInfo.file));
switch dropEventInfo.type {
case DROP_FILE: window.onDropFile.dispatch(CFFI.stringValue(dropEventInfo.file));
case DROP_TEXT: //window.onDropText.dispatch(CFFI.stringValue(dropEventInfo.file));
case DROP_BEGIN: window.onDropStart.dispatch();
case DROP_COMPLETE: window.onDropEnd.dispatch();
}
}
}
@@ -686,6 +691,9 @@ class NativeApplication
#if (haxe_ver >= 4.0) private enum #else @:enum private #end abstract DropEventType(Int)
{
var DROP_FILE = 0;
var DROP_TEXT = 1;
var DROP_BEGIN = 2;
var DROP_COMPLETE = 3;
}
@:keep /*private*/ class GamepadEventInfo

View File

@@ -61,6 +61,10 @@ class Window
public var onClose(default, null) = new Event<Void->Void>();
public var onDeactivate(default, null) = new Event<Void->Void>();
public var onDropFile(default, null) = new Event<String->Void>();
// SDL_DROPTEXT is only implemented for X11 on Linux
//public var onDropText(default, null) = new Event<String->Void>();
public var onDropStart(default, null) = new Event<Void->Void>();
public var onDropEnd(default, null) = new Event<Void->Void>();
public var onEnter(default, null) = new Event<Void->Void>();
public var onExpose(default, null) = new Event<Void->Void>();
public var onFocusIn(default, null) = new Event<Void->Void>();