> > Is there a method to change the color to focused widget?
> > I tried to include some instructions about the color in the callback,
> > but the color changing doesn't work.
>
> This is a separate problem, really. The easiest way to do this is probably to 
> make your own widget, subclassed from Fl_Slider or similar, and in the handle 
> method change the widget colour for FL_ENTER and FL_LEAVE events.
>


Following Ivano's query, I thought I'd put together a simple demo of changing 
the slider widget colour in response to focus changing.

Using 1.1.9, this turned out to be trickier than I had initially expected: my 
sub-classed Fl_Slider widget doesn't receive FL_FOCUS events for mouse clicks, 
so I had to handle that event via the callback method, but with the callback 
when() set to FL_WHEN_RELEASE_ALWAYS - which I actually knew, in retrospect, as 
I've done this before... Oh well, worked example below, in case anyone finds it 
useful!

--
// demo of handling enter/leave events for sliders
// fltk-config --compile slider-focus.cxx
#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Slider.H>
#include <FL/Fl_Button.H>

static Fl_Double_Window *main_win=(Fl_Double_Window *)0;
static Fl_Button *exit_bt=(Fl_Button *)0;

class mod_slider : public Fl_Slider {
public:
        mod_slider(int X, int Y, int W, int H, const char *L) :
        Fl_Slider(X,Y,W,H,L){};

        int handle(int ev);
};

int mod_slider::handle(int ev) {
        int res = Fl_Slider::handle(ev);
        switch(ev){
        case FL_FOCUS:
                selection_color(FL_YELLOW);
                break;

        case FL_UNFOCUS:
                selection_color(FL_BLUE);
                break;

        default:
                break;
        }

        return res;
} // handle

static mod_slider *slider1=(mod_slider *)0;
static mod_slider *slider2=(mod_slider *)0;
static mod_slider *slider3=(mod_slider *)0;
static mod_slider *slider4=(mod_slider *)0;

static void cb_slider(mod_slider *w, void*) {
        w->selection_color(FL_YELLOW);
        w->redraw();
}

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

int main(int argc, char **argv) {
        main_win = new Fl_Double_Window(600, 320, "Slider Test Window");
        main_win->begin();

        slider1 = new mod_slider(25, 24, 48, 251, "Chan 1");
        slider1->type(4);
        slider1->selection_color(FL_BLUE);
        slider1->callback((Fl_Callback*)cb_slider);
        slider1->when(FL_WHEN_RELEASE_ALWAYS);

        slider2 = new mod_slider(151, 24, 48, 251, "Chan 2");
        slider2->type(4);
        slider2->selection_color(FL_BLUE);
        slider2->callback((Fl_Callback*)cb_slider);
        slider2->when(FL_WHEN_RELEASE_ALWAYS);

        slider3 = new mod_slider(278, 24, 48, 251, "Chan 3");
        slider3->type(4);
        slider3->selection_color(FL_BLUE);
        slider3->callback((Fl_Callback*)cb_slider);
        slider3->when(FL_WHEN_RELEASE_ALWAYS);

        slider4 = new mod_slider(405, 24, 48, 251, "Chan 4");
        slider4->type(4);
        slider4->selection_color(FL_BLUE);
        slider4->callback((Fl_Callback*)cb_slider);
        slider4->when(FL_WHEN_RELEASE_ALWAYS);

        exit_bt = new Fl_Button(500, 256, 70, 29, "Exit");
        exit_bt->box(FL_THIN_UP_BOX);
        exit_bt->callback((Fl_Callback*)cb_exit_bt);

        main_win->end();
        main_win->show(argc, argv);
        return Fl::run();
} // main
/* end of file */

--
Ian

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

Reply via email to