You could use fltk build-in capabilities by using either
Fl::add_timeout() or Fl::repeat_timeout() functions.
Lets say you have a widget w and you want to update its label every 0.1
second. Write a function like

void timeout_callback(void * widget){
 static time_t last_time= 0
 char buffer[128];
 time_t new_time = time(0) ;
 if(new_time!= last_time){ // change
   last_time = new_time;
   struct tm * ts = localtime(&new_time);
   strftime(buffer, sizeof(bufffer), "%a %Y-%m-%d %H:%M:%S %Z", ts);
   Fl_Widget * w = (Fl_Widget *)w;
   w->copy_label(buffer);
   w->redraw_label();
 }
 Fl::add_timeout(0.1, &timeout_callback, widget);
}

and assign callback for the first time by

  Fl::add_timeout(0, &timeout_callback, widget);

If you destroy the widget before program ends be sure to remove the timeout

  Fl::remove_timeout(&timeout_callback, widget);

otherwise your program would crash on the next timeout call.

R.



Moslem Kazemi wrote:
> Hi fltkers,
> 
> I am a newbie! :) and am trying to see if fltk would suit my application 
> needs. I would appreciate your help re. the following question.
> 
> I try to pose my question through a simple example as follows:
> Let's say I have a fltk window with a text output widget and a member 
> variable which itself is a class, say a timer. I would like to see what is 
> the proper way that I could access/update the value of the text output widget 
> from within the methods of the class timer?
> Should I pass a pointer of the text widget to the timer class? Is there way 
> that I could post a message from within the methods in timer class to the 
> main window and ask to update the widget value?
> 
> Thanks,
> --Moslem.
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to