I have a CGPath and I want to draw it once to a NSView. Seems relatively simple but I haven't found a way in AppKit (non iphone).
+1
A:
Inside -drawRect:
, You use CGContextAddPath to add it to a context, and use CGContext(Draw|Fill|Stroke)Path
to draw it. I.e. you subclass NSView, and override
- (void)drawRect:(NSRect)needsDisplayInRect
{
CGContextRef cgcontext = [[NSGraphicsContext currentContext] graphicsPort];
CGContextAddPath(cgcontext,path); // assumes you have CGPathRef*path;
CGContextStrokePath(cgcontext);
}
Then -drawRect:
will be called whenever appropriate. You can force the view to update by calling [view displayIfNeeded]
.
Yuji
2010-05-12 18:17:22
CGContextAddPath doesn't actually draw the path — you need to use CGContext{Draw|Fill|Stroke}Path for that.
Chuck
2010-05-12 18:24:24
Chuck is right. This is what I ended up doing. Just thought there would be a simpler way but I guess not.
James Van Boxtel
2010-05-12 18:34:11
You're right. I'll correct it.
Yuji
2010-05-12 18:48:38