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

Re: NSBezierPath techniques?


  • Subject: Re: NSBezierPath techniques?
  • From: Thomas Lachand-Robert <email@hidden>
  • Date: Wed, 10 Apr 2002 13:43:44 +0200

Le mercredi 10 avril 2002, ` 02:18 , James G. Pengra a icrit :

I would like to draw a segmented path using mouse clicks to designate points along the path. I would like to develop the path a piece at a time by clicking at successive points in an NSView. (I'm a refugee from the old Mac ways of drawing using the Quickdraw MoveTo and LineTo commands.)

You can still do the same in Quartz, just manage to store the array of points as you prefer.

After instantiating NSBezierPath and setting the starting point, I overrode the mouseDown method to get the next point on the path and employed the method "+(void)strokeLineFromPoint:a toPoint:b" to draw the next segment, but Project Builder told me that NSBezierPath does not respond to that method, so my first question is - why not?

NSBezierPath does, but instances of it doesn't, because it's a class method. Use [myPath stroke] if you have an already build bezier path (as the name indicates, the instance stores the points of the path). [NSBezierPath strokeLineFromPoint:a toPoint:b] is a convenience method allowing you to draw lines with no bezier path instantiated.

I also tried to simply add the mouse-click point to the BezierPath and then re-stroke the whole path, even though that seems like overkill. My second question is: is it necessary to stroke the whole path just to display one more segment of the path on screen?

Obviously not. You should draw the entire path in the drawRect method for your view, though.

In the example code that I'm using as a guide, the BezierPath is "stroked" from within the "- (void)drawRect:(NSRect)rect" method. In my case I'm trying to draw from within a mouseDown method, so I suspect that I'm not getting the NSView properly focused so that draw commands can take effect, so my last question is: Can you make the drawing commands work from anywhere withing your code, or must you work through established methods like -(void)drawRect:rect?


Yes, you just have to lockFocus in your view.

Note: you should study the Sketch example, which essentially does that (and more).

Thomas Lachand-Robert
********************** email@hidden
<< Et le chemin est long du projet ` la chose. >> Molihre, Tartuffe.
_______________________________________________
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: 
 >NSBezierPath techniques? (From: "James G. Pengra" <email@hidden>)

  • Prev by Date: Re: How to make mailto: links clickable
  • Next by Date: Getting mounted network paths
  • Previous by thread: NSBezierPath techniques?
  • Next by thread: Looking for system service written in Java
  • Index(es):
    • Date
    • Thread