Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for dropping files into window #1040

Closed
jefvel opened this issue Jan 26, 2022 · 4 comments · Fixed by #1043
Closed

Support for dropping files into window #1040

jefvel opened this issue Jan 26, 2022 · 4 comments · Fixed by #1043

Comments

@jefvel
Copy link
Contributor

jefvel commented Jan 26, 2022

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.

@Yanrishatum
Copy link
Contributor

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™)

@jefvel
Copy link
Contributor Author

jefvel commented Jan 26, 2022

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.

@ncannasse
Copy link
Member

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.

@jefvel
Copy link
Contributor Author

jefvel commented Jan 29, 2022

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants