Greg Ercolano wrote:
> I think the clean approach would be to forget using a button,
> and make the image area a class derived from Fl_Box with its
> own event handle()er that detects mouse clicks on the image
> (FL_PUSH and FL_RELEASE) and invoke the callback.
>
> Should be easy to do.
> I can post some code that would show how to do this if needed.
Here's some example code.
It includes letting the user push on a button, but drag off
and release without registering as a click.
The XPM was too big to paste, so I've put it here:
http://seriss.com/people/erco/fltk/tmp/buttonab.xpm
It does necessitate hard coding in the x/y/w/h positions
of each button in the image, but I think there's no way
around that no matter what approach is used.
#include <stdio.h>
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Pixmap.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;
int ret = Fl_Box::handle(e);
switch (e) {
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"); break;
case 2: printf("BUTTON B\n"); 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());
}
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk