Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!cs.utexas.edu!rice!uw-beaver!Teknowledge.COM!polya!ali From: ali@polya.Stanford.EDU (Ali T. Ozer) Newsgroups: comp.sys.next Subject: Re: Bitmaps from views Message-ID: <12873@polya.Stanford.EDU> Date: 22 Nov 89 18:35:49 GMT References: <867@shelby.Stanford.EDU> Reply-To: ali@Polya.Stanford.EDU (Ali T. Ozer) Organization: . Lines: 57 In article <867@shelby.Stanford.EDU> Dave Combs writes: > ... After I sent my note out, >I realized that I'd left out one crucial piece of information, namely that >the image that I'm trying to place in a bitmap consists of a whole >hierarchy of views, rather than just a single view. ... >To restate the problem for anyone who missed it - to speed up some >interactive drawing operations (for a "link and node editor" I'm developing) >I would like to cache certain images in Bitmaps. It appears that the >standard "cache to offscreen window, then composite" trick only works >when the image being cached is only a single view, whereas each of my >images is a hierarchy of views. What's the best way to get these to a >Bitmap? Hmm, I see, your problem is somewhat more complicated. How about this, then --- go ahead, draw your views into a window using the normal drawing stuff, then, composite from the window to a bitmap. The drawing in the window will be done through the view heirarchy, and you won't have to worry about locking focus on the bitmaps. Here's how you composite from a window to a bitmap: [bitmap lockFocus]; PScomposite (srcX, srcY, width, height, // Of the area in the window [window gState], 0.0, 0.0, NX_COPY); [bitmap unlockFocus]; The window you draw into can either be on-screen or off-screen. If it's on-screen, you will have some extra work to do as [window gState] will give you the graphics state of the window, which includes the borders and such. Thus, you'd need to account for these when specifying srcX, srcY. Or you can create a gState for the contentView of the window (once, after the window is created), and use that. To create: [[window contentView] allocateGState]; To use: PScomposite (srcX, srcY, width, height, // Of the area in the window [[window contentView] gState], 0.0, 0.0, NX_COPY); Creating an off-screen window might be a better idea; in that case you specify style:NX_PLAINSTYLE. This way you won't have any borders or title bars to worry about and you can just use [window gState] when compositing. Actually, if all you wanted to do was composite from this cache, you can even just use this off-screen window as the cache and forget about using a bitmap; after all, a bitmap is just a part of an off-screen window with some extra functionality thrown in and some window functionality removed. Bitmaps just tend to be more efficient as the appkit uses shared windows to stick all the bitmaps into. But if you're just going to use one big cache bitmap, it won't matter which you use. Ali