• 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 11:56:56 -0700

On Wednesday, August 13, 2003, at 7:35 AM, Richard Chamberlain wrote:

Thanks Alastair,

On Wednesday, August 13, 2003, at 02:48 pm, Alastair J.Houghton wrote:

On Wednesday, August 13, 2003, at 12:45 pm, Richard Chamberlain wrote:

I tried drawing in the mouseDragged method but that doesn't seem to work.

This should work, but only if you remembered to do [self lockFocus] and [self unlockFocus] around your drawing. (Assuming, that is, that you're drawing in the view that received the -mouseDragged: message.)

Sorry I hadn't noticed those methods. So I've got this:

- (void)mouseDragged:(NSEvent *)event
{
NSPoint currentPoint = [self convertPoint:[event locationInWindow] fromView:nil];
NSBezierPath* path = [[NSBezierPath alloc] init];
[self lockFocus];
[[NSColor redColor] set];
[path setLineWidth: 2.0];
[path moveToPoint:lastPoint];
[path lineToPoint: currentPoint];
[path closePath];

[path stroke];
[self unlockFocus];
[lines addObject:path];
[path release];
lastPoint = currentPoint;
}

and it doesn't work :-(

Eventually the scribbles appear but not straight away for some reason. I set the drawRect code to use a different colour so I can see what is being drawn where and red lines do appear.

Any suggestions?

First suggestion: don't do any drawing in an event-handling method, and don't call -lockFocus yourself. Just update the info you need to do the drawing, and call -setNeedsDisplayInRect:.

Second suggestion: don't throw away the path every time. You can empty a path by sending it a -removeAllPoints message.

Third suggestion: check out the "cropped image" sample at:

http://developer.apple.com/samplecode/Sample_Code/Cocoa/ Cropped_Image.htm

Look at how the "LassoStyleCropMarker" was implemented.

-jcr

John C. Randolph <email@hidden> (408) 974-8819
Sr. Cocoa Software Engineer,
Apple Worldwide Developer Relations
http://developer.apple.com/cocoa/index.html
_______________________________________________
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.

  • Follow-Ups:
    • Re: scribbling
      • From: Richard Chamberlain <email@hidden>
    • Drawing while handling events (was Re: scribbling)
      • From: Fritz Anderson <email@hidden>
References: 
 >Re: scribbling (From: Richard Chamberlain <email@hidden>)

  • Prev by Date: how to change the behaviour of a document based application
  • Next by Date: Re: Backwards compatibility
  • Previous by thread: Re: scribbling
  • Next by thread: Drawing while handling events (was Re: scribbling)
  • Index(es):
    • Date
    • Thread