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,
Robb.

<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>

// for usleep used in main()
#include <unistd.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(x(),y());            // 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();
//              flush();                    // give fltk some cpu to update the 
screen
//              show();
        }
};

class myWindow : public Fl_Window {
        splashWindow *pSplashWin;
public:
        void show() {
                Fl_Window::show();                  // Show main window widget 
first
                if (pSplashWin) {
                        // Cleanup
                        remove( pSplashWin );           // remove splash window
                        delete( pSplashWin );           // deallocate it
                        pSplashWin = 0;
                }
        } // show()

// Constructor
        myWindow(int X, int Y, int W, int H) : Fl_Window(X,Y,W,H) {
                splashWindow *pTmp;
                pSplashWin = 0;
                // Create Splash Screen child window
                pTmp = new splashWindow( X, Y, W, H, "My Splash", 
"./splash-bg3.png" );
//              Fl::flush();
//              Fl::check();                    // give fltk some cpu to update 
the screen
                // Add a button to the main screen, so we know when it's 
displayed.
                Fl_Button *btn1 = new Fl_Button(40, 40, 200, 200, "MAIN WINDOW" 
);
                end();
                show();
                Fl::check();                    // give fltk some cpu to update 
the screen
//              Fl::flush();
        pSplashWin = pTmp;
        }
};

int main(int argc, char ** argv) {

        fl_register_images();
        Fl::scheme("plastic");
        Fl_Window *pWin = new myWindow(0, 0, 640, 480);
        // wait while splash is displayed
        /*
                There is a noticeable delay before the PNG image appears, 
because the
                picture is NOT rendered by the first itteration of the loop 
below.
                The picture is rendered when Fl::check() is called.
                I tried numerous different things (see constructor above), in 
order to
                "flush" the PNG image to the display immediately, but nothing 
worked.
        */
        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();
}
------------------------
<end code>
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to