> 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
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk