• 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: 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.

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

  • Prev by Date: Re: variadic variable argument list in #define
  • Next by Date: Re: MVC question
  • Previous by thread: Re: Drawing onto NSImageView subclass (Newbie)
  • Next by thread: Re: Drawing onto NSImageView subclass (Newbie)
  • Index(es):
    • Date
    • Thread