OK, I felt guilty about the hacky cast in the previous example, so here's the job done "better"...
#include <FL/Fl.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Double_Window.H>
// --------------------------------------------------------------------
// Define and instantiate class for splash screen.
// --------------------------------------------------------------------
class SplashScreen : public Fl_Double_Window {
Fl_Button *btnSplash;
// Action to perform for "Go to instructions" button's callback.
// implemented after instructionsScreen is declared
void cb_btnSplashAux();
// "Go to instructions" button's static callback.
static void cb_btnSplash(Fl_Widget *but, void *data) {
SplashScreen *o = (SplashScreen*)data;
o->cb_btnSplashAux();
}
public:
SplashScreen(int W, int H, const char *L = 0) : Fl_Double_Window(W, H, L) {
btnSplash = new Fl_Button(660, 550, 120, 40, "Go to Instructions");
btnSplash->callback(cb_btnSplash, (void*)this);
}
};
// --------------------------------------------------------------------
// Define and instantiate class for instructions screen.
// --------------------------------------------------------------------
class InstructionsScreen : public Fl_Double_Window {
Fl_Button *btnInstructions;
// Action to perform for "Go to splash" button's callback.
// implemented after splashScreen is declared
void cb_btnInstructionsAux();
// "Go to splash" button's static callback.
static void cb_btnInstructions(Fl_Widget *but, void *data) {
InstructionsScreen *o = (InstructionsScreen*)data;
o->cb_btnInstructionsAux();
}
public:
InstructionsScreen(int W, int H, const char *L = 0) : Fl_Double_Window(W, H, L) {
btnInstructions = new Fl_Button(660, 550, 120, 40, "Go to Splash");
btnInstructions->callback(cb_btnInstructions, (void*)this);
}
};
// Declare the window class instances
SplashScreen splashScreen(800, 600, "Flip Flaps - Splash");
InstructionsScreen instructionsScreen(800, 600, "Flip Flaps - Instructions");
// Now implement the methods that depend on the instance declarations
void SplashScreen::cb_btnSplashAux() {
hide();
instructionsScreen.show();
}
void InstructionsScreen::cb_btnInstructionsAux() {
hide();
splashScreen.show();
}
// ********************************************************************
// Main function.
// ********************************************************************
int main()
{