Re: Drawing onto NSImageView subclass (Newbie)
Re: Drawing onto NSImageView subclass (Newbie)
- Subject: Re: Drawing onto NSImageView subclass (Newbie)
- From: Andreas Mayer <email@hidden>
- Date: Tue, 10 Feb 2004 03:02:50 +0100
Am 10.02.2004 um 01:53 schrieb Alan Cook:
Here it is.
Well, since you replace the point (center) with every click, where do
you think the other points should be stored?
I also included the code for addPoint: (poorly named).
So why didn't you rename it yet?
Replace your NSPoint center with
NSMutableArray *pointArray = [[NSMutableArray alloc] init];
Rename addPoint: to drawPoint:
Add addPoint:
- (void)addPoint:(NSPoint)newPoint
{
[pointArray addObject:[NSValue valueWithPoint:newPoint]];
}
Change mouseDown:
-(void)mouseDown:(NSEvent *)event
{
NSPoint eventLocation = [event locationInWindow];
[self addPoint:[self convertPoint:eventLocation fromView:nil]];
[self setNeedsDisplay:YES];
}
Change drawRect:
-(void)drawRect:(NSRect)rect
{
[super drawRect:rect];
NSEnumerator *enumerator = [pointArray objectEnumerator];
id value;
while (value = [enumerator nextObject]) {
[self drawPoint:[value pointValue]];
}
}
And don't forget to add the [path fill] at the end of the drawPoint:
method.
All typed in Mail - so look out for errors. :)
bye. Andreas.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.