Re: Rects and points...
Re: Rects and points...
- Subject: Re: Rects and points...
- From: "John C. Randolph" <email@hidden>
- Date: Tue, 20 Nov 2001 12:20:49 -0800
On Tuesday, November 20, 2001, at 07:16 AM, Riccardo Santato wrote:
>
Hi there.
>
I'd reaally like someone of you help me in making this code work.
>
I'm just having fun with Bezier curves, but nothing is displayed... Can
>
you tell me please where are the errors ?
1) You haven't implemented -drawRect:. The -drawRect: method that you
inherit from NSView doesn't do anything.
2) You create a path, but never draw it. Read the NSBezierPath
documentation for the -stroke and -fill methods.
3) You don't need the convertPoint:toView: calls. That method is
typically used for translating the location of mouse events (for
example) to your view's coordinate space.
Try it like this:
@implementation myView
- (id)initWithFrame:(NSRect)frame
{
[super initWithFrame:frameRect];
curve = [[NSBezierPath bezierPath] retain];
[curve moveToPoint:NSMakePoint(0.0, 0.0)];
[curve lineToPoint:NSMakePoint(100.0, 100.0)];
[curve lineToPoint:NSMakePoint(50.0,50.0)];
return self;
}
- (void) drawRect:(NSRect) rect
{
[[NSColor whiteColor] set];
NSRectFill(rect);
[[NSColor blackColor] set];
[curve stroke];
}
- (void) dealloc
{
if (curve)
[curve release];
[super dealloc];
}
@end
I almost had a psychic girlfriend, but she left me before we met. --
Steven Wright