[comp.sys.mac.programmer] GWorld woes

CXT105@psuvm.psu.edu (Christopher Tate) (05/04/91)

Does anyone have any idea why the following code doesn't work?  I'm trying
to implement a "click on a given object" detection scheme by using an
offscreen GWorld to figure out what object has been clicked on (layered
objects; MacDraw sort of stuff).

Unfortunately, it never seems to think that anything has been clicked on.
Any suggestions?  I'm using THINK C 4, with the 32-bit CQD header files
that Phil Shapiro sent me (thanks!).

----- code starts here -----

GWorldPtr  screen, offscreen;
GDHandle   scrGDH, offGDH;
Ptr        offAddr;
Point      mouse;
Rect       bRect;

bRect.top = bRect.left = 0;
bRect.bottom = bRect.right = 1;    /* one-pixel rectangle */
(void) NewGWorld(&offscreen, 1, &bRect, 0L, offGDH, 0);
LockPixels(offscreen->portPixMap);

/* that's the initialization ... later on, I try the following: */

SetGWorld(offscreen, offGDH);      /* draw offscreen */
offAddr = GetPixBaseAddr(offscreen->portPixMap);
MovePortTo(mouse.h, mouse.v);      /* from EventRecord; global coords */
DrawObject();                      /* draw the desired object */
if (*offAddr) SysBeep(3);          /* beep if we click on it */
SetGWorld(screen, scrGDH);         /* switch back to drawing on screen */

/* that's the gist of it ... the machine never beeps */