• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Drawing onto NSImageView subclass (Newbie)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

References: 
 >Re: Drawing onto NSImageView subclass (Newbie) (From: Alan Cook <email@hidden>)

  • Prev by Date: Re: Drawing onto NSImageView subclass (Newbie)
  • Next by Date: Printing without NSPrintPanel
  • Previous by thread: Re: Drawing onto NSImageView subclass (Newbie)
  • Next by thread: Clarification: What is exatly drawing inside a thread
  • Index(es):
    • Date
    • Thread