Re: Text over graphics
Re: Text over graphics
- Subject: Re: Text over graphics
- From: "Erik M. Buck" <email@hidden>
- Date: Fri, 28 Sep 2001 12:04:27 -0500
There are several ways to achieve your goal.
1) Do your complex composting into a separate off-screen NSImage. Then
composite the entire NSImage into your view. Then draw the text. When the
text changes, composite just the portion of the off-screen image under the
text and then draw the text.
2) Use two different views: one for the image and a sub-view for the text.
Whenever the text is redrawn, the image view will receive a call
to -drawRect: with just the rectangle that needs to be redrawn. You can be
as clever as you want in -drawRect to do minimal drawing
3) Before you draw the text the first time, grab a bitmap of the background
behind the text. Draw the text. When the text changes, draw the grabbed
bitmap to erase the old text and then draw the new text. The good news is
that you do not have to do this the hard way: A search on temporary drawing
reveals the following:
cacheImageInRect:
- (void)cacheImageInRect:(NSRect)aRect
Stores the receiver's raster image from aRect, which is expressed in the
receiver's base coordinate system. This allows the receiver to perform
temporary drawing, such as a band around the selection as the user drags the
mouse, and to quickly restore the previous image by invoking
restoreCachedImage and flushWindowIfNeeded. The next time the window
displays, it discards its cached image rectangles. You can also explicitly
use discardCachedImage to free the memory occupied by cached image
rectangles. aRect is made integral before caching the image to avoid
antialiasing artifacts.
See Also: - display