Distinguish simple click from click and drag
Does anyone know how to discriminate between _click1 and _click1nDrag? The following code always returns -1 (_click1nDrag). Click1 should return +1 according to FB/Tools/Constants/_FBasic Mouse Group.
COMPILE 0, _caseInsensitive
LOCAL FN doMouse
PRINT%(20,40)"Click1 = " MOUSE(0)
PRINT%(20,80)"Click1nDrag = " MOUSE(0)
WINDOW#1,"Cmd.period to quit",(30,40)-(500,400)
PRINT%(20,20) "Click once."
ON MOUSE FN doMouse
Try a delay and test, e.g.
vary the delay to suit whatever you're doing
LONG IF FN STILLDOWN = _true
' go to drag logic
' go to click logic
There is a new toolbox call that comes with the Drag Manager that tests to see if you initiated a drag. It's supposed to be for use with drag Manager, but you might be able to use it.
' from the drag manager headers - translated from C
you then call this:
' with a lot of help from Mel.
' HOW TO CALL THE ROUTINE
' osErr% = FN WaitMouseMoved(initialMouse&)
' RETURNS true IF A DRAG CAN BE INITIATED
CLEAR LOCAL MODE
LOCAL FN WaitMouseMoved(initialMouse&)
` SUBQ.W #2,sp ;clear space for osErr
` MOVE.L ^initialMouse&,-(sp)
` DC.W $7023,$ABED
` MOVE.W (sp)+,^osErr% ;D0 = osErr
END FN = osErr%
LONG IF FN WaitMouseMoved( mPt&)
I can't remember offhand if the mPt& must be in global or local coords - in my app i use eWhere&, 'cos I use an event framework, rather than vanilla FB.
' you got a drag going
' it was just a click
OK - just checked in Programmer guidelines - it's global.
Another caveat - I don't know whether you have to install drag handlers to get this to work, or whether it is independant. Only one way to find out ;-)
_click1 made sense on older Macs, where the user could actually click and release the mouse before you got the event. Nowdays, everything runs so much faster that _nobody_ is fast enough to release the mouse button before the event fires. So you always get a click1nDrag message.
I generally don't use time to distinguish between clicks and drags. Instead, I sample the starting mouse position, then run in a loop comparing the current position with the original position. If the current position changes by more than some predefined "slop value" (say four pixels in any direction) then I start the drag-n-drop operation.
Otherwise, I just wait for them to release the mouse and call it a click.