Re: Drawing onto NSImageView subclass (Newbie)
Re: Drawing onto NSImageView subclass (Newbie)
- Subject: Re: Drawing onto NSImageView subclass (Newbie)
- From: John Harte <email@hidden>
- Date: Mon, 9 Feb 2004 21:28:52 -0500
This works.
- (void) mouseDown: (NSEvent*) event {
NSPoint eventLocation = [event locationInWindow];
NSPoint center = [self convertPoint:eventLocation fromView:nil];
if (!_points) {
_points = [[NSMutableArray alloc] init];
}
[_points addObject: [NSValue valueWithPoint: center]];
[self setNeedsDisplay: YES];
}
-(void) drawRect: (NSRect) rect {
[super drawRect:rect];
NSEnumerator* enumerator = [_points objectEnumerator];
NSValue* value;
while (value = [enumerator nextObject]) {
NSPoint p;
[value getValue: &p];
[self drawPoint: p];
}
}
- (void) drawPoint: (NSPoint) aPoint {
NSRect dotRect;
dotRect.origin.x = aPoint.x - 5.0;
dotRect.origin.y = aPoint.y - 5.0;
dotRect.size.width = 10.0;
dotRect.size.height = 10.0;
[[NSColor redColor] set];
NSBezierPath* path = [NSBezierPath bezierPathWithOvalInRect:dotRect];
[path fill];
}
@end
On Feb 9, 2004, at 7:53 PM, Alan Cook wrote:
>
> Show us your code for mouseDown: and drawRect:
>
>
Here it is. Some of the code can be moved around without any effect
>
like the [path fill] in drawRect:, but since that is actually drawing
>
it, it seemed that drawRect: would be the acceptable place to put it.
>
I also included the code for addPoint: (poorly named).
_______________________________________________
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.