Forums > Dev

Drag'n'Drop with drag location

Oct 18 2012 | 11:26 pm

I am developing an UI object which, among other things, features drag’n’drop behavior.
Everything is working well however I need to know the x/y location of the drag point as I am dragging – for instance – from the filebrowser upon my object. According to where on my object I drag, different messages have to be sent to it.
In ext_drag.h there is a function prototype that makes me hope what I want to accomplish is possible.

The prototype in question is:

void jdrag_getlocation(t_object *dg, long index, double *xpos, double *ypos);

I tried using it and even though I managed to get it to compile in my code, the result is that xpos and ypos always get 0.0, no matter where I am dragging.

A first sketch of the code is as follows:

long myobj_acceptsdrag_locked(t_myobj *x, t_object *drag, t_object *view)
    long flags = 0;

    // I am interested only in textfiles
    if (jdrag_matchdragrole(drag, gensym("textfile"), flags)) {

        double xpos, ypos;
        jdrag_getlocation(drag, 0, &xpos, &ypos);

        object_post((t_object *)x, "pos %.2f %.2f", xpos, ypos);
        // this always return 0.0 in both xpos and ypos

        return 1;
    return 0;

This code works well in the sense that when I drag a text file upon my object, the object’s border is highlighted and the file recognized, however xpos and ypos always return 0.0.

The patcher object must have a mechanism to report the drag location because I can create objects in a specific location of the patcher simply by dragging and dropping to that location.

What am I doing wrong? How can I know the drag location in my external?

Thanks a lot for any help.

– Luigi

Viewing 1 post (of 1 total)

Forums > Dev