Marc R.J. Brevoort wrote:
> In the end I rolled my own. Here's the code.

> void Fl_Image_Button::draw() {
>       if (value()==0)
>       {
>               if (upimage!=NULL) {
>                       this->image(upimage);
>               }
>       } else {
>               if (this->value()==1)
>               {
>                       if (downimage!=NULL) {
>                               this->image(downimage);
>                       }
>               }
>       }
>       Fl_Button::draw();
> }

        Another approach would be to have the button's image()
        be modified on the handle() events, which is I think how
        Fl_Button internally operates. (I usually try to follow
        FLTK's own internal operation for consistency.)

        Here's an example complete with Mac Aqua-esque button images.
        Here, the single MyButton class can be used for any two up/down
        images without modifying the class; the images are set by the
        updown() method.

        The button is automatically sized to match the image's size.

        This should be compatible with Fluid too, so you can make
        regular buttons in fluid, but set the class to MyButton,
        and use the 'Extra Code' to set the updown() images.
        When you run the app, you'll see the actual button images.

        You might even be able to set the 'image:' in fluid to the
        up image, so that the fluid preview shows your actual button
        images.

        Just be sure the two images for up/down are exactly the
        same size.

        Don't be too intimidated by the size of this app;
        most of the code is the button images, as it's meant to be
        a completely working example that you can just paste+run.

#include <stdio.h>
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Pixmap.H>
//
// Demo of how to make a custom up/down image for a button -erco
//
/* XPM */
static char * up_xpm[] = {
"73 21 16 1",
"       c #373836",
".      c #474946",
"+      c #565855",
"@      c #5F615E",
"#      c #70726F",
"$      c #7E807D",
"%      c #878986",
"x      c #969895",
"*      c #A1A3A0",
"=      c #B0B2AF",
"-      c #BEC0BD",
";      c #CACCC9",
"z      c #D7D9D6",
",      c #E2E4E1",
"'      c #EDEFEC",
")      c #FBFDFA",
"'''''''-*$#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#$*-''''''''",
"''''';x$*;,'))))))))))))))))))))))))))))))))))))))))))))))))',;*$x;''''''",
"''''=%*,'''''''''''''''''''''''''''''''''''''''''''''''''''''''',*%='''''",
"'''=%-''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''-%=''''",
"'';x=,'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''',=x;'''",
"''*xz,'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''',zx*'''",
"'-%=,,'''''''''''''''''''''' #''' #'' #*. %''''''''''''''''''''''',,=%-''",
",*x-z,'''''''''''''''''''''' #''' #'' .+=% *'''''''''''''''''''''',z-x*,'",
",%=-;,'''''''''''''''''''''' #''' #''  z''.@'''''''''''''''''''''',;-=%,'",
",#-;;;;zzzzzzzzzzzzzzzzzzzzz #zzz #zz #zzz@ zzzzzzzzzzzzzzzzzzzzz;;;;-#,'",
",@;;;;zzzz,,,,,,,,,,,,,,,,,, #,,, #,, #,,,# ,,,,,,,,,,,,,,,,,,zzzz;;;;@,'",
",#-z;zzzz,,,,,,,,,,,,,,,,,,, #,,, #,, #,,,@.,,,,,,,,,,,,,,,,,,,zzzz;z-@,'",
",$=zzzz,,,,,,,,,,,,,,,,,,,,, #,,x #,, #,,z #,,,,,,,,,,,,,,,,,,,,,zzzz=$,'",
",xx,zz,,,'''''''''''''''''''+.-x+ #'' @--@ ;''''''''''''''''''',,,zz,xx,'",
",=$z,,,,''''''''''''''''''''-. @z #''    @-''''''''''''''''''''',,,,z$=,'",
",z%*''''''''''''''''''''''''''''''''' #'''''''''''''''''''''''''''''*%z''",
"',=$;)'))))'))))))))))))))))))))))))) $)))))))))))))))))))))'))))');$=,''",
"''z*%;))))))))))))))))))))))))))))))) $)))))))))))))))))))))))))));%*z'''",
"'',;x$='))))))))))))))))))))))))))))))))))))))))))))))))))))))))'=$x;,'''",
"''',;*$$=;'))))))))))))))))))))))))))))))))))))))))))))))))))';=$$*;,''''",
"'''',z-*%##@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@##%*-z,'''''"};
/* XPM */
static char * down_xpm[] = {
"73 21 16 1",
"       c #373936",
".      c #454744",
"+      c #545653",
"@      c #5F615E",
"#      c #6E706D",
"$      c #7A7C79",
"%      c #868885",
"x      c #969895",
"*      c #A1A39F",
"=      c #AFB1AE",
"-      c #BEC0BD",
";      c #CACCC9",
"y      c #D7D9D6",
",      c #E2E4E1",
"'      c #EDEFEC",
")      c #FBFDFA",
"'''''''-*%#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#%*-''''''''",
"''''';x$*;,'))))))))))))))))))))))))))))))))))))))))))))))))',;*$x;''''''",
"''''=%*,'''''''''''''''''''''''''''''''''''''''''''''''''''''''',*%='''''",
"'''=%-''''''''''''''''$ ''''''''''''''''''''''''''''''''''''''''''-%=''''",
"'';x=,''''''''''''''''# '''''''''''''''''''''''''''''''''''''''''',=x;'''",
"''*xy,''''''''''''''''# '''''''''''''''''''''''''''''''''''''''''',yx*'''",
"'-%=,,''''''''''''''''# '''''''''''''''''''''''''''''''''''''''''',,=%-''",
",*x-y,''''''''''''-@    '''-@ .$y'+#'', @'', =' #-+ @,'''''''''''',y-x*,'",
",%=-;,'''''''''''; @--@ ''; #-=.+'%.''=  ''- ,' ++=* x'''''''''''',;-=%,'",
",#-;;;;yyyyyyyyyy# ;yy# yy# yyy* ** -y#@ =y$+yy  -yy #yyyyyyyyyyy;;;;-#,'",
",@;;;;yyyy,,,,,,,.@,,,# ,,.@,,,y $; *y.=.%,+%,, #,,, #,,,,,,,,yyyy;;;;@,'",
",#-y;yyyy,,,,,,,, #,,,# ,, #,,,, #,.$- [EMAIL PROTECTED] =,, #,,, 
#,,,,,,,,,yyyy;y-#,'",
",$=yyyy,,,,,,,,,, #,,,# ,,.@,,,y $,#+%#,* * ,,, #,,, #,,,,,,,,,,,yyyy=$,'",
",xx,yy,,,''''''''@.''y  ''#.,''= ='x +*'; +@''' #''' #''''''''',,,yy,xx,'",
",=$y,,,,'''''''''* %-+. ''; #-=.+'';  y''. x''' #''' #'''''''''',,,,y$=,'",
",y%*''''''''''''''% .*$ '''-@ .$,''' +'''$ ;''' $''' $''''''''''''''*%y''",
"',=$;)'))))'))))))))))))))))))))))))))))))))))))))))))))))))'))))');$=,''",
"''y*%;))))))))))))))))))))))))))))))))))))))))))))))))))))))))))));%*y'''",
"'',;x$='))))))))))))))))))))))))))))))))))))))))))))))))))))))))'=$x;,'''",
"''',;*$%=;'))))))))))))))))))))))))))))))))))))))))))))))))))';=%$*;,''''",
"'''',y-*%$#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#$%*-y,'''''"};
// CUSTOM IMAGE BUTTON CLASS
class MyButton : public Fl_Button {
    Fl_Pixmap *upimage, *dnimage;
public:
    MyButton(int X,int Y,int W,int H, const char*L=0):Fl_Button(X,Y,W,H,L) {
        upimage = dnimage = 0;
    }
    void updown(Fl_Pixmap &up,Fl_Pixmap &dn) {
        upimage = &up;
        dnimage = &dn;
        image(upimage);
        resize(x(),y(),up.w(),up.h());
        clear_visible_focus();
    }
    int handle(int event) {
        int ret = Fl_Button::handle(event);
        switch ( event ) {
            case    FL_PUSH: image(dnimage); redraw(); ret = 1; break;
            case   FL_LEAVE:
            case FL_UNFOCUS:
            case FL_RELEASE: image(upimage); redraw(); ret = 1; break;
        }
        return(ret);
    }
};
int main(int argc, char **argv) {
    Fl_Pixmap up(up_xpm);
    Fl_Pixmap down(down_xpm);
    Fl_Window win(100,100,"Test");
    win.color(0xedefec00);              // bg color of mac buttons
    MyButton b1(10,10,0,0); b1.updown(up,down);
    MyButton b2(10,40,0,0); b2.updown(up,down);
    win.end();
    win.show();
    return(Fl::run());
}
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to