corelab@msscc.med.utah.edu (12/06/90)
I am fairly new to Mac programming and have some questions about offscreen bitmaps. It seems like drawing in offscreem bitmaps is the only reasonable way to deal with windows whose contents change as the prog. runs. IM says that under most circumstances it's the thing to do, but does not elaborate on how to do it. OK, I kind of enjoy figuring things like this out, but it seems like some information about how things behave is missing. I assume that the thing to do is do an OpenPort (although IM claims it's something one won't usually call directly), set aside storage for the offscreen bit image, declare a bitmap and set it up to point to the bit image, and change the portBits of the new GrafPort to point to the bit image. Then, all drawing would be done to the offscreen GrafPort, and regions drawn in would be added to the update region of the actual window. The application will be set up to handle update events for the window by doing a copybits from the off- screen bitmap to the bitmap of the window. My questions are: 1. Have I got it right so far? 2. Is there some convenient way to add what is drawn offscreen to the window's update region? I could see how if only, say, rectangles were being drawn, it would be a simple matter of calling InvalRect for the rectangle (in the project I'm working on, I' collecting data in real time and plotting points (OK, not QD points but rather pixels), probably by drawing tiny lines from (x,y) to (x+1,y+1) BTW is this the best way to do it?). However, it seems like if a lot of drawing is being done using various drawing routines in different contexts, it's a bit of a pain to in each case decide what rect or region to add (also I wonder whether adding lots of pieces to the region slows things down, like in the data collection case described where I'll be adding on the order of 10 rects every second). Is there some more automatic way to do things that I'm missing? 3. Im states that visRgn has no effect on images not displayed on the screen. What exactly does that mean? I certainly get the having no effect part, but how does QD decide if a GrafPort is on the screen. I can think of at least two interpretations: it may check portBits to see whether the bit image is the same as the screens, or it may check the somewhat mysterious device field. IM says device is zero for the screen, but doesn't mention any other values. I realize I could just set the visRgn to cover the whole bitmap; I'd just like to be sure I'm clear on how everything works. Any hints on the topic would be appreciated. Thanks in advance, and my apologies if this is an annoying faq. -Lyle