John Hoare schrieb:
> Perhaps If I give you an example of how my library is used, you (or
> someone) can give me a better way to achieve this.
>
> Picture* pic = robot.takePicture("color");
> pic->show(); //blocks until image is closed
>
> This code should take a picture from the robot, and then open a display
> window, and display the picture. From my understanding, this should be
> easy: open a window, and then call Fl::run(), which will return once the
> image is closed.

For applications working in background and from time to time popping up 
a window, I would not use Fl::run(), but something like that:

volatile bool apprun= true;
Fl_Pic_Window   PW;     // Class that shows window with pic
robot R;
while (Fl::check() || apprun)
{
        Picture* pic = R.takePicture("color");
        if (pic)        PW.show(Pic);
        apprun= R.busy();
        if (PW.visible())       Fl::wait(0.1);
        else Sleep(100);
}
return 0;

This is a mainloop, which runs while a Fl_Window is open (Fl::check()== 
true) and a background process is working. You can access apprun also by 
threads (volatile) and you can open and close as much windows as you 
like, while the loop is running. For example not opening a single global 
defined window, but a new window for every new pic.

The part "Fl::wait(0.1)/Sleep(100)" prevents the loop from taking 100% 
CPU load. It is not necessary to use Fl::wait() and check for visible 
windows, when Fl::check() is called fast enough. If you only would use 
"Sleep(100)" (milliseconds! ;o) the Fl_Window should react fast enought 
for fluid feeling. This means, you can do background operations, without 
using a thread (but don't forget to Sleep, also Sleep(0) helps to reduce 
CPU load). You also should try to rise this time, to find out, when 
windows start to be slow (for example when moving them around). Even 0.5 
s could be a sufficient interval for displays.

HTH,

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

Reply via email to