Robb Main wrote:
Thanks to everyone with all the great analysis & suggestions.
I will try out as many as I can this evening.
A note on design intent, though - I should have added to the original posting
;-(...
I built the splashWindow class into the constructor for the main window because I wanted to hide implementation
details of this whole messy business from the init code in main(). I planned on building in a progress bar, etc, and
I don't want implementation of all the "bells & whistles" (which are NOT important) cluttering up the
initialization code / sequence for the application (which _IS_ important). I know I can just put my
"important" stuff in a separate function ("important_stuff()"!), but it struck me that there
should be a more clean & eloquent solution, given all the object-oriented magic fltk is based on - hiding details
is the cornerstone.
Anyway - if two separate window classes & required to make the rubber hit the
road, so be it!
Not necessary two classes, I'll append another example to this posting.
I tried to achieve the following:
- no extra classes, only FLTK classes
- variable time to display
- splash-screen clickable by user to close it (optional)
- can be used as an own module (splash_window.cxx / .H)
Maybe this can be combined with your idea to do everything in your main image
constructor, but I'll leave this as an exercise ...
Another option would be to give an Fl_Image as argument for the splash_window()
function. This way the function would be independent of image type and loading
mechanism and could also be used to show an embedded image (pixmap).
BTW. Yuri had the same idea to use Fl::add_timeout() to hide the splash window.
This ensures that the normal FLTK event handling can be done during the splash
window display, and there is no delay as in your wait/check loop.
Enjoy
Albrecht
//
// save this as one file "splash.cxx" or as separate files,
// according to the comments below.
//
// compile with fltk-config --use-images --compile splash.cxx
// (one file version only)
//
// no copyright intended, feel free to use this example code, if you
// like
//
//----------------------------------------------------------------------
// splash_window.H:
#ifndef SPLASH_WINDOW_H
#define SPLASH_WINDOW_H
void splash_window( const char *name, double time=3.0, int clickable=1 );
#endif // SPLASH_WINDOW_H
//----------------------------------------------------------------------
// splash_window.cxx:
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_PNG_Image.H>
#include <FL/Fl_Button.H>
#ifndef SPLASH_WINDOW_H // remove this line, if files are separated
#include "splash_window.H"
#endif // remove this line, if files are separated
// this is called by the timeout or if closed by clicking the button
static void splash_end(void *p) {
((Fl_Window *)p)->hide();
}
// button callback: remove timer and close window
static void splash_button_cb(Fl_Widget *, void *p) {
Fl::remove_timeout(splash_end);
splash_end(p);
}
// window callback: prevent the user from closing the window
// with <ESC>. This is necessary, if "clickable" == 0
static void splash_win_cb(Fl_Widget *, void *p) {
return;
}
/** creates and displays the splash window for \c time seconds.
\param[in] name png image file name
\param[in] time time to wait in seconds
\param[in] clickable 1, if user is allowed to close the window
0, otherwise
*/
void splash_window ( const char *name, double time, int clickable ) {
int X,Y,W,H;
Fl_Group *current_group = Fl_Group::current(); // save current group
Fl_Group::current(0); // reset parent window
Fl_PNG_Image *img = new Fl_PNG_Image(name); // load image file
W = img->w();
H = img->h();
int found = W*H; // 0, if image not found
if (!found) W = H = 300; // set error window size
X = (Fl::w()-W)/2; // center splash window on primary screen
Y = (Fl::h()-H)/2;
Fl_Window *psw = new Fl_Window(X,Y,W,H); // create splash window
psw->border(0); // borderless
psw->callback(splash_win_cb); // prevent close by <ESC>
Fl_Button *b = new Fl_Button(0,0,W,H); // used, if clickable
b->box(FL_FLAT_BOX); // make it flat
if (found)
b->image(img); // set image to be displayed
else {
b->label("Image file not found"); // set error text
b->align(FL_ALIGN_INSIDE|FL_ALIGN_CENTER); // center text
b->labelsize(24); // text size
}
if (clickable) // user may close splash
b->callback(splash_button_cb,psw); // set button callback
// psw->end(); // see next line instead
Fl_Group::current(current_group); // restore current group
psw->show(); // show splash window
Fl::add_timeout(time,splash_end,psw); // start the display timer
// Wait while the splash window is displayed
while (psw->shown()) Fl::wait(0); // wait, until closed
// Cleanup
delete psw;
delete img;
} // show_splash()
//----------------------------------------------------------------------
// main/test program (splash.cxx):
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Button.H>
#ifndef SPLASH_WINDOW_H // remove this line, if files are separated
#include "splash_window.H"
#endif // remove this line, if files are separated
int main(int argc, char ** argv) {
Fl::scheme("plastic");
// show the splash window and wait ...
splash_window("splash.png", 5.0, 1);
// now show the main window
Fl_Window *pWin = new Fl_Window(100, 100, 640, 480, "Main Window");
Fl_Button *btn1 = new Fl_Button( 40, 40, 200, 200, "MAIN WINDOW" );
pWin->end();
pWin->show(argc,argv);
return Fl::run();
}
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk