Hello, I tried and crated a cusom widget, using the sample found here:
http://seriss.com/people/erco/fltk/#SliderInput The goal is to build a «connector». It's a box, which would have little «anchors» on it (anchors are represent with little buttons). In the (i hope) near future, my connectors will be linked using anchors (and a line between the links). For the moment, i'm stuck with the buttons callback. I've defined it in the constructor, but it is never called, so the connector "event" function always drag the connector. Look: button's callback is defined in connector constructor, but it's never called. Thank you for having a look at this. /* g++ -o connector.{elf,cpp} $(fltk-config --cxxflags --ldflags) -I/usr/include/FL */ #include <stdio.h> #include <Fl.H> #include <Fl_Double_Window.H> #include <Fl_Box.H> #include <Fl_Button.H> #include <Fl_Group.H> Fl_Double_Window *G_window = 0; class Connector : public Fl_Group { private: Fl_Box *box ; Fl_Button *btn ; int btn_is_pushed ; int handle(int e) { int ret = 1; if (!btn_is_pushed) { switch ( e ) { static int pos_org[2] = { 0, 0 }; case FL_PUSH: pos_org[0] = x() - Fl::event_x(); pos_org[1] = y() - Fl::event_y(); break; case FL_RELEASE: //G_window->redraw(); break; case FL_DRAG: position(pos_org[0]+Fl::event_x(), pos_org[1]+Fl::event_y()); G_window->redraw(); break; default: ret = 0; } return ret; } } //it seems we never enter this function. static void CB_btn(Fl_Widget *w, void *data) { int *d = (int *) data; Connector *connector = dynamic_cast<Connector *>(w); switch (*d) { case FL_PUSH: printf("pushed!"); connector->btn_is_pushed=1; break; case FL_RELEASE: printf("released!"); connector->btn_is_pushed=0; break; default: printf("default!"); break; } } public: Connector (int x,int y,int w,int h,const char *l=0) : Fl_Group(x,y,w,h,l) { box = new Fl_Box(x,y,w,h); box->box (FL_BORDER_BOX); box->color ((Fl_Color) 0xccddee00); btn=new Fl_Button(this->x()+10, this->y()+5, 10,10); btn->callback(CB_btn, (void*)btn /*this*/); // btn->when(FL_WHEN_ENTER_KEY|FL_WHEN_NOT_CHANGED); end(); //fin du groupe } }; int main(void) { G_window = new Fl_Double_Window(500, 400); G_window->begin(); Connector connect(10,10,150,40); G_window->end(); G_window->show(); Fl::run(); return 0; } _______________________________________________ fltk mailing list [email protected] http://lists.easysw.com/mailman/listinfo/fltk

