As a continuation from this thread, I been working on adding drag and drop functionality to allegro. Once again, windows only as I can only test on my personal setup.
MSDN has information about the functions. There are few online examples. I found this website with a link to an all 'C' source to add drop capability to a Win32 app.
An edit box is created that you can drag text from one application to the box.
I even cleaned up the code to remove all extraneous functions that are not needed as a target only app. I also condensed the code into two files (main.c and dropdata.c). I also changed some function names.
The example app, with the changes, compiles, runs, and behaves as expected. It will accept text from a secondary source.
I added this file my allegro project compiles and runs. However, the window does not accept the drop. It won't accept any of the drag/drop functions (drag_enter, drag_over, drop).
Any thoughts?
The example source actually loads a dialog with a simple editbox. Is it the type of window that allegro creates that won't accept drops?
I think this could only be a very rudimentary implimentation. Not even sure this belongs as an addon, because once you get into DnD, very quickly you want all the bells and whistles of a full GUI library. But it would be great example code to donate to the community. -sorry I couldn't find the contents of ALLEGRO_DROP or ALLEGRO_DROP_DATA. ALLEGRO_DROP_DATA can be anything. why not just have a "void *data;" in your ALLEGRO_DROP struct. -since you don't know what is inside of ALLEGRO_DROP_DATA you need a generic way of asking "what am I dragging or what kind of object am I dragging?" like a "const char *drag_id_string;" or a simple "int drag_id;" in the DnD struct. -u should probably keep a copy of the original ALLEGRO_EVENT that began the drag in your DnD struct or else copy all the relavant fields so they are available to the programmer, So when processing your mouse/touch events, you can know if they are related to your current DnD operation and compare to origin (position, time, etc.) and update the screen accordingly. -you need to pass the DnD struct as a parameter in all your callback funcs, otherwise at most you can only perform 1 DnD operation at a time which would be a very severe limitation to impose. worst case: the mouse and each touchscreen finger can all be dragging something simultaneously. -usually drag-and-drop has a configurable movement threshold before kicking in, otherwise it would be too sensitive (especially on high-resolution displays) -HWND is Windows specific. It needs to be generic across all platforms. At worst, pass ALLEGRO_DISPLAY instead good luck
Not even sure this belongs as an addon, because once you get into DnD, very quickly you want all the bells and whistles of a full GUI library.
Only if by bells and whistles you mean clipboard support . I think DnD might be useful in some situations.
Incidentally, just so this doesn't get lost, I suggest, at your convenience, to make a pull request at the github mirror (https://github.com/liballeg/allegro5). It might continue to get ignored (I'm a bit busy and this still seems like it needs some work), but at least it won't get buried in the forums.
Pho75_, I think you're misunderstanding what I'm trying to do. I want to drag data from one application into my application not dragging objects around my screen.
And, I know it needs to be platform independent. These are generic objects and functions. Each platform will need it's own implementation of those objects. I'm working on a windows version.
The callbacks are for testing at the moment. Eventually, when it gets closer to finalization, I plan on instead pushing drag/drop events into a queue.
At the moment, I'm just trying to get a rudimentary text dragging example running. Here is the code I have.
You have functions to create and destroy ALLEGRO_DROP_TARGET but I don't see any public functions that use those.
DanielH,
Apologies, thanks for clarifying. Cool feature to add.
Trent - I originally had this:
void al_set_drop_position_function(bool(*func)(ALLEGRO_DROP_TARGET *pDropTarget, y, int x, int y)); void al_set_drop_target_function(void(*func)(ALLEGRO_DROP_TARGET *pDropTarget, int x, int y, ALLEGRO_DROP_DATA *pDropData));
with a separate function to retrieve the display for that target
ALLEGRO_DISPLAY *al_get_display_from_drop_target(ALLEGRO_DROP_TARGET *pDropTarget);
At the moment, I am simplifying the whole process until I get it working.
UPDATE: I finally have a working prototype. The problem was that the drop target had to be created in the same thread that processes windows messages.
The new code is set up that all you have to do is or another flag when you create a new display (ALLEGRO_ACCEPT_DROP). This will setup the display to generate drag/drop events. Default: any type any where on the screen. There are functions to change this.
The function, al_retrieve_drop_data, needs work. Retrieving text is easy. Converting a HBITMAP to an ALLEGRO_BITMAP is needed.