> I would like to create a callback timer so that I get notified after a
> specified number of seconds/minutes. I would like to, for 
> example, be able
> to display a window/dialog after that. Or, for example, I 
> would like that
> window dialog to die after a specified number of 
> seconds/minutes. Is there
> any such facility in FLTK? A code example will be just wonderful.

OK: here's the example - this shows how to add, repeat and remove timer
callbacks.
I think that covers most of the bases...

--------------------------
// fltk-config --compile timer_demo.cxx
#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Value_Output.H>

#define WIN_DELAY 10.0

static Fl_Double_Window *main_win = (Fl_Double_Window *)0;
static Fl_Double_Window *secnd_win = (Fl_Double_Window *)0;
static Fl_Value_Output *ticker = (Fl_Value_Output*)0;

static int tick = (int)WIN_DELAY;

static void cb_Quit(Fl_Button*, void*) {
    if(main_win) main_win->hide();
    if(secnd_win) secnd_win->hide();
}

static void dismiss_scnd_win(void *) {
    if(secnd_win) secnd_win->hide();
}

static void cancel_timer(void *) {
    if(secnd_win) secnd_win->hide();
    Fl::remove_timeout(dismiss_scnd_win);
    tick = 0;
}

static void delay_show_win(void *) {
    if(secnd_win) {
        secnd_win->show();
        tick = (int)WIN_DELAY;
        // dismiss scnd win after delay
        Fl::add_timeout(WIN_DELAY, dismiss_scnd_win);
    }
}

static void tick_count(void *) {
    if(tick) {
        tick = tick - 1;
        ticker->value(tick);
    }
    Fl::repeat_timeout(1.0, tick_count);
}

int main(int argc, char **argv) {
    main_win = new Fl_Double_Window(100, 100, 439, 321, "Main win");
    main_win->begin();
    Fl_Button* o = new Fl_Button(345, 265, 80, 35, "Quit");
    o->callback((Fl_Callback*)cb_Quit);

    ticker = new Fl_Value_Output(120, 20, 30, 30, "Tick");
    ticker->value(tick);

    main_win->end();

    main_win->show(argc, argv);

    secnd_win = new Fl_Double_Window(550, 100, 439, 321, "Delayed Win");
    secnd_win->begin();
    secnd_win->callback((Fl_Callback*)cancel_timer);
    secnd_win->end();

    // show scnd win after delay
    Fl::add_timeout(WIN_DELAY, delay_show_win);

    // count the ticks down
    Fl::add_timeout(1.0, tick_count);

    return Fl::run();
} // main

/* end of file */

--------------------------


SELEX Galileo Ltd
Registered Office: Sigma House, Christopher Martin Road, Basildon, Essex SS14 
3EL
A company registered in England & Wales.  Company no. 02426132
********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************

_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to