On 17.08.2011 17:21, Emer Rodriguez wrote:
> Good afternoon,
>
> I want to have a Fl_Chart updated every time the data is added or replaced. I
> tried to do a test using Ercolano's example but I did not succeed. By the
> way, I want to thank Greg for the tutorial videos and the code examples.
> Great job!
>
> Here goes my try:
-- stripped not commented code --
> int main() {
> Fl_Window *win = new Fl_Window(1000, 480);
> Fl_Chart *chart = new Fl_Chart(20, 20, win->w()-40, win->h()-40,
> "Chart");
...
> win->show();
> chart->show();
>
> for(int i=1;i<=30;i++)
> {
> static char c[10];
> sprintf(c,"%i",i);
> chart->replace(i,100,c,78);
> Sleep(1000); //Simulate updates
> }
> return(Fl::run());
> }
You can't use Sleep to wait during any FLTK loops, since this
doesn't allow FLTK to do its job (updating the widgets). In your
demo you do all updating even before you run the FLTK event queue.
That's not the way you should do it. The proper way is to use
Fl::add_timeout() and Fl::repeat_timeout() and to update the
widget in their callbacks (only once for each call), and to call
chart->redraw() before leaving the callback. This ought to do
what you need. I'm sure others (including Greg) will chime in
and show you the correct way if you need (sorry, I can't do it
right now).
But for a quick HACK(!!!) you could try to replace the loop
with:
for(int i=1;i<=30;i++)
{
static char c[10];
sprintf(c,"%i",i);
chart->replace(i,100,c,78);
chart->redraw(); // ADDED
Fl::check(); // ADDED
Sleep(1000); //Simulate updates
}
This "works" in the way that it does what you want before
starting the FLTK loop, but that's not the recommended way
for a real FLTK app. (tested and working).
Albrecht
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk