On 16 Oct 2012, at 20:36, Doug Parks wrote:

> I decided to make a custom button class so that I could reduce the amount of 
> code in my project.  I was able to create the button but when I click on the 
> button, the callback isn't being called.  Before I made the custom button 
> class the button worked fine.  Below is an excerpt from my code.
> 
> class newButton : public Fl_Button
> {
>   Fl_Button *myButton;
>   public:
>   newButton(int x, int y, int w, int h, const char * l = 0):Fl_Button(x, y, 
> w, h, l)
> {
>   myButton = new Fl_Button(x, y, w, h, l);
>   myButton->box(FL_GTK_ROUND_UP_BOX);
>   myButton->color((Fl_Color)24);
>   myButton->selection_color((Fl_Color)24);
>   myButton->labelcolor(FL_WHITE);
>   myButton->labelfont(1);
> }
> };
> 
> newButton accept(687, 652, 75, 25, "Accept");
> accept.callback(accept_cb);
> 
> The callback is supposed to open a new window and close the current window 
> but it isn't doing anything at the moment.
> 
> Any help would be appreciated, thanks.


Um, I may be missing something important, but why have you created a new button 
inside your derived button class?

In general, that is not needed... 

Here's a way to do this; perhaps this is what you meant?

---------
// fltk-config --compile button-demo.cxx

#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Button.H>

class newButton : public Fl_Button
{

public:
  newButton(int x, int y, int w, int h, const char * l = 0):Fl_Button(x, y, w, 
h, l)
  {
    box(FL_GTK_ROUND_UP_BOX);
    color((Fl_Color)24);
    selection_color((Fl_Color)24);
    labelcolor(FL_WHITE);
    labelfont(1);
  }
};

static Fl_Double_Window *main_win = (Fl_Double_Window *)0;

static void cb_Quit(Fl_Button*, void*) {
  if(main_win) main_win->hide();
}


int main(int argc, char **argv) {
  main_win = new Fl_Double_Window(100, 100, 439, 321, "Main win");
  main_win->begin();

  newButton* myButton = new newButton(345, 265, 80, 35, "Quit");
  myButton->callback((Fl_Callback*)cb_Quit);
  
  main_win->end();
  
  main_win->show(argc, argv);
  
  return Fl::run();
} // main

/* end of file */
---------






_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to