Michael Schmid wrote:
> What I finally need is the following behaviour:
>
> Button unpressed: Picture 1 is shown on button
> Button pressed: Picture 2 is shown on button
> A function is called if you release the button, but just if you release
> it on the button. If the button gets released, because you move the
> mouse away from the button, then the function shouldn't be called.
>
> To show the two pictures I configurated the button as FL_WHEN_CHANGED
> and did the following code in the callback:
>
> static void fCallbackButtonHelp(Fl_Button*, void *)
> {
> if (pMainButtonHelp->value())
> {
> pMainButtonHelp->image(pPixmapHelpPressed);
> }
> else
> {
> pMainButtonHelp->image(pPixmapHelpUnpressed);
> fFunctionToBeCalled();
> }
> }
>
> I thought that I can maybe make another "if" to call the
> fFunctionToBeCalled just if the mouse is still on the button (i.e. the
> callback was not called because the mouse was moved away, but because
> the mouse was released on the button....)
Matthias replied already that you can derive your own class and do
anything you want by monitoring events like FL_ENTER, FL_LEAVE, FL_PUSH,
FL_DRAG, FL_RELEASE, and so on. For specific purposes, this is generally
the best way to go, but maybe more complicated than you would need here.
> Is there any simple solution for this?
If you can deal with the callback being called like you wrote before,
then you can indeed add another "if" to check the x/y coordinates of the
event being handled. You can use Fl::event_inside(YourButton) [1] or, if
necessary Fl::event_x() [2] and Fl::event_y() [3] to check the
coordinates of the event that triggered the callback.
[1] http://www.fltk.org/doc-1.1/Fl.html#Fl.event_inside
[2] http://www.fltk.org/doc-1.1/Fl.html#Fl.event_x
[3] http://www.fltk.org/doc-1.1/Fl.html#Fl.event_y
Albrecht
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk