Subclassing a plastic Fl_Button

12 views
Skip to first unread message

Gonzalo Garramuño

unread,
Aug 11, 2021, 8:00:19 PM8/11/21
to fltkg...@googlegroups.com
I would like to subclass a plastic Fl_Button and change it to a flat
drawing before getting pressed.  I would like to set it up in the
constructor.  However, the following does not work:


    Button::Button( int X, int Y, int W, int H, const char* L ) :
        Fl_Button( X, Y, W, H, L )
    {
        box( FL_FLAT_BOX ); // here it does not work
    }

    void Button::draw()
    {
        if (type() == FL_HIDDEN_BUTTON) return;
        Fl_Color col = value() ? selection_color() : color();
        box( FL_FLAT_BOX );  // here it works
        draw_box(value() ? (down_box()?down_box():fl_down(box())) :
box(), col);
        draw_backdrop();
        if (labeltype() == FL_NORMAL_LABEL && value()) {
            Fl_Color c = labelcolor();
            labelcolor(fl_contrast(c, col));
            draw_label();
            labelcolor(c);
        } else draw_label();
        if (Fl::focus() == this) draw_focus();
    }

Can someone explain me why and how do I go around it?

Greg Ercolano

unread,
Aug 11, 2021, 8:19:30 PM8/11/21
to fltkg...@googlegroups.com

On 8/11/21 5:00 PM, Gonzalo Garramuño wrote:

I would like to subclass a plastic Fl_Button and change it to a flat drawing
before getting pressed.

    I'm assuming when you say 'plastic button' you mean one of the FL_PLASTIC_XXX_BOX
    values, and not Fl::scheme("plastic"), or you'd have described it as a plastic scheme
    with a button.

    So you want it to be an FL_FLAT_BOX before being pressed, then plastic
    while pressed? If so I'd think that'd be in the ctor:

      box(FL_FLAT_BOX);
      down_box(FL_PLASTIC_THIN_UP_BOX);

    Or if you want it to switch from being flat to a plastic button /after/
    being pressed (like a toggle), then I suppose in the ctor:

        box(FL_FLAT_BOX);

    ..and in the callback:

        down_box(FL_PLASTIC_THIN_UP_BOX);

    ..to cause it to switch.
    But I'm probably not understanding quite what you want..


Gonzalo Garramuño

unread,
Aug 11, 2021, 8:26:48 PM8/11/21
to fltkg...@googlegroups.com

El 11/8/21 a las 21:19, Greg Ercolano escribió:
>
> On 8/11/21 5:00 PM, Gonzalo Garramuño wrote:
>
>> I would like to subclass a plastic Fl_Button and change it to a flat
>> drawing
>> before getting pressed.
>
>     I'm assuming when you say 'plastic button' you mean one of the
> FL_PLASTIC_XXX_BOX
>     values, and not Fl::scheme("plastic"), or you'd have described it
> as a plastic scheme
>     with a button.
>
No, you got it backwards.  I have an Fl::scheme( "plastic" ) and I want
one of the buttons to be flat.  How do I go about it?


Gmail Ercolano

unread,
Aug 11, 2021, 8:56:47 PM8/11/21
to fltkg...@googlegroups.com

On 8/11/21 5:26 PM, Gonzalo Garramuño wrote:

No, you got it backwards.  I have an Fl::scheme( "plastic" ) and I want one of the buttons to be flat.
How do I go about it?

    Hmm, if I set the Fl::scheme("plastic") and create two buttons, and set one of them
    to box(FL_FLAT_BOX), I get a flat button, so it's kinda unclear what you want instead:



#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Button.H>
int main()
{
    Fl::scheme("plastic");
    Fl_Double_Window *win = new Fl_Double_Window(800,800,"Test");
    Fl_Button *b1 = new Fl_Button(10,10,200,30,"Normal Button");
    Fl_Button *b2 = new Fl_Button(10,50,200,30,"Flat Button");
    b2->box(FL_FLAT_BOX);
    win->end();
    win->show();
    return Fl::run();
}

Gonzalo Garramuño

unread,
Aug 11, 2021, 8:58:06 PM8/11/21
to fltkg...@googlegroups.com

El 11/8/21 a las 21:19, Greg Ercolano escribió:
>
> On 8/11/21 5:00 PM, Gonzalo Garramuño wrote:
>
>> I would like to subclass a plastic Fl_Button and change it to a flat
>> drawing
>> before getting pressed.
Never mind.  I figured it out.  The Fl::scheme("plastic") was getting
called after the widget was created.

Greg Ercolano

unread,
Aug 11, 2021, 9:07:12 PM8/11/21
to fltkg...@googlegroups.com

On 8/11/21 5:58 PM, Gonzalo Garramuño wrote:

Never mind.  I figured it out.  The Fl::scheme("plastic") was getting called after the widget was created.

    Yes, you'll want to set the scheme really far up in main(), almost first thing.
    The only FLTK thing I might call before setting the scheme is fl_register_images().
Reply all
Reply to author
Forward
0 new messages