Re: Problems while using NSBezierPath
Re: Problems while using NSBezierPath
- Subject: Re: Problems while using NSBezierPath
- From: James Chen <email@hidden>
- Date: Sun, 28 Aug 2005 00:36:43 +0800
On Aug 27, 2005, at 3:44 AM, Shrinivasa Kini wrote:
Hi all,
I am writing a piece of software which requires making some nodes and
links on a screen.
So I am writing a subclass of NSView and creating objects of
NSBezierPath for showing my Nodes and Links (basically line between 2
points).
In the NSView subclass - which I call GraphView - I override the
drawRect:(NSRect)rect method for drawing my objects. The Nodes come up
fine, but the bezierPaths created to show the links are never
displayed in the view. Here is a snippet of my GraphView code-
- (void)drawRect:(NSRect)rect
{
if ( mode == NODEMODE )
{
NSRect r;
NSBezierPath *bp;
r = NSMakeRect(mouseLoc.x-10, mouseLoc.y-10, 20, 20);
bp = [NSBezierPath bezierPathWithOvalInRect:r];
[[NSColor blueColor] set];
[bp fill];
// That is weird here to create a node once you get a
update event.
[bezierPathArr addObject:bp];
}
else if ( mode == LINKMODE )
{
//NSBezierPath *bl = [[NSBezierPath alloc] init];
NSBezierPath *bl =[[NSBezierPath bezierPath];
//Use class method +bezierPath instead or you should
release bl at the end.
[[NSColor blackColor] set];
[NSBezierPath setDefaultLineWidth:5];
[NSBezierPath setDefaultLineJoinStyle:NSRoundLineCapStyle];
NSRect rect1 = [(NSBezierPath*)[bezierPathArr
objectAtIndex:firstSelectedBezierPath] bounds];
NSRect rect2 = [(NSBezierPath*)[bezierPathArr
objectAtIndex:secondSelectedBezierPath] bounds];
[bl moveToPoint:NSMakePoint(rect1.origin.x+30,rect1.origin.y
+30)];
[bl lineToPoint:NSMakePoint(rect2.origin.x+30,rect2.origin.y
+30)];
[bl stroke]; // you forget to draw the path.
}
}
HTH,
James
_______________________________________________
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