HeapsIO / heaps

Heaps : Haxe Game Framework

Home Page:http://heaps.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support for dropping files into window

jefvel opened this issue · comments

commented

It would be cool to be able to drop files into a heaps app, and have an event for that.
So you can load files in apps easily.

SDL has the SDL_DropEvent, and for JS you can add a ondrop event onto the game canvas. Not sure about DirectX though.

I'd like to double that notion. However I'd first like to figure out the exact API it would be accessible under.

Option A:

  1. An explicit acceptDragAndDrop flag which would attach drop listener on JS and enable corresponding features on SDL/DX.
  2. A full on new hxd.Event type with drag&drop data.

Pros: Event can be delivered trough input handling system, meaning that it could be "taken" by an Interactive it was dropped on.
Cons: Can break compatibility because new enum would have to be added to switch statements. Propagates trough entire system.

Option B:
The addDragAndDrop / removeDragAndDrop methods for Window, that would enable drag&drop internally as long as there's listeners and would call said events when file is dropped.
Pros: Only things that needs drag&drop would handle it. Won't cause potential compatibility issues. (Not that people care much about them)
Cons: Less flexible.

Not sure about DirectX though

As everything with DX - it needs more work because hooks have to be manually implemented for winapi. Pretty sure I had some preliminary works on HL side to get that stuff working. But as long as we can get it working on 2 out of 3 targets it's good enough. (I.e. JS + SDL with DX being done Later™)

commented

There's also some handling that has to be done on the JS side, since there you will need the native event to get the actual data dropped into the app, compared to just getting the file path in SDL. I'm not sure what would be a good way to do that.

So going with option B might be a good idea. The listener could return an an object like { filePath: String, getData: Void -> Bytes }, or similar so it could also support folders/multiple files.

I think we need something more dynamic that "on file dropped", because we might want the app and the cursor to react to which kind of file is currently being hovered some part of the app.

commented

Would it be good if Window has the addDragAndDrop/removeDragAndDrop functions as Yanrishatum proposed, with an additional FileDropEvent enum with the values OnFileOver and OnFileDrop or similar?