Caching NSViews
Caching NSViews
- Subject: Caching NSViews
- From: Drew McCormack <email@hidden>
- Date: Tue, 12 Nov 2002 20:45:46 +0100
I have an NSView subclass which I have tried to optimize by drawing to
an NSImage, and then compositing the image to screen when needed. Here
is the code:
-(void)drawRect:(NSRect)rect {
if ( [self needsLayout] ) {
[self layout];
[_cachedImage release];
_cachedImage = [[NSImage alloc] initWithSize:[self frame].size];
[_cachedImage setBackgroundColor:[NSColor whiteColor]];
[_cachedImage lockFocus];
[super drawRect:[self frame]]; // This does the actual drawing
[_cachedImage unlockFocus];
}
[_cachedImage compositeToPoint:rect.origin fromRect:rect
operation:NSCompositeCopy];
}
The problem is, this NSView class has sub-views, and I don't want these
to draw after I have cached their drawing in the NSImage. Because they
are sub-views, the Cocoa drawing architecture is calling their
drawRect: methods. My question is: Is there any way to avoid the
sub-views drawing short of adding an ivar or two (eg
_shouldDrawWhenAsked) to my NSView subclasses? Basically, is there an
easy way of escaping the usual display order of drawing a view, then
it's subviews, then their subviews, etc.
Drew
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
... ... ... ... ... ... ... ...
Dr. Drew McCormack
Trade Strategist (www.trade-strategist.com)
Trading simulation software for Mac OS X
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.