Re: Trouble drawing a polygon...
Re: Trouble drawing a polygon...
- Subject: Re: Trouble drawing a polygon...
- From: Shawn Erickson <email@hidden>
- Date: Tue, 26 Apr 2005 13:54:10 -0700
On Apr 26, 2005, at 1:29 PM, Brian O'Brien wrote:
My first polygon! :)
But nothing is drawing....
NSPoint p;
int i;
NSBezier * path = [NSBezierPath alloc] init];
Try using the following place of the above...
NSBezierPath* path = [NSBezierPath bezierPath];
[path setLineWidth:1.0];
<<<< you don't define a starting point here likely should (moveToPoint:)
// draw first set of points. green
for (i=0; i < npoints; ++i)
{
p = [self getAPoint:i];
[path lineToPoint:p];
}
[path closePath];
[[NSColor greenColor] set];
[path stroke];
<<<< should clear the prior path points here before the below or use a
different NSBezierPath
[path removeAllPoints];
or
path = [NSBezierPath bezierPath];
// draw second set of points. red
for (i=0; i < npoints; ++i)
{
p = [self getBPoint:i];
[path lineToPoint:p];
}
[path closePath];
[[NSColor redColor] set];
[path stroke];
The following isn't needed if you use +bezierPath above.
[path dealloc];
Have I misunderstood something?
Anyway are you sure you are getting valid points back from your
getAPoint: and getBPoint:?
Also stepping back even farther... you sure your drawRect: method is
getting called?
What is the difference between this and say appendBezierPathWithPoints?
Well not much other then you can pass an buffer full of points in one
shot getting line segments between those, performance gain potentially
(and less code to manage in theory).
How do you add one point at a time with the append method?
Well what do you mean by point here?
You append points while also defining what the arc should look like
from the last end point to the new point you are adding. Normally you
use moveToPoint:, lineToPoint:, closePath:, curveToPoint:::, and
friends. Or use the various appendBezierPathWithXxx methods.
Or do you just want dots and not lines?
-Shawn
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden