dirac wrote:
> Hi FLTKers,
> I'm writing a little app where a series of buttons "do something" when the 
> corresponding key is pressed (and when is released too), displaying a 
> graphical status when the button is on (e.g. a black square inside it); 'q' 
> handles the first button, 'w' the second, 'e' the third and so on.
> First of all I have extended Fl_Button providing the following methods:
> 
> -----------------------------------------------------------------------
> void myButton::draw() {
>   fl_draw_box(FL_BORDER_BOX, x(), y(), w(), h(), FL_BACKGROUND_COLOR);
> }
> void myButton::on() {
>   fl_rectf(x()+5, y()+5, w()-10, h()-10, 0, 0, 0);
> }
> void myButton::off() {
>   fl_rectf(x()+5, y()+5, w()-10, h()-10, FL_BACKGROUND_COLOR);
> }
> -----------------------------------------------------------------------
> 
> Then I've grouped the buttons into a Fl_Group overriding handle(). The code 
> is very minimal: if FL_KEYDOWN case, the button is turned on calling on() 
> method (off() for KEYUP), paying attention to keep focus active with:
> 
> -----------------------------------------------------------------------
> case FL_UNFOCUS:
>   this->take_focus();
>   return 1;
> -----------------------------------------------------------------------
> 
> Sadly, fl_rectf() into myButton::on() stops drawing the black square if I 
> click another widget outside the Fl_Group and I don't understand why... Maybe 
> a lose of focus? But i'm forcing it into FL_UNFOCUS! Is the drawing procedure 
> completely wrong?
> Thank you in advance for any positive suggestion (and forgive my english :-)).

I do not think I have understood your question, but:

I suspect that you have not understood how the drawing process in fltk 
is done - in particular, you never call the draw method directly 
yourself, you always let the fltk runtime do that for you.

Also, you can not (in general) draw into a widget outside the scope of 
its own draw method.

You need to read the docs, and check the examples in the test folder - 
in particular the keyboard example would be relevant here I think.

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

Reply via email to