Sparkaround wrote:
> It seemed that this example code make the problem more clear.
> The program will never exit if I press 'a' !

        Oops, my bad -- since your widget derives from Fl_Widget,
        I don't think it responds to FL_ENTER/LEAVE/FOCUS by default,
        so the code needs a small modification to react to the FL_KEYDOWN event
        (see below).

        I don't think this will affect your problem of slowness to respond,
        but it should make it react to the KEYDOWN event..

#include <FL/Fl.H>
#include <FL/Fl_Widget.H>
#include <FL/Fl_Double_Window.H>
#include <FL/fl_draw.H>
#include <stdlib.h>             // exit()

#define DELAY 0.001

class Test_Draw: public Fl_Widget {
public:
    Test_Draw(int x, int y, int w, int h, char *l=0):Fl_Widget(x,y,w,h,l) {
    }
    void draw() {
        static int d=0;
        d++;
        fl_rectf(x(),y(), (int) d%w(), (int)d%h(), d%255,d%255,d%255);
    }
    int handle(int e) {
        int ret = Fl_Widget::handle(e);
        switch (e) {
            case FL_ENTER:      // must handle these to get FL_KEYDOWN
            case FL_LEAVE:
            case FL_FOCUS:
                ret = 1;
                break;
            case FL_KEYDOWN:
                ret = 1;
                printf("KEYDOWN: %d\n", Fl::event_key());
                if ( Fl::event_key('a') ) exit(0);
                break;
        }
        return(ret);
    }
};

Test_Draw *t;
static void update(void *) {
    t->redraw();
    Fl::repeat_timeout(DELAY, update, 0);
}

int main(int argc, char **argv) {
    Fl_Double_Window w(200,200,Fl::w()/2, Fl::h()/2);
    //Fl_Window w(200,200,Fl::w()/2, Fl::h()/2);
    t = new Test_Draw(0,0,w.w(),w.h());
    w.end();
    w.show(argc, argv);
    Fl::add_timeout(DELAY, update, 0);
    return(Fl::run());
}

> I have to stop the program with 'ESC'. It take me about ten seconds to press 
> 'ESC' before the program exited.
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to