[comp.sys.mac.programmer] Mouse Location

rg2c+@andrew.cmu.edu (Robert Nelson Gasch) (01/30/91)

Does anybody out there know how to access the location of a mouseclick?
In a program I'm writing, I'm displaying some graphics and depending
on which part of the picture the user clicks on, I'd like to take
appropriate action. If anybody knows the code to access the location
of a mouse click (preferrably in C), please forward me a copy.

Thanx alot --> Rob

gv9b2c9z@umiami.ir.miami.edu (Ordinary Man) (02/01/91)

In article <0bdWARO00UhW04iF8J@andrew.cmu.edu>, rg2c+@andrew.cmu.edu (Robert Nelson Gasch) writes:
> Does anybody out there know how to access the location of a mouseclick?
> In a program I'm writing, I'm displaying some graphics and depending
> on which part of the picture the user clicks on, I'd like to take
> appropriate action. If anybody knows the code to access the location
> of a mouse click (preferrably in C), please forward me a copy.

All you really have to do is call:

	Point	mouseLoc;

	GetMouse(&mouseLoc);
	...

which returns in mouseLoc the current location of the mouse (whether the
button was clicked or not) in LOCAL coordinates. I once made the mistake
off calling GlobalToLocal on mouseLoc which is obviously unnecessary.
Remember, the local coordinates are of the current GrafPort and mouseLoc
is of type Point.


> Thanx alot --> Rob

No problem,
		==Dan
-- 
/-------------------------------------------------------------------------\
|   Dan Weisman -  University of Miami - Florida   |  ||   ||   ||   ||   |
|--------------------------------------------------|  ||   ||   ||\ /||   |
|   INTERNET  -----> gv9b2c9z@umiami.IR.Miami.edu  |  ||   ||   || | ||   |
|     BITNET  -----> gv9b2c9z@umiami               |  |||||||   || | ||   |
|-------------------------------------------------------------------------|
|      "...bows it's head and prays to the mother of all machines."       |
\_________________________________________________________________________/

Jim.Spencer@p510.f22.n282.z1.mmug.edgar.mn.org (Jim Spencer) (02/01/91)

Robert Nelson Gasch writes in a message to All

RNG> Does anybody out there know how to access the location of a mouseclick?

The location of the mouse click is returned in the EventRecord with every event event.  In its simplest form:

myEvent: EventRecord;
thelocation: Point;

GetNextEvent(everyEvent, myEvent);

case myEvent.what of
     ...
     mouseDown:
          ...
          thelocation := myEvent.where;  
{etc.}

Note that the location of the mouse returned in where is global or screen coordinates.  You may need to use GlobalToLocal(thelocation) to convert to your window's coordinates.

You can also always call GetMouse(thelocation) and it will return the location of the mouse at the time it is called regardless of whether the mouse is down or not.
 

--  
Jim Spencer - via The Minnesota Macintosh Users Group UUCP-Fido Gateway
UUCP: ...uunet!tcnet!kksys!edgar!mmug!22.510!Jim.Spencer
INET: Jim.Spencer@p510.f22.n282.z1.mmug.edgar.mn.org

francis@uchicago.edu (Francis Stracke) (02/01/91)

In article <1991Jan31.153307.7732@umiami.ir.miami.edu> gv9b2c9z@umiami.ir.miami.edu (Ordinary Man) writes:

   In article <0bdWARO00UhW04iF8J@andrew.cmu.edu>, rg2c+@andrew.cmu.edu (Robert Nelson Gasch) writes:
   > Does anybody out there know how to access the location of a mouseclick?

   All you really have to do is call:

	   Point	mouseLoc;

	   GetMouse(&mouseLoc);

No, no! Whenever you get any event (evt), evt.where holds the location
of the mouse at the time the event occurred.  This is what you want:
it is possible that the user may have moved the mouse since clicking
(esp. if you're doing something slow).  (It's also faster to read the
value than to call a procedure.  :-)

--
/=============================================================================\
| Francis Stracke		| My opinions are my own.  I don't steal them.|
| Department of Mathematics	|=============================================|
| University of Chicago		| Until you stalk and overrun,	     	      |
| francis@zaphod.uchicago.edu	|  you can't devour anyone. -- Hobbes 	      |
\=============================================================================/