OK, glib mode off.

Here's a slightly revised (I hesitate to say "enhanced") version of
Greg's code that also changes the cursor to a hand when you are over the
active button areas.

HTH,
-- 
Ian

//**********************************************************************
***********
#include <stdio.h>
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Pixmap.H>
#include <FL/fl_draw.H>

#include "buttonab.xpm"
// Demonstrate a 'clickable image'
class ButtonImage : public Fl_Box
{
    int which_button() {
        if ( Fl::event_inside(x()+2, y()+4 ,63,19) ) return(1);
        if ( Fl::event_inside(x()+2, y()+26,63,19) ) return(2);
        return(0);
    }
    int handle(int e) {
        static int but_down, but_up;
                static int curs_hand = 0;
                int in_box;
        int ret = Fl_Box::handle(e);
        switch (e) {
                        case FL_MOVE:
                                ret = 1;
                                in_box = (which_button() != 0) ? 1 : 0;
                                if(in_box && !curs_hand) {
                                        fl_cursor(FL_CURSOR_HAND,
FL_BLACK, FL_WHITE);
                                        curs_hand = 1;
                                }
                                else if (curs_hand && !in_box) {
                                        fl_cursor(FL_CURSOR_DEFAULT,
FL_BLACK, FL_WHITE);
                                        curs_hand = 0;
                                }
                                break;
            case FL_PUSH:
                but_down = which_button();
                ret = 1;
                break;
            case FL_RELEASE:
                ret = 1;
                but_up = which_button();
                if ( but_down == but_up ) {
                    switch (but_up) {
                        case 1: printf("BUTTON A\n"); fflush(stdout);
                                                        break;
                        case 2: printf("BUTTON B\n"); fflush(stdout);
                                                        break;
                    }
                }
                break;
        }
        return(ret);
    }
public:
    ButtonImage(int X,int Y) : Fl_Box(X,Y,5,5) {
        static Fl_Pixmap buttonpixmap(buttonab_xpm);
        image(buttonpixmap);
        resize(X,Y,buttonpixmap.w(),buttonpixmap.h());
    }
};

int main() {
    Fl_Window win(180,180);
    new ButtonImage(50,50);
    win.end();
    win.show();
    return(Fl::run());
}

/* end of file */



SELEX Sensors and Airborne Systems Limited
Registered Office: Sigma House, Christopher Martin Road, Basildon, Essex SS14 
3EL
A company registered in England & Wales.  Company no. 02426132
********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************

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

Reply via email to