Discussion:
can't get no FL_DRAG event
testalucida
2013-04-13 21:47:57 UTC
Permalink
Hi all,

can someone explain, what's wrong with this code? There's no FL_DRAG event upcoming in the Box class:

#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Group.H>
#include <FL/Fl_Box.H>
#include <stdio.h>

class Box : public Fl_Box {
public:
Box( int x, int y, int w, int h )
: Fl_Box( x, y, w, h )
{
box( FL_UP_BOX );
color( fl_lighter( FL_YELLOW ) );
}
protected:
int handle( int evt ) {
int rc = Fl_Box::handle( evt );

if( evt == FL_DRAG ) {
printf( "dragging\n", evt );
return 1;
}

return rc;
}
};

int main() {
Fl_Double_Window *pWin = new Fl_Double_Window( 500, 500, "Dragging" );
Fl_Group *pGrp = new Fl_Group( 0, 0, 500, 500 );
pGrp->box( FL_FLAT_BOX );
pGrp->color( fl_lighter( FL_GRAY ) );
pGrp->begin();
Box *pBox = new Box( 50, 50, 200, 25 );
pGrp->end();
pWin->end();
pWin->resizable( pWin );
pWin->show();

return Fl::run();
}

Thanks & bye
testalucida
Greg Ercolano
2013-04-13 22:12:14 UTC
Permalink
The docs for the FL_DRAG event will tell you why:
http://fltk.org/doc-1.3/events.html

Under the section "Mouse Events":

----
FL_DRAG
[..]
In order to receive FL_DRAG events, the widget must return non-zero
when handling FL_PUSH.
----

So add this one line to your handle() method:

if (evt == FL_PUSH) rc = 1;

Or, just rewrite the handle() method with a switch(), ie:

int handle(int evt) {
int rc = Fl_Box::handle(evt);
switch (evt) {
case FL_PUSH: rc=1; break
case FL_DRAG: printf("Dragging..\n"); rc=1; break;
}
return rc;
}
testalucida
2013-04-14 05:57:36 UTC
Permalink
thank you.
Post by Greg Ercolano
http://fltk.org/doc-1.3/events.html
----
FL_DRAG
[..]
In order to receive FL_DRAG events, the widget must return non-zero
when handling FL_PUSH.
----
if (evt == FL_PUSH) rc = 1;
int handle(int evt) {
int rc = Fl_Box::handle(evt);
switch (evt) {
case FL_PUSH: rc=1; break
case FL_DRAG: printf("Dragging..\n"); rc=1; break;
}
return rc;
}
Loading...