So I have this class which is supposed to contain my window and all the functions that I'm going to use as callbacks.
#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Group.H>
#include <FL/Fl_Value_Input.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Slider.H>
#include <FL/Fl_Check_Button.H>
#include "world.hpp"
class Controller
{
private:
Fl_Double_Window *window;
public:
int process(int argc, char **argv);
void nextStep(Fl_Widget *widget, void *data);
void togglePlay(Fl_Widget *widget, void *data);
void newWorld(Fl_Widget *widget, void *data);
void randFill(Fl_Widget *widget, void *data);
void togglePreviz(Fl_Widget *widget, void *data);
void updateSpeed(Fl_Widget *widget, void *data);
Fl_Double_Window* make_window();
};
Now in the implementation of "make_window()" (which was originally created using FLUID) I want to assign my functions to the appropriate widgets.
Fl_Double_Window* Controller::make_window()
{
//Generated with FLUID designer
Fl_Double_Window* w;
{ Fl_Double_Window* o = new Fl_Double_Window(1200, 900);
w = o; if (w) {/* empty */}
o->color(FL_FOREGROUND_COLOR);
{ World* o = new World(25, 25, 800, 800);
o->box(FL_DOWN_BOX);
o->color((Fl_Color)30);
o->end();
} // Fl_Group* o
{ Fl_Group* o = new Fl_Group(850, 25, 300, 805);
o->box(FL_DOWN_BOX);
o->color(FL_INACTIVE_COLOR);
{ Fl_Value_Input* o = new Fl_Value_Input(875, 50, 100, 24, "Cellules");
o->align(Fl_Align(FL_ALIGN_RIGHT));
} // Fl_Value_Input* o
{ Fl_Button* o = new Fl_Button(900, 100, 200, 40, "Creation Monde");
o->box(FL_ROUNDED_BOX);
o->callback(newWorld);
} // Fl_Button* o
{ Fl_Slider* o = new Fl_Slider(FL_HOR_NICE_SLIDER, 900, 175, 200, 25, "Vitesse");
o->callback(updateSpeed);
o->align(Fl_Align(FL_ALIGN_TOP));
o->bounds(0.0, 1.0);
} // Fl_Slider* o
{ Fl_Check_Button* o = new Fl_Check_Button(875, 225, 64, 20, "Mode PreViz");
o->callback(togglePreviz);
o->down_box(FL_DOWN_BOX);
} // Fl_Check_Button* o
{ Fl_Value_Input* o = new Fl_Value_Input(875, 300, 100, 24, "Taux");
o->align(Fl_Align(FL_ALIGN_RIGHT));
} // Fl_Value_Input* o
{ Fl_Button* o = new Fl_Button(900, 350, 200, 40, "Remplissage Aleatoire");
o->callback(randFill);
o->box(FL_ROUNDED_BOX);
} // Fl_Button* o
{ Fl_Button* o = new Fl_Button(950, 500, 100, 100, "@>");
o->callback(togglePlay);
o->box(FL_ROUNDED_BOX);
o->labelsize(50);
} // Fl_Button* o
{ Fl_Button* o = new Fl_Button(950, 650, 100, 100, "@->");
o->callback(nextStep);
o->box(FL_ROUNDED_BOX);
o->labelsize(50);
} // Fl_Button* o
o->end();
} // Fl_Group* o
o->end();
} // Fl_Double_Window* o
return w;
}
The problem is that at every line where I call "o->callback(myFunctionPointer);" I get an error telling me that
no instance of overloaded function "Fl_Button::callback" matches the argument list -- argument types are: (void (Fl_Widget *widget, void *data)) -- object type is: Fl_Button
From what I've researched it should mean that I don't send the appropriate number or type of parameters in my "callback" function. After digging in the documentation, I've found that the "callback" function expects at least a pointer to a Fl_callback object but I've seen examples of code where people just send a function pointer and it seems to work just fine on their code.
Why won't FLTK accept my pointers ? Have I declared them wrong ?
Any help would be appreciated
Thanks
this
in my functions and your "ad-hock callback management" is a bit too complicated for me (I'm not a complete beginner but I'm certainly not quite experienced yet). Do you have any other Idea on how I could manage my code to make it work ? – Hazard