> > In the code below, the PNG image I'm loading is not displayed immediately. 
> > I've been unable to overcome the delay before it is displayed, although I'm 
> > told the image should be ready to display immediately after loading (i.e., 
> > the constructor returns). What am I doing wrong?
> >
> > Thanks,
> >     for (int i=0; i<3; i++ ) {
> >             usleep( 1000000 );
> >             Fl::check();
> >     }
> >     // Now show the main window - this will remove the splash screen
> >     pWin->show();
> >     return Fl::run();
> > }
>
> You window not redraw your self 'cause usleep stop code execution.
>
> one possible way is use add_timeout for hiding slash window. and use 
> different thread for doing hard job while splash is shown.
>
> ---------------------code------------------
> #include <FL/Fl.H>
> #include <FL/Fl_Shared_Image.H>
> #include <FL/Fl_Single_Window.H>
> #include <FL/Fl_PNG_Image.H>
> #include <FL/Fl_Button.H>
> #include <FL/fl_draw.H>
>
> class splashWindow : public Fl_Window {
>     Fl_PNG_Image *pBGImage;
> protected:
>     virtual void draw() {
>         Fl_Window::draw(); // Draw window widget first
>         if ( pBGImage )
>       pBGImage->draw(0,0); // draw PNG image over the above
>     }
> public:
>     // Constructor
>     splashWindow(int X, int Y, int W, int H, char *pszTitle, char 
> *pszBGImage) : Fl_Window(X,Y,W,H) {
>         pBGImage = new Fl_PNG_Image( pszBGImage );
>         border(0);
>         end();
>     }
> };
>
> class myWindow : public Fl_Window {
> public:
>     myWindow(int X, int Y, int W, int H) : Fl_Window(X,Y,W,H) {
>         Fl_Button *btn1 = new Fl_Button(40, 40, 200, 200, "MAIN WINDOW" );
>     }
> };
>
> splashWindow *pSplashWin;
>
> // callback for hiding splash window
> void callback(void*){
>   if(pSplashWin)pSplashWin->hide();
> }
>
> int main(int argc, char ** argv) {
>     int a(10),b(10),c(10);
>     fl_register_images();
>     Fl::scheme("plastic");
>     pSplashWin = new splashWindow(200,200,640,480, "My Splash", "./03.png" 
> );//change name
>     pSplashWin->end();
>     pSplashWin->show(argc,argv);
>     Fl_Window *pWin = new myWindow(200, 200, 640, 480);
>     Fl::add_timeout(5.0, callback);//hide splash in callback
> #if 1    // simple call Fl::run()
>     Fl::run();//wil return when pSplashWin will be hidden
> #else   // or use Fl::run() like code
>     while(pSplashWin->shown()){
>       Fl::wait(0);
>       // uncoment for cause redraw problem or insert sleep
>       //for(long long i=0;i<900000000;++i){a*=b;a-=c;}
>     }
> #endif
>     pWin->show(argc,argv);
>     return Fl::run();
> }
> ------------------code-------------------
> change #if 1 to #if 0 and uncoment for and you can see your problem again.
>
> Yury P. Fedorchenko

Thanks for this code, Yury.
I tried it, and it works as advertised.
However, given the clarification I posted sometime after you posted this, I 
won't go this route - the mainline code is now too cluttered with 
implementation of the "eye-candy splash screen" code, and I need to be doing 
things while the splash screen is displayed, so I'd like to avoid having to 
constantly yield to background fltk processing to ensure my splash screen gets 
displayed sometime after I expected it to be there.

Your comment on threads is of interest, and I may eventually use it in this 
project - but only because I'll be using threads anyway. Other than that, 
adding threading calls just to display eye-candy would again fall into the 
realm of using a slege-hammer on a fly.

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

Reply via email to