Re: XForms: Mouse clicks (newbe)

Steve Lamont (spl@szechuan.ucsd.edu)
Thu, 25 Sep 97 06:04:30 PDT

To subscribers of the xforms list from spl@szechuan.ucsd.edu (Steve Lamont) :

from Sander Stoks <sanders@sci.kun.nl> :
> For my graduation project, I am writing an app to do image processing.
> I have an fl_canvas in there to show the image, bordered with sliders
> to act as scrollbars. Everything works OK. But I'd like to be able
> to click on that image and get the coordinates returned.

Look at the function fl_add_canvas_handler() described in the section
on Canvas. You will need to add an ButtonPress XEvent handler, at
least. You will probably wish to add handlers for the ButtonRelease
event, MotionNotify event, Expose event, and, perhaps, ConfigureNotify
event, as well.

A hint: if you add and remove MotionNotify events handlers on the fly
(only when a mouse button is pressed, for instance), you will also
need to do an

fl_addto_selected_xevent( FL_ObjWin( your_canvas ),
OwnerGrabButtonMask );

Otherwise, the MotionNotify event doesn't get registered.

You will probably also find that the pointer MotionNotify events are
somewhat sluggish or erratic. If you do, then you'll want to also
call

fl_remove_selected_xevent( FL_ObjWin( your_canvas ),
PointerMotionHintMask );

This tells the X server to send you all the motion events generated.
Otherwise, X just sends you the MotionEvents periodically. If this is
good enough, there is a motion history buffer which can be queried
with a straight Xlib function call.

The ButtonPress, ButtonRelease, and MotionNotify XEvents all contain
the pointer coordinates relative to the Window which received the
XEvent (your Canvas).

Refer to the manual and your favorite Xlib reference for details (I
like the O'Reilly and Associates series).

spl
_________________________________________________
To unsubscribe, send the message "unsubscribe" to
xforms-request@bob.usuf2.usuhs.mil or see
http://bob.usuf2.usuhs.mil/mailserv/xforms.html
Xforms Home Page: http://bragg.phys.uwm.edu/xforms
List Archive: http://bob.usuf2.usuhs.mil/mailserv/list-archives/