• 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: scribbling
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: scribbling


  • Subject: Re: scribbling
  • From: John Randolph <email@hidden>
  • Date: Wed, 13 Aug 2003 16:28:18 -0700

On Wednesday, August 13, 2003, at 3:17 PM, Richard Chamberlain wrote:

The problem with this is that compared to the lockFocus way the drawing is not smooth with gaps between each NSBezierPath. The slower you move the cursor the greater the space between each line is.

I don't really understand why this would be the case.

I've listed the code at the end of my mail in case I've missed something.

Thanks,

Richard

--

- (void)mouseDown:(NSEvent *)event
{
lastPoint = [self convertPoint:[event locationInWindow] fromView:nil];
NSLog(@"MouseDown x = %.2f, y = %.2f", lastPoint.x, lastPoint.y);
}

- (void)mouseDragged:(NSEvent *)event
{
NSPoint currentPoint = [self convertPoint:[event locationInWindow] fromView:nil];
NSBezierPath* path;
path = [[NSBezierPath alloc] init];
[path setLineWidth: 2.0];
[path moveToPoint:lastPoint];
[path lineToPoint: currentPoint];
[path closePath];
[lines addObject:path];
lastPoint = currentPoint;
[self setNeedsDisplayInRect: [path bounds]];
[path release];
}

Well, you're creating a new NSBezierPath object every time -mouseDragged: is called. Is that really what you want, or do you want to create the path in -mouseDown:, and add a point to it in -mouseDragged:?

The way I would go about this, is..

In mouseDown:, create an NSBezierPath object, tell it to moveToPoint: (current location) and add it to the "lines" array.

In mouseDragged:, send the latest path ([lines lastObject]) a lineToPoint: message.

In -drawRect: iterate over the paths in 'lines', and stroke any of them that intersect the given rect.

If you want to get fancy, you might also change the cursor in -mouseDown: and restore it in -mouseUp:.

-jcr
_______________________________________________
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: scribbling (From: Richard Chamberlain <email@hidden>)

  • Prev by Date: Re: (Possible OT) Localized variants
  • Next by Date: Re: nspopupbutton with same menu
  • Previous by thread: Re: scribbling
  • Next by thread: Re: scribbling
  • Index(es):
    • Date
    • Thread