domino@sunybcs (Michael Domino) (01/13/88)
I have this display that is quite involved and takes a couple of seconds to set up. There are four windows, so I have been calling GetNewWindow, doing the necessary drawing, then going on to the next window, repeating this for each window. But this looks not-so-clever to a user, so what I thought I would do is set everything up in an offscreen bitmap, use CopyBits to display the whole thing all at once, and then set the portBits field of each window's grafport back to screenBits, so that all subsequent drawing takes place on the screen. I've used CopyBits successfully before to copy something from screenBits to an offscreen bitmap (to refresh the screen later), but I've never had any occasion to actually do any drawing offscreen. I thought the following code might work...but it doesn't (just get garbage). The windows are set to be initially invisible. This code is probably incredibly naive. What's the proper way? Lightspeed C, by the way. BitMap offScreenBits; /* The offscreen bitmap. */ Rect boundsRect; /* The copy bounds. */ /* This function works fine. */ Ptr NewBitMap(b, r) BitMap *b; Rect r; { b->rowBytes = ((r.right - r.left + 15) / 16) * 2; b->baseAddr = NewPtr(b->rowBytes * (r.bottom - r.top)); b->bounds = r; if(MemError() != noErr) return NULL; else return b->baseAddr; } func() { int i, firstWID = 128; WindowPtr w; boundsRect.left = 2; boundsRect.right = 510; boundsRect.top = 20; boundsRect.bottom = 340; if(NewBitMap(&offScreenBits, boundsRect) == NULL) return errorcode; for(i = 0; i < 4; i++) { w = GetNewWindow(firstWID + i, NULL, (WindowPtr)-1L); SetPort(w); SetPortBits(&offScreenBits); ShowWindow(w); DrawStuff(w); SetPortBits(&screenBits); } CopyBits(&offScreenBits, &screenBits, &offScreenBits.bounds, &boundsRect, srcCopy, NULL); } Michael Domino @ SUNY/Buffalo internet: domino@cs.buffalo.edu uucp: ..!{rutgers,watmath,boulder,decvax}!sunybcs!domino BITNET: domino@sunybcs.BITNET phone: 716-881-6420
dgold@apple.UUCP (David Goldsmith) (01/14/88)
Any technique which does a CopyBits directly to the screen is not compatible with MultiFinder. A better way to do it is to draw the contents of each window in an offscreen bitmap, then copy that bitmap into the window. The frame of the window cannot be displayed into an offscreen bitmap and copied onscreen if you want to remain compatible with MultiFinder and other future system software. -- David Goldsmith Apple Computer, Inc. AppleLink: GOLDSMITH1 UUCP: {nsc,dual,sun,voder,ucbvax!mtxinu}!apple!dgold CSNET: dgold@apple.CSNET, dgold%apple@CSNET-RELAY BIX: dgoldsmith