Jeremy Henty wrote:
>> I'm still seeing
>> no ENTER events and a LEAVE event whenever the pointer leaves the box
>> *or* the window.
To get LEAVE events, you have to return(1) from the ENTER
event, indicating your handler()'s interest in getting them.
Quote the docs on event handling:
http://fltk.org/documentation.php/doc-1.1/events.html#7_3
FL_ENTER
The mouse has been moved to point at this widget. This can be used
for highlighting feedback. If a widget wants to highlight or otherwise
track the mouse, it indicates this *by returning non-zero* from its
handle() method. It then becomes the Fl::belowmouse() widget and will
receive FL_MOVE and FL_LEAVE events.
This is to prevent FLTK from having to send FL_LEAVE events
to widgets that dont need them.
So rewriting your app the way I generally prefer to see
event handling (see ***'s):
#include <stdio.h>
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Box.H>
class Box : public Fl_Box {
public:
Box(int x, int y, int w, int h) :
Fl_Box(x,y,w,h) {
box(FL_FLAT_BOX);
color(FL_WHITE);
}
virtual int handle(int);
};
int Box::handle(int ev) {
int ret = Fl_Box::handle(ev); // ***
switch (ev) {
case FL_ENTER:
printf("ENTER; ev = %d ; Fl::event() = %d ;\n",
ev, Fl::event());
ret = 1; // ***
break;
case FL_LEAVE:
printf("LEAVE\n");
break;
}
return(ret); // ***
}
int main(int argc, char **argv) {
Fl_Window *window = new Fl_Window(300,300,"Enter/Leave");
window->begin();
new Box(50,50,200,200);
window->end();
window->show(argc,argv);
return Fl::run();
}
You can code it however you want, as long as you're
not eclipsing events from the base class's handle()
method (unless you have a good reason to).
I usually find myself coding like the above, calling
the base class's handle() at the top, keeping the return
value, so that my case statements can set the return value
to 1 if needed.
> The value returned by Fl::event() is *not*
> the same as the value passed to handle() (!!!).
I'm not sure if Fl::event() is supposed to be valid
in this context, since the argument passed to handle()
is the only valid event number.
handle()ers sometimes call each other with different
event values, so Fl::event() can't be involved.
It's only in other contexts, IIRC, such as widget callbacks
you should need Fl::event() to get the event number being
processed, as there usually is no other way.
(Widget callbacks aren't passed event info in the argument list,
so the Fl:: methods are the only way)
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk