🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.amiga.tech
Article #11144

Double click detection?

#11144
From: Ross Cunniff
Date: Mon, 23 Jan 1989 17:24
93 lines
3192 bytes
I've been fiddling around with detecting double-clicking of the select
button in an application I'm writing.  The method I've come up with follows
(it has been typed in from memory; don't flame me for minor typos...).
It works OK, except that a single click without excessive mouse motion
following takes a noticble amount of time to get processed.  In addition,
the double click loop is hard on the multitasking O/S.  (I just realized
that I could use Intuition timer events; any caveats?)  Does anybody
have a better way of doing this?

A second, only slightly releated question is:  How does one safely close
windows with shared IDCMP ports?  The AutoDocs give a passing mention
to a routine named CloseWindowSafely(), and claim that it is documented
in one of the early issues of AmigaMail.  I don't seem to have that issue.


At any rate, here is the double click loop:

	Wait( 1 << Win->UserPort->mp_SigBit );

	while( Msg = GetMsg( Win->UserPort ) ) {
	    /* Copy Code, Class, etc. fields from Msg; deleted for space */
	    ReplyMsg( Msg );

	    if( (Class == MOUSEBUTTONS) && (Code == SELECTDOWN) ) {
		/* Mouse click; Save current parameters */
		OldS = CurrS;	OldU = CurrU;
		OldX = MouseX;	OldY = MouseY;
		/* Etc... */

		Done = NOT_DONE;
		while( Done == NOT_DONE ) {
		    Msg = GetMsg( Win->UserPort );
		    if( Msg ) {
			/* Copy fields from Msg; deleted for space */
			ReplyMsg( Msg );

			if( (Class == MOUSEBUTTONS) && (Code == SELECTDOWN) ) {
			    if( DoubleClick( OldS, OldU, CurrS, CurrU ) ) {
				/* Aha! a double click */
				Done = DOUBLE_CLICK;
			    }
			    else {
				/* Oops!  Two discrete mouse clicks */
				Done = TWO_EVENTS;
			    }
			}
			else if( Class == MOUSEMOVE ) {
			    if(		(ABS( OldX - MouseX ) > MAX_XDLTA) ||
					(ABS( OldY - MouseY ) > MAX_YDLTA) )
			    {
				/* We moved the mouse too far */
				Done = TWO_EVENTS;
			    }
			}
			else {
			    /* Another event (gadgetclick? RAWKEY?) came in */
			    Done = TWO_EVENTS;
			}
		    }
		    else {
			/* No event pending; see if we've timed out */
			CurrentTime( &CurrS, &CurrU );
			if( DoubleClick( OldS, OldU, CurrS, CurrU ) ) {
			    /* We timed out; go away */
			    Done = TIMEOUT;
			}
		    }
		}	/* end while( Done == NOT_DONE ) */

		/* OK, something happened;  process it */
		switch( Done ) {
		    case DOUBLE_CLICK :
			/* Do double click stuff */
			break;
		    case TWO_EVENTS :
			/* Do stuff for first event */
			/* Do stuff for second event */
			break;
		    case TIMEOUT :
			/* Do stuff for first event */
			break;
		}
	    }	/* end if( select click ) */
	    else {
		/* Do stuff for other events */
	    }
	}	/* end while( Msg ) */



				Ross Cunniff
				...{ucbvax,hplabs}!hpfcrt!cunniff
				cunniff%hpfcrt@hplabs.HP.COM
Technical Details
Message-ID: <11640007@hpfcdc.HP.COM>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!lll-winken!ncis.llnl.gov!helios.ee.lbl.gov!pasteur!ucbvax!hplabs!hpfcdc!cunniff

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!lll-winken!ncis.llnl.gov!helios.ee.lbl.gov!pasteur!ucbvax!hplabs!hpfcdc!cunniff
From: cunniff@hpfcdc.HP.COM (Ross Cunniff)
Newsgroups: comp.sys.amiga.tech
Subject: Double click detection?
Message-ID: <11640007@hpfcdc.HP.COM>
Date: 23 Jan 89 17:24:08 GMT
Organization: HP Ft. Collins, Co.
Lines: 93