|
|
| Drag and drop files possible? |
|
Lillebror
Member #11,789
March 2010
|
I've been scouting the forums and the manual for an answer to this question but to no avail. I'd like to be able to drag and drop a file (e.g. txt/bmp) onto an Allegro application window and have the application use the file in some way. Sort of like a terminal argument. I should mention that I'm using Ubuntu, Allegro 4.2.2 and C++. How would you go about this? |
|
Thomas Fjellstrom
Member #476
June 2000
|
You have to use platform specific APIs. In X, you'd have to figure out how to talk the X Drag and Drop protocol. Its not something allegro supports itself. -- |
|
Elverion
Member #6,239
September 2005
|
Very rarely does anybody actually use the drag-and-drop method like that. Honestly, it typically gives the application a very amateurish feel. How often do you see this used in professional software? You can, however, take advantage of drag-and-drop to the actual binary. That is, the user would drag test.txt onto myprogram.exe (assuming Windows in this case, of course), which would pass in "test.txt" to argv. Multiple files are also supported like this. As far as I know, this works the same on every OS that maters. -- |
|
Matthew Leverton
Supreme Loser
January 1999
|
Elverion said: How often do you see this used in professional software? Uhm, ... drag and drop is very natural for GUI elements. However, it is a bad replacement for argv[] functionality. |
|
Elverion
Member #6,239
September 2005
|
Matthew Leverton said: Uhm, ... drag and drop is very natural for GUI elements. For GUI elements within the same application, yes. That's not what he asked, though. -- |
|
gnolam
Member #2,030
March 2002
|
Elverion said: Honestly, it typically gives the application a very amateurish feel. What. Elverion said: For GUI elements within the same application, yes. Drag & drop between file managers and applications is very, very standard - and for good reasons. For example, the former is specifically designed for ease of browsing, and you can keep several windows open at a time (unlike an "Open File" dialog, which you only get one of at a time). -- |
|
Trezker
Member #1,739
December 2001
|
Using a file browser outside your program instead of opening a file dialog in the program may be a very good idea if you're going through a lot of files. I think it would be nice if Allegro 5 had a ALLEGRO_EVENT_DISPLAY_FILE_DROP that gives you the path of files dropped on your window. |
|
Thomas Fjellstrom
Member #476
June 2000
|
Trezker said: I think it would be nice if Allegro 5 had a ALLEGRO_EVENT_DISPLAY_FILE_DROP that gives you the path of files dropped on your window. The hard part is handling all the various types and formats on various systems. D&D code is not a simple prospect. I very much doubt it'll be added to the core. But I can see it being an addon. And it'd probably be more like "Start Drop" "Drop Data" etc, to make it possible to handle D&D like most GUI libraries do (D&D of internal types as well as custom application types from other apps). -- |
|
Oscar Giner
Member #2,207
April 2002
|
Thomas Fjellstrom said: The hard part is handling all the various types and formats on various systems. D&D code is not a simple prospect. I don't know about linux, but on Windows the specific case of allowing dropping files in your app window is very easy. There're just 2 functions to perform the task: First you enable file drop for a window or control with DragAcceptFiles. You process WM_DROPFILES message and get the filenames dropped with DragQueryFile. -- |
|
Thomas Fjellstrom
Member #476
June 2000
|
Files are a bit different. Its not that hard to support. What does get a little more tricky is custom objects from any random app. -- |
|
LennyLen
Member #5,313
December 2004
|
Thomas Fjellstrom said: Files are a bit different. Its not that hard to support. What does get a little more tricky is custom objects from any random app. This thread is about dragging and dropping files.
|
|
Thomas Fjellstrom
Member #476
June 2000
|
LennyLen said: This thread is about dragging and dropping files. But doing it so allegro only supports one, and not the other would be asinine. -- |
|
LennyLen
Member #5,313
December 2004
|
Thomas Fjellstrom said: But doing it so allegro only supports one, and not the other would be asinine. Not really. Dragging and dropping files occurs a lot more often than dragging and dropping objects from within an application. append: As an example, I can drag image files from explorer to both Paint and Paint Shop Pro, but I can't drag an image from either one of those applications to the other.
|
|
Thomas Fjellstrom
Member #476
June 2000
|
I suppose you have a point. -- |
|
|