Re: Problem on clearing points and paths on a NSView
Re: Problem on clearing points and paths on a NSView
- Subject: Re: Problem on clearing points and paths on a NSView
- From: JArod Wen <email@hidden>
- Date: Tue, 22 Jul 2008 21:45:01 -0400
Thanks for your reply!
drawRect:
-(void)drawRect:(NSRect)rect
{
[self renderCurrentFrame];
}
and renderCurrentFrame:
- (void)renderCurrentFrame
{
if(isMeasured)
switch (measureMethod) {
case 0:
[self renderPoint:singlePoint];
break;
case 1:
[self renderPath:pathForDistanceMeasure];
break;
case 2:
[self renderPath:pathForAngleMeasure];
break;
case 3:
[self renderPath:selectedPath];
break;
default:
break;
}
[self needsDisplay];
}
and renderPoint:
- (void)renderPoint:(NSPoint)pointLoc
{
[pathForPositionMeasure appendBezierPathWithArcWithCenter: pointLoc
radius: BLOB_SIZE / 2.0
startAngle: 0.0
endAngle: 360.0];
[[NSColor blackColor] set];
[pathForPositionMeasure fill];
[[NSColor whiteColor] set];
[pathForPositionMeasure stroke];
}
and renderPath:
- (void)renderPath:(NSBezierPath *)pathForRender
{
int i = 0;
float lineDash[3];
lineDash[0] = 3.0;
lineDash[1] = 2.0;
lineDash[2] = 3.0;
for(i=0; i < [pathForRender elementCount]; i++){
NSPoint elementPoint[3];
NSBezierPathElement element;
element = [pathForRender elementAtIndex:i
associatedPoints:elementPoint];
NSBezierPath *pathPoint = [[NSBezierPath alloc] init];
[pathPoint appendBezierPathWithArcWithCenter: elementPoint[0]
radius: BLOB_SIZE / 2.0
startAngle: 0.0
endAngle: 360.0];
[[NSColor blackColor] set];
[pathPoint fill];
[[NSColor whiteColor] set];
[pathPoint stroke];
}
[[[NSColor whiteColor] colorWithAlphaComponent:0.5] set];
[pathForRender fill];
[[NSColor blackColor] set];
[pathForRender setLineWidth:1.0];
[pathForRender setLineDash:lineDash count:3 phase:0.0];
[pathForRender stroke];
}
Now I am considering the possible memory leakage in renderPath, since
each time the path will be initialized and the previous one will cause
memory leakage, which may be also the reason why I cannot get rid of
them from the view. But if so, how about the renderPoint? It seems ok
but still cannot be removed...
Thanks for any suggestions!
On Jul 22, 2008, at 9:10 PM, Jens Alfke wrote:
On 22 Jul '08, at 3:03 PM, JArod Wen wrote:
I met a problem on clearing points and paths on a customized
NSView. I set four NSBezierPath for drawing:
pathForPositionMeasure, pathForDistanceMeasure, pathForAngleMeasure
and selectedPath, and used the following code for clearing:
And the drawRect is only contained the code to draw these four
paths. But after these lines are executed, points and paths are
still there on the view. Is there any way to clear them?
I think we need to see your -drawRect: method. And where are the
four path variables declared? They're instance variables of the view
class, probably?
—Jens
---------------
JArod Wen
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden