SFML community forums

General => Feature requests => Topic started by: Mr_Blame on October 07, 2015, 04:04:09 pm

Title: File drop
Post by: Mr_Blame on October 07, 2015, 04:04:09 pm
Hello  :)
Why can't we add support for file dropping in window(you know when you drag'n'drop a file in editor window and it opens it)(as example it is supproted in GLFW)
Title: Re: File drop
Post by: eXpl0it3r on October 07, 2015, 04:25:40 pm
Please follow the contribution guidelines for feature requests:

Quote from: Contribution Guidelines (http://www.sfml-dev.org/contribute.php#requesting-features)
A feature request should always contain a rationale for the change. Whenever you suggest a feature, argue from a user perspective: in which way is SFML limited? What use cases does the feature allow? How can other users benefit from the change?
Title: Re: File drop
Post by: Laurent on October 07, 2015, 07:17:54 pm
What does it mean to "support" it? What kind of files should we handle, and what should we do with them?

When you drop a file on an executable, its path is passed as an argument so you can retrieve it with argv[1] and do whatever you want with it in your program.
Title: Re: File drop
Post by: Mr_Blame on October 07, 2015, 09:11:28 pm
In glfw it supports any file format. In glfw when you drop a file in app's OPENNED WINDOW it calls callback with params: window on wich was dropped a file and its name.
Title: Re: File drop
Post by: zsbzsb on October 08, 2015, 12:08:38 am
You do realize that dropping isn't limited to files, drag and drop can support a wide variety of meta types. And then if we did implement the dropping part, the next request is for starting the drag from within an SFML window.

And you still haven't answered the basic questions from the contribution guidelines.
Title: Re: File drop
Post by: Ruckamongus on October 08, 2015, 10:58:28 pm
I like this feature request. I think it would fit well as an sf::Event? For example, lets say you have a media player. It'd be nice to allow a user to drag a media file from the desktop and drop it into the media player instead of having to go through a file->open type of dialog.

Formally:
In which way is SFML limited?
SFML does not have a way to know if something was dragged (such as a file) onto the running application window.

What use cases does the feature allow?
Allowing the opening of media files for a media player, save game/project files in some sort of editor (such as a scene designer), or dropping links/images from elsewhere to be modified in app.

How can other users benefit from the change?
Having a mechanism to interact with outside media makes sense for Simple and Fast Multimedia Library. End user convenience is in the aforementioned part.


How would it be implemented? I don't know. I've never used this feature in a lower level language, so I don't know the underlying considerations necessary to make a good proposal here. Here's a rudimentary idea:

enum MetaType {File, Text, Unknown};

struct DragData
{
     sf::String Text;
     MetaType Type;
}

//....Somehow be given a DragData struct from SFML:
DragData data;
if (Data.Type == MetaType::File)
{
     std::ifstream File(Data.Text.toAnsiString());
}
 

Then a window can have a function or event that can return a DragData. I honestly have no idea what types would fall into the "MetaData" enum (again, I'm not really educated with this aspect), or how a window would handle multiple files or "DragData" structs dropped into the window at once.

Anyway, aside from my terribly ignorant implementation idea, I think the overall suggestion may not be a bad one. Especially if SFML will support file systems (I believe this idea was thrown around in the forums somewhere too).
Title: Re: File drop
Post by: GraphicsWhale on October 09, 2015, 11:06:09 pm
I don't see how this would benefit many people. I suppose possibly custom music selection? In game resource editing? But then again, that's pretty rare, and a file selection dialog could easily work just as well.

Having a mechanism to interact with outside media makes sense for Simple and Fast Multimedia Library. End user convenience is in the aforementioned part.

I don't see how drag-and-dropping has to do with multimedia. It's just a faster alternative to dialog boxes.

Anyway, aside from my terribly ignorant implementation idea

Why'd you suggest it then? :) /s
Title: Re: File drop
Post by: Satus on October 09, 2015, 11:50:14 pm
Well, I can imagine some use cases for this feature, for example image gallery or video/music player, or level editor.
Title: Re: File drop
Post by: GraphicsWhale on October 10, 2015, 02:20:45 am
Well, I can imagine some use cases for this feature, for example image gallery or video/music player, or level editor.

While those are all valid uses for drag-and-drop, I'm not quite convinced the first two are the kind of applications one would make using SFML. Or why anybody would want to make them at all for that matter. Still support the feature, though, because the third one you stated is relevant and actually sounds pretty helpful.
Title: Re: File drop
Post by: Satus on October 10, 2015, 02:29:58 am
While those are all valid uses for drag-and-drop, I'm not quite convinced the first two are the kind of applications one would make using SFML.

Well, if I remember correctly, there was video player implemented with SFML and that it wasn't bad at all.

But yeah, I'm not sure that is this feature will be used by more than few people.
Title: Re: File drop
Post by: binary1248 on October 10, 2015, 05:11:58 pm
The question that really has to be asked is: Is SFML the library people would use when they need this kind of interaction with other applications? It is true that other libraries like GLFW have support for this, but I honestly can't think of a use case where one would use GLFW over something like... Qt or wxWidgets or any other more specialized UI library to create an application that needs this kind of support.

Just think about it, SFML's main target is applications that do all their rendering exclusively through OpenGL. Most of the time, SFML applications don't even need proper UI widget support. There are GUI libraries like SFGUI and TGUI, but their users know well that they aren't designed to compete with "real" widget libraries like Qt that provide native looking widgets. If someone really needs drag and drop support in an application making use of SFML, they would be better off embedding an SFML window into a widget from another library. This brings me to what I think the reason is that GLFW supports drag and drop: From what I can tell, GLFW doesn't allow embedding their windows in widgets from other libraries like SFML does, so I guess from that point of view providing their own drap and drop support kind of makes sense.

As examples, look at any game that would typically be played in fullscreen. They probably don't support drag and drop even when you play them in windowed mode. The example of the video player that was brought up isn't a typical application of the sfeMovie library if you ask me. sfeMovie's main purpose is to provide applications who render exclusively through OpenGL a way to render movies as part of their 2D/3D scene. If you asked me to make a video player application, sure I could use SFML and sfeMovie, but why do so if I could make something even better and more suited to the task using Qt and a dedicated movie playback library (if Qt doesn't already support it somehow)?

It's all a question of what SFML is and isn't designed to do. I don't know what direction GLFW is taking/took, but SFML tries to have a well-defined aim. This means having to reject supporting stuff that only sees use in niche application types.
Title: Re: File drop
Post by: GraphicsWhale on October 11, 2015, 02:56:52 am
Pros:
- Great for resource importation (such as custom music or custom file format importer/exporter)
- Opens up new uses for SFML

Cons:
- Has to be implemented
- Has to be maintained
- Moves away from the library being about mostly about game development
- Introduces a feature that only works on certain platforms (doesn't work on mobile)

It'd be a cool feature, but there's understandable reasons why it probably wont be implemented.
Title: Re: File drop
Post by: IngloriousTom on October 12, 2015, 05:05:54 pm
I beg to differ !

- Has to be implemented
- Has to be maintained
True for any other feature

Quote
- Moves away from the library being about mostly about game development
While true for the library usage, the purpose is not limited to game development and I personally have three SFML projects unrelated to games.


Quote
- Introduces a feature that only works on certain platforms (doesn't work on mobile)
Not unheard of, since touch support is currently only available on mobile.

I would love to see drag and drop implemented because it is a common interaction in Windows, Linux and Mac, and certainly even more OS.
But I agree that it's a complex feature and few users will ever need it.
Title: Re: File drop
Post by: Hapax on October 12, 2015, 05:44:25 pm
Although I've not come across a time that I have used this, it could well be the fact that I didn't have the ability to do so so it was not a considered possibility.

Generating an sf::Event idea is an extremely interesting approach.

I would like to point out that SFML isn't "games-only" as many people keep saying. If it is, this introduction should probably be altered:
Quote
SFML provides a simple interface to the various components of your PC, to ease the development of games and multimedia applications.
Title: Re: File drop
Post by: Nexus on October 12, 2015, 11:02:16 pm
I would love to see drag and drop implemented because it is a common interaction in Windows, Linux and Mac, and certainly even more OS.
Would you also be willing to draft an API, write an implementation, test it on various platforms, get feedback, and maintain it even 2 years later when new bugs appear? I'm not saying this alone would help the feature be integrated, but you should be aware that there's more to it than just "hey this would be nice, please implement it". This without considering the dozens (https://github.com/SFML/SFML/issues) of more important tasks at the moment, and the questionable scope of the feature itself ;)

I would like to point out that SFML isn't "games-only" as many people keep saying. If it is, this introduction should probably be altered:
People keep saying that SFML focuses on games, not that it is games-only. And this still holds true, most applications written with SFML are games. The user base is indeed a factor we consider when thinking about what needs to part of the library or not.
Title: Re: File drop
Post by: GraphicsWhale on October 13, 2015, 01:35:45 am
- Has to be implemented
- Has to be maintained
True for any other feature

Of course. But the SFML team consists of only a handful of people who spend their spare time maintaining the library, and they probably are mostly hobbyists (correct me if I'm wrong).

It's not as simple as just coming up with an idea. Some of these features may take days to implement and get running properly. And it'll have to be maintained for the lifetime of the library.

So it's important to consider whether or not the feature is really worth putting off bug fixes and useful features for.

- Moves away from the library being about mostly about game development
While true for the library usage, the purpose is not limited to game development and I personally have three SFML projects unrelated to games.

The library can very well be used for non-game applications, and there's no problems with that. However, most of the applications made with SFML are games.

- Introduces a feature that only works on certain platforms (doesn't work on mobile)
Not unheard of, since touch support is currently only available on mobile.

http://www.newegg.com/Touch-Screen-Monitors/SubCategory/ID-514 (http://www.newegg.com/Touch-Screen-Monitors/SubCategory/ID-514)

Input devices shouldn't count.
Controllers could be considered a "console-only" feature, but I use one for certain PC games sometimes.

I was more talking about OS-specific features. A mobile game shouldn't ask you to change your config file, and a desktop game shouldn't ask if you want to be taken to the app store (well, the latter used to be true). Same goes for drag & drop.
Title: Re: File drop
Post by: Turbine on November 03, 2015, 12:26:51 am
I wouldn't mind using this feature to easily upload skins for user's ship armour, or crawl a resource archive.
Title: Re: File drop
Post by: ratzlaff on November 03, 2015, 09:27:52 pm
I would use this feature to test out a lua script
Title: Re: File drop
Post by: GraphicsWhale on November 05, 2015, 05:34:06 am
I would use this feature to test out a lua script

I get what you're saying, but couldn't you just use a certain reserved key or in-game command to do that for you? How would your game know where to use the script (assuming you're using more than a single script, which is usually)?
Title: Re: File drop
Post by: ratzlaff on November 05, 2015, 04:04:32 pm
I would use this feature to test out a lua script

I get what you're saying, but couldn't you just use a certain reserved key or in-game command to do that for you? How would your game know where to use the script (assuming you're using more than a single script, which is usually)?

You assume I only want to run a specific lua script. No this would be to test out and iterate on any script I want to run.

Think of it as an alternative to copy-paste into the console.

Could you do it other ways? certainly. Would they be as quick to use? They are not.
Disclaimer: we utilize drag and drop to test out our scripts like this on the software I maintain at work.
Title: Re: File drop
Post by: GraphicsWhale on November 05, 2015, 11:26:25 pm
I'm confused. You say you want to test out a specific script. But dropping a file into the window does not tell it what the script is for (i.e. a script for AI, a script for GUI, etc) . If you have 10 scripts running, and you want to test a new one by dropping it into the window, how does it know what the script is supposed to be used for?

And if you're just testing out Lua in general, why not use an IDE instead of trying to drop it into an application?
Title: Re: File drop
Post by: SpeCter on November 06, 2015, 09:48:26 am
Why should SFML care at all what should be done with the dropped file?
Just let SFML create an Event like FileDropEvent, attach the filepath to it and let the user handle the rest.
Title: Re: File drop
Post by: Satus on November 06, 2015, 09:53:39 am
Why should SFML care at all what should be done with the dropped file?

Following this logic, you can request any feature to be added.
Title: Re: File drop
Post by: SpeCter on November 06, 2015, 11:11:37 am
Why should SFML care at all what should be done with the dropped file?

Following this logic, you can request any feature to be added.

Sorry, but I'm not quite sure what you want to say or how you came to that conclusion from what I said.
Title: Re: File drop
Post by: Satus on November 06, 2015, 02:00:50 pm
Sorry, but I'm not quite sure what you want to say or how you came to that conclusion from what I said.

You said:
Why should SFML care at all what should be done with the dropped file?

But it is wrong. If you want a feature to be added to library, you have to provide a reason for that. That includes, what problems will this feature solve, how many users will benefit from this feature, what are typical use cases etc.

Though, I personally think that a multimedia library should have file drop support.
Title: Re: File drop
Post by: SpeCter on November 06, 2015, 02:56:29 pm
Sorry, but I'm not quite sure what you want to say or how you came to that conclusion from what I said.

You said:
Why should SFML care at all what should be done with the dropped file?

But it is wrong. If you want a feature to be added to library, you have to provide a reason for that. That includes, what problems will this feature solve, how many users will benefit from this feature, what are typical use cases etc.

Though, I personally think that a multimedia library should have file drop support.

I didn't say that I want this feature(Though I would like it). What I said is, that SFML should not be concerned with what kind of file was dragged onto the window.
If a feature like file drop was added, SFML should just notify the program that a file was dropped.

For example:


From here on SFML's job should be done.
It should be the users responsibility to choose what has to be done with the awesomesong.mp3.
With the supplied information you have everything you need to open the file and in this example play music.

tl;dr
SFML itself shouldn't care what to do with the file itself. Just notify the program through an event that a file drop happened.
This is what I think what should be SFML's responsibility if this feature gets added.

I still fail to see how you come to your conclusion that by my logic every feature can be requested to be added.
I neither requested this feature, nor did I try to justify it. I even said that SFML should not care about what to do with the file as in that is not SFML's responsibility.
Title: Re: File drop
Post by: GraphicsWhale on November 08, 2015, 09:45:26 am
Never did we suggest that SFML should decide on what to do depending on the type of file. The problem is that it's hard to implement and maintain features, so if you need to add one then it better be useful.

If you're referring to the Lua thing I was just saying that many applications that use scripts usually use more than one script, so dragging-and-dropping it into the window doesn't make a whole lot of sense since the application (which consists of more than just SFML) wouldn't know where to place that script since different scripts serve different purposes.

This applies to more than games, but for example: If your game has two scripts, one for GUI that has an onButtonClick function and one for AI that has an onPlayerSeen function, they're obviously not interchangeable, so how do you know which of the two purposes the script serves? You can't (at least not with drag-and-drop). And if you're just testing out a single Lua script that doesn't require any specific functions to be defined, why not use an actual Lua IDE or something instead? Let alone the fact that if you have a single script and version control, you could just have an "update script" hotkey and just modify the one file instead of dragging-and-dropping files into your window.
Title: Re: File drop
Post by: jdiamond on January 29, 2016, 06:19:51 pm
Well, I can imagine some use cases for this feature, for example image gallery or video/music player, or level editor.

While those are all valid uses for drag-and-drop, I'm not quite convinced the first two are the kind of applications one would make using SFML. Or why anybody would want to make them at all for that matter. Still support the feature, though, because the third one you stated is relevant and actually sounds pretty helpful.

I think this notion that SFML is just for games is completely misguided.  Any library that makes the creation of a graphical tool easier is priceless.  I am evaluating SFML for the creation of graphical utilities, because it's much simpler to use than OpenSDL.  And for utilities, drag an drop is a very handy way for people to locate directories, save or retrieve images, etc.

If it were so easy to use native GUI systems then none of these libraries would be popular.  But the fact is that few people have created graphical APIs with programmers in mind.  SFML is exactly the type of code that used to sell for $500 each to developers.

Title: Re: File drop
Post by: Phanoo on August 11, 2016, 04:39:42 pm
I suggest adding this functionnality, it's really needed for modern apps where you can drag-n-drop files instead of choosing them from the file explorer. But no problem it's probably too much work :)
Title: Re: File drop
Post by: Phanoo on August 26, 2016, 05:05:27 pm
SDL2 has it : https://wiki.libsdl.org/SDL_DropEvent
Title: Re: File drop
Post by: Hapax on August 26, 2016, 07:57:58 pm
SFML doesn't need to implement the drop event as long as it destroy the events that it doesn't use and that has been discussed (for SFML 3). Don't think it got confirmed for certain though.

Then, you could implement this event from the remaining events yourself. Still, if SFML wanted to, I suppose it could transform this event into its own.
Title: Re: File drop
Post by: Ruckamongus on August 26, 2016, 08:21:45 pm
SDL's API is exactly how I imagined SFML to have it. Really, all I'd want is a file path, I can get the name, figure out what to do with it, etc. myself. Still, we're going down the "SFML is not SDL so stop comparing" and "give us a proper usage case" road. It seems the consensus is it's not going to happen unless somebody can produce a working PR (even then who knows? (https://github.com/SFML/SFML/pull/715)).

I should clarify I love SFML despite the tone of my post; I use it almost exclusively. It just seems that development is very slow due to... excessive thoughtfulness? It seems a topic, suggestion, or PR can be beat around for months at a time with no real progress to be made.
Title: Re: File drop
Post by: Phanoo on September 18, 2017, 04:11:49 pm
I completely agree, and that's why i often make fun and cynical answers to Laurent's posts. His work is great no problem. BUT. Tooooo much thoughtfulness, endless useless debates instead of implementing the damn functionnality that would take less time than talking about it (well ok, not all of them are easy to implement, but some ARE)

I've also asked for a way to set Line Height attribute for Texts, first answer i got is something like "why would you need that", "just edit the font itself"...

I'm making a (free) software that aims for professional quality with SFML, and i just can't forget the drag&drop for my users, wake up we are in 2017 lulz

Dunno why we have to justify the evidence
Title: Re: File drop
Post by: Laurent on September 18, 2017, 10:52:07 pm
I don't know if you noticed, but now that SFML development is driven by the team and the community (most contributions are "external" now), things get more easily integrated. I don't even participate to most of the discussions, and when I do, it's to comment on implementation things.

Line height is implemented by the way.

If you provide a (not even complete) PR for drag&drop, it will probably be integrated.

Quote
Dunno why we have to justify the evidence
I like to think that questioning everything, even the evidence, allows to come up with new choices and ideas. If we all make the same things, similar to what others did before us, ... what's the point? ;)
Title: Re: File drop
Post by: FRex on September 20, 2017, 09:31:49 am
I consider feature parity important, especially with stuff that is so simple to code (at least in Windows).

Someone will someday move to SDL or GLFW and say he missed this in SFML and say it online, just like people used to give SDL crap for not having multi window support long ago when SFML had it.
No one will care about 'oh, SFML is not like a super toolkit' and such and they will even say we are stupid for saying these things and spending time on excuses instead of implementation.
The use case of dropping images or scripts or whatever on the window is compelling enough to me.

As for types and stuff - no. This isn't how this works, all you get in a drop files event is a list of file names, not data, not types, etc. just a bunch of strings with full filenames of what files were dropped on the window, it's up to you to open them if you want and if they are no longer there or not accessible to your process or whatever - up to you to deal with it too.

Here is a proof of concept for Windows, of course that void * in Event is a placeholder just to get it running quickly. Maybe the list could be accessible in the window and be filled on event and the event to just contain a pointer to it and XY..? I have no idea, it's hard to do cleanly the way SFML does things.

As for Linux, it's a bit more complex and I didn't read into https://www.freedesktop.org/wiki/Specifications/XDND/ yet so that'll take a while, maybe it should wait until the API is in place.

Here is a repo https://github.com/FRex/SFML/tree/win32_drag_and_drop and a test program:
#include <SFML/Window.hpp>
#include <iostream>

int main(int argc, char ** argv)
{
    sf::Window app(sf::VideoMode(640u, 480u), "Drag and Drop");
    while(app.isOpen())
    {
        sf::Event eve;
        while(app.pollEvent(eve))
        {
            if(eve.type == sf::Event::Closed)
                app.close();

            if(eve.type == sf::Event::FilesDropped)
            {
                std::printf("Got files on %d, %d:\n", eve.fileDrop.x, eve.fileDrop.y);
                const auto& fs = *(const std::vector<std::string>*)(eve.fileDrop.files);
                for(auto f : fs)
                    std::cout << f << std::endl;

                std::cout << "-----------------" << std::endl;
            }
        }//while app poll event eve
        app.display();
    }//while app is open
}
Title: Re: File drop
Post by: Hiura on September 20, 2017, 10:12:35 am
As for types and stuff - no. This isn't how this works, all you get in a drop files event is a list of file names, not data, not types, etc. just a bunch of strings with full filenames of what files were dropped on the window, it's up to you to open them if you want and if they are no longer there or not accessible to your process or whatever - up to you to deal with it too.

This might be okay for Microsoft Windows platforms, but SFML aims to be cross-platform and therefore such assumptions are frequently what make API limited, forcing people to write more workaround than necessary.

Note that a PR is already open with exactly the same focus and issues. See my concerns there: https://github.com/SFML/SFML/pull/1222#issuecomment-301183280 (It also has setFileDroppingEnabled, which is an interesting feature.)

I think it's the right time to get a proper API design about how to handle different data types as this is a common feature with the scheduled improvement of the clipboard API. Without answering this first, we might end up with inconsistent APIs.
Title: Re: File drop
Post by: FRex on September 20, 2017, 12:41:16 pm
This is just for files, the other data can have own event to not force users to do switch in a switch. I don't think anything in events right now requires such a construct. I actually noticed the text only clipboard we got when I took a look at this which is why I thought we might focus on the biggest catch first here too.

Honestly, even file names are kind of problematic-ish because on Windows they use a 16bit wchar and on Linux it's all normal chars in UTF8. I converted to an std::string because I assume we use that for filename, as we do in all the loadFromFile and openFromFile functions. Text drag and drop can be sf::String of course.

According to http://anton.maurovic.com/posts/win32-api-approach-to-windows-drag-and-drop/ Windows supports non-file list drag and drop (and it clearly does as you can drag and drop text between textual elements of different windows/programs) but only via COM or a third party library that wraps that COM..?

According to https://www.freedesktop.org/wiki/Specifications/XDND/ Linux (or more accurately anything using X) seems to support other kinds of data. No idea about Wayland but it probably does too and we don't have a Wayland backend anyway. :P

I've seen LCL (a Pascal GUI toolkit, quite portable and using one of other GUI toolkits as backend) only implement the file list drag and drop, Qt seems to implement it all and mesh it into one 'drop event'.

Toggling the drop acceptance of course possible too (for winapi at least, not sure with X and win COM).

I also have no idea for a good API. ;D

I also hate to give Windows only stuff a slack but maybe drop files is a good cut off point to satisfy most users with least effort. No drag and drop at all will be much worse than a drag and drop that only handles file list and one that handles everything will be complicated, so this might do or at least do for now.

We are already cutting many corners and saying we are not that rich of a windowing toolkit, like not supporting transparent and non rectangular windows, the tray, client side decorations, etc. and just tell people to use the window handle then so we might as well do just file drop since it'll satisfy most users and the code for the (sadly..) most popular platform is SO simple.

I'm not sure if that COM code for rich drag and drop needs more than just a handle, but the win api file drop required handling a message in SFML code, I'll try see if it's possible to replace the message handler or not with just what SMFL exposes to user and the winapi, if yes then this might serve as a workaround for now.
Title: Re: File drop
Post by: Phanoo on September 20, 2017, 03:13:08 pm
I didnt managed to get filedrop working only with SFML's getWindowHandle + windows API functions. I'm able to get the drop icon when a file is dragged into the window but the callbacks doesn't work despite my attempts. I'm not sure if it's possible without modifying SFML code to handle the windows filedrop messages. (please note i'm not familiar with windows API, I just messed with some code found here and there)


For the way it should work, getting the files paths and drop position is really all everyone needs IMO, + something to enable/disable it (so the developer can use it to create specific drop zones).
Title: Re: File drop
Post by: FRex on September 20, 2017, 04:28:41 pm
It's sort of possible but you'll need a global pointer for the original function and some global structure (not in the example) to inform yourself of the files being dropped and of the names themselves. Sadly, the userdata of the handle can't be used - SFML uses that to store sf::Window pointer.

See: https://gist.github.com/FRex/3f7b8d1ad1289a2117553ff3702f04af

I'm not familiar with win api either BTW. :P
Title: Re: File drop
Post by: barnack on October 26, 2017, 01:52:17 pm
Uhm honestly i think this feature would be appreciated by many people.
I'd eventually help with the coding of the Windows side, but correct me if i'm wrong, i had the impression that SFML libraries aim to be totally cross platform, not allowing to have a platform specific function. If that's the case. And my knowledge of Linux system interaction is little to totally inexistent, hence my help would be meaningless...
But i really whish someone with overall knowledge/time could develop that feature in the library.
Some use examples?
drag images in an image viewer,
drag programs to a shortcut-management custom window,
drag textures in a game supporting custom textures / make character "modding" more user friendly.
But mostly, something which is always hugely undervalued: editors.
Map editors always benefit from drag-drop. May it be a .lua script of events being copied from another map, may it be map's settings exported in an external ini file, up to the simpler and conventional "drag the file type this editor makes in order to open it", which works from any editor, not only games ones.
Title: Re: File drop
Post by: FRex on October 26, 2017, 03:42:14 pm
Windows implementation for drag and drop files (but not text) is a non-issue and available in link above (and before in some old PR too I believe): https://gist.github.com/FRex/3f7b8d1ad1289a2117553ff3702f04af
The real problem is creating a nice API and implementations for X (and Mac..) to actually achieve cross-platformness of that.
There were plenty of use cases already mentioned too (and I'm in totally favor, not that it matters more than anyone else's opinion here).
Title: Re: File drop
Post by: barnack on October 27, 2017, 01:10:25 am
Well yeah being possible is not the issue; but it'd be much more clean to push it as an event within the library rather than having the external call unwrapped
Title: Re: File drop
Post by: FRex on October 27, 2017, 01:14:28 am
The Events are all PODs, that's the problem. We can't just put a vector of strings into the Event. They need to be stored elsewhere (but where?) somehow and then retrievable from there and cleaned up when they're no longer needed...
Title: Re: File drop
Post by: barnack on October 27, 2017, 03:47:25 pm
The Events are all PODs, that's the problem. We can't just put a vector of strings into the Event. They need to be stored elsewhere (but where?) somehow and then retrievable from there and cleaned up when they're no longer needed...
Is "a string pointer" the answer to your question?
Title: Re: File drop
Post by: FRex on October 27, 2017, 03:56:46 pm
And what about pointer invalidation, where is it actually stored, who owns and frees it?
Title: Re: File drop
Post by: Hiura on October 27, 2017, 04:01:11 pm
Note that a PR is already open with exactly the same focus and issues. See my concerns there: https://github.com/SFML/SFML/pull/1222#issuecomment-301183280 (It also has setFileDroppingEnabled, which is an interesting feature.)

Here I suggest an alternative that can deal with pointer invalidation & ownership, did you have a look at it?
Title: Re: File drop
Post by: FRex on October 27, 2017, 04:10:11 pm
I didn't but I thought of 64 bit ID + invalidate on next pop event or some other call too, the only problem it has is that now events are pure data with 0 extras or context needed and that'd change it. It'd feel awkward compared to rest of the API but I'd not mind personally (clearing on pop event might be bad for people storing all events per frame in a buffer though and clearing on display is a bit weird but at least not problematic, dedicated clear method for these is of course out of the question because everyone would forget to call it...).
Title: Re: File drop
Post by: Hiura on October 30, 2017, 03:26:31 pm
Quote
It'd feel awkward compared to rest of the API
That's understandable. Yet, I think for 2.x it's fine. For 3.x we can come up with a better design which leverage post C++-98 facilities. With C++17, variant and smart pointers this is not an issue. This probably can be achieved with C++14 as well.
Title: Re: File drop
Post by: FRex on November 06, 2017, 01:26:05 pm
Perhaps a callback into user code then, if it's set the window accepts dropped files (and passes the paths to it). No memory issues, no action at a distance clean ups, etc.
Title: Re: File drop
Post by: Hiura on November 07, 2017, 10:30:45 am
I'm not convinced callbacks are better here. To start with, callback API stray much further apart from the current API. Callbacks also tend to generate memory complication for the user. If they want callback, they can implement such system on top of a "regular" system, such as the one I suggested.
Title: Re: File drop
Post by: FRex on November 07, 2017, 10:44:19 am
Just for the file drop, not for everything. This feature is very specific and unlike the others already anyway, it's rare and not representable as a POD even. What memory complications do callbacks cause?
Title: Re: File drop
Post by: Laurent on November 07, 2017, 11:01:53 am
Quote
Just for the file drop, not for everything
That's why it would be weird. All other SFML events are reachable by polling the event queue, and this specific one would be delivered through a callback. Although I understand the technical limitations of the Event union, I'm not in favor of introducing this kind of design inconsistency in the API.
Title: Re: File drop
Post by: Hiura on November 07, 2017, 11:02:59 am
I understood you meant only for file drop event, that's why I think the API would be too different from the rest of the Event-related API. C++ is not a managed memory language -- just stating the obvious here -- hence making sure your callback is always callable is not a trivial thing to do: the user has to make sure all references are still valid and so on. It also tends to generate spaghetti code. I think this kind of design should not be forced upon the user unless no other solution is possible at all, or we might lose the S of SFML.
Title: Re: File drop
Post by: FRex on November 07, 2017, 11:30:33 am
If anything, I'd find a callback simple and easy to understand personally. Callback with just a list of dropped items, window reference and user pointer seems like a really good solution that avoids weird lifetime action at a distance implicit agreements ('poll for paths before next display' or something) and doesn't look weird in the API (because it'd look weird to have getPaths() in sf::Window that is only supposed to be used after a certain event is handled, and we already go away from 'pure events' to event + poll window or something so it's not consistent with all the other events).

We already have 'callbacks' in InputStreams, sort of (since function pointer or virtual function is how 'callbacks' are done pre-C++11, save for people who use third party std::function like classes), and 'white sprite because I deleted sf::Texture' is a common beginner problem already that comes from the same mistake, all the caveats that are possible here already apply in SFML. I don't see how a callback instead of polling could generate spaghetti code.
Title: Re: File drop
Post by: Phanoo on January 03, 2018, 04:40:04 pm
I understood you meant only for file drop event, that's why I think the API would be too different from the rest of the Event-related API. C++ is not a managed memory language -- just stating the obvious here -- hence making sure your callback is always callable is not a trivial thing to do: the user has to make sure all references are still valid and so on. It also tends to generate spaghetti code. I think this kind of design should not be forced upon the user unless no other solution is possible at all, or we might lose the S of SFML.

I'd suggest not to worry much about the S of SFML. Too much S = a lib that would not be useful for any serious project. Just avoid getting horribly complicated like the OpenGL api, but we are far, FAR from that. Currently i had more problems fighting against the simplicity of some SFML interfaces rather than their complexity.
Just make a decision and go for it, nobody will ever agree on whether a callback is the best solution or not.
Title: Re: File drop
Post by: eXpl0it3r on August 05, 2021, 03:40:39 pm
Just to relink this here as well, I've started a solution design, so we can collect all the required information in one place with pro/contra arguments and potential API designs.

It's in the wiki, as such if anyone feels like working on this topic, feel free to edit it.

https://github.com/SFML/SFML/wiki/SD:-File-Drop