Re: Bug in Cocoa drawing? (was 'Changing subviews during drawing')
Re: Bug in Cocoa drawing? (was 'Changing subviews during drawing')
- Subject: Re: Bug in Cocoa drawing? (was 'Changing subviews during drawing')
- From: Drew McCormack <email@hidden>
- Date: Fri, 2 Apr 2004 10:17:24 +0200
Here is a cut down version of the code in the NRTPlotView class:
- (void)drawRect:(NSRect)rect
{
[_cachedImage release];
_cachedImage = [[NSImage alloc] initWithSize:[self
frame].size];
[_cachedImage lockFocus];
[_component drawInPlotView:self]; // This code includes the
NS_DURING block
[_cachedImage unlockFocus];
[_cachedImage compositeToPoint:rect.origin fromRect:rect
operation:NSCompositeSourceOver];
}
Two questions:
* What happens in "drawInPlotView:"?
This draws some lines with NSBezierCurve. To calculate the lines
involves some complex calculations, and that is why I use the
NS_DURING: I want to catch exceptions raised in calculating where the
lines should be drawn.
* Why do you use "compositToPoint:..." *after* you have unlocked the
image? Are you not supposed to bracket all drawing operations inside a
lock/unlock block?
The code I wrote is very cut down. I usually have several branches in
there, to check whether the cache is up to date or not. Basically, if
the cache is not up to date, I draw to the NSImage, which then contains
the graphics needed for the NRTPlotView. I composite this image to the
NRTPlotView graphics context, because that is the purpose of the
drawRect: method. If at some later time drawRect: is called, and the
NRTPlotView attributes have not changed, I can just composite the
cached image.
So the answer is: I do the drawing when the NSImage has focus, but I
composite the NSImage itself when the NRTPlotView has focus.
* What are you drawing in the last "compositToPoint:..." operation?
Drawing the NRTPlotView.
Is this a bug, or am I doing something illegal with when I lock focus
on the NSImage?
I would guess the latter.
Someone else has said they have also had this problem in the past.
Apparently the new exception handling constructions can help, in
particular, the @finally block. I may try this and see if it works.
Drew
========================================
Dr. Drew McCormack (Kmr. R153)
Afd. Theoretische Chemie
Faculteit Exacte Wetenschappen
Vrije Universiteit Amsterdam
De Boelelaan 1083
1081 HV Amsterdam
The Netherlands
Email email@hidden
Telephone +31 20 44 47623
Mobile +31 6 483 21307
Fax +31 20 44 47629
_______________________________________________
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.