FB II Compiler

PG PRO

Debugging

Memory

System

Mathematics

Resources

Disk I/O

Windows

Controls

Menus

Mouse

Keyboard

Text

Fonts

Drawing

Sound

Clipboard

Printing

Communication

ASM

Made with FB

MOUSE

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
  msEvnt=MOUSE(0)
  SELECT msEvnt
    CASE _click1
      BEEP
      PRINT%(20,40)"Click1 = " MOUSE(0)
    CASE _click1nDrag
      PRINT%(20,80)"Click1nDrag = " MOUSE(0)
  END SELECT
END FN

WINDOW#1,"Cmd.period to quit",(30,40)-(500,400)
PRINT%(20,20) "Click once."

ON MOUSE FN doMouse
DO
  HANDLEEVENTS
UNTIL 0

Steve Van Voorst


Try a delay and test, e.g.

DELAY 0300
LONG IF FN STILLDOWN = _true
' go to drag logic
XELSE
' go to click logic
END IF

vary the delay to suit whatever you're doing

Dale


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
' with a lot of help from Mel.

'=D7=D7=D7
' HOW TO CALL THE ROUTINE
' osErr% = FN WaitMouseMoved(initialMouse&)
' RETURNS true IF A DRAG CAN BE INITIATED
'
CLEAR LOCAL MODE
LOCAL FN WaitMouseMoved(initialMouse&)
  DIM osErr
  ` 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%

you then call this:

LONG IF FN WaitMouseMoved( mPt&)
' you got a drag going
XELSE
' it was just a click
END IF

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.

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 ;-)

jonathan


_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.

Mars