w_reade
2002.11.21, 08:50 PM
Well, I was writing a blitterÖ and it all seemed to be going ok, copying from one GWorld to another without a hitch, when I tried to convince it to draw from a GWorld to a window. This is what I did:
void DrawGWorldToWindow (GWorldPtr theGWorld, WindowRef theWindow)
{
PixMapHandle srcPixMap, dstPixMap;
CGrafPtr winPort, storePort;
GDHandle storeDevice;
Rect srcBounds, dstBounds;
srcPixMap = GetGWorldPixMap(theGWorld);
GetPixBounds(srcPixMap, &srcBounds);
LockPixels(srcPixMap);
dstBounds = srcBounds;
if (g->pref.border && theWindow == g->theWindow)
OffsetRect(&dstBounds, BORDER_WIDTH, BORDER_HEIGHT);
winPort = GetWindowPort(theWindow);
dstPixMap = GetPortPixMap(winPort);
LockPixels(dstPixMap);
GetGWorld(&storePort, &storeDevice);
SetGWorld(winPort, NULL);
[blitting function]
/* QuickCopy(srcPixMap, dstPixMap, &srcBounds, &dstBounds); */
UnlockPixels(srcPixMap);
UnlockPixels(dstPixMap);
SetGWorld(storePort, storeDevice);
}
When I use CopyBits(), it draws to the window fine.
When I use my own function, it draws on top of everything on the main screen, even when the app is in the background, into the dstRect as interpreted in global co-ordinates rather than local (so the window gets drawn at the top left of the screen, eclipsing the menubar).
If I offset the dstRect to where it should be on screen, the picture is clipped to the window's port bounds where the port bounds are interpreted wrong in the same way as before; so I get the pixels drawn in the right place on screen, but the clipping's wrong, and you can't see anything except where the window overlaps.
This is probably because my blitter gets the dstPixMap's bounds and clips against themÖ but why does it draw directly onto screen in the first place? I asked for the window's port, after all, and I thought that the window's port was, well, the window's port, not the whole-screen-the-window-lives-on's portÖ
It's very vexing - All I do in my blitter is take two PixMapHandles and two Rect *s, clip the Rects a bit, get the PixMaps' Depths, RowBytes's and BaseAddrs, and BlockMoveData() with the information gleaned.
So, presumably there's something that CopyBits does that I should do tooÖ does anyone know what it might be? Does CopyBits somehow know when I'm drawing to a window and compensate? Surely not.
ButÖ all suggestions welcome, and thanks in advance.
void DrawGWorldToWindow (GWorldPtr theGWorld, WindowRef theWindow)
{
PixMapHandle srcPixMap, dstPixMap;
CGrafPtr winPort, storePort;
GDHandle storeDevice;
Rect srcBounds, dstBounds;
srcPixMap = GetGWorldPixMap(theGWorld);
GetPixBounds(srcPixMap, &srcBounds);
LockPixels(srcPixMap);
dstBounds = srcBounds;
if (g->pref.border && theWindow == g->theWindow)
OffsetRect(&dstBounds, BORDER_WIDTH, BORDER_HEIGHT);
winPort = GetWindowPort(theWindow);
dstPixMap = GetPortPixMap(winPort);
LockPixels(dstPixMap);
GetGWorld(&storePort, &storeDevice);
SetGWorld(winPort, NULL);
[blitting function]
/* QuickCopy(srcPixMap, dstPixMap, &srcBounds, &dstBounds); */
UnlockPixels(srcPixMap);
UnlockPixels(dstPixMap);
SetGWorld(storePort, storeDevice);
}
When I use CopyBits(), it draws to the window fine.
When I use my own function, it draws on top of everything on the main screen, even when the app is in the background, into the dstRect as interpreted in global co-ordinates rather than local (so the window gets drawn at the top left of the screen, eclipsing the menubar).
If I offset the dstRect to where it should be on screen, the picture is clipped to the window's port bounds where the port bounds are interpreted wrong in the same way as before; so I get the pixels drawn in the right place on screen, but the clipping's wrong, and you can't see anything except where the window overlaps.
This is probably because my blitter gets the dstPixMap's bounds and clips against themÖ but why does it draw directly onto screen in the first place? I asked for the window's port, after all, and I thought that the window's port was, well, the window's port, not the whole-screen-the-window-lives-on's portÖ
It's very vexing - All I do in my blitter is take two PixMapHandles and two Rect *s, clip the Rects a bit, get the PixMaps' Depths, RowBytes's and BaseAddrs, and BlockMoveData() with the information gleaned.
So, presumably there's something that CopyBits does that I should do tooÖ does anyone know what it might be? Does CopyBits somehow know when I'm drawing to a window and compensate? Surely not.
ButÖ all suggestions welcome, and thanks in advance.