Re: NSBezierPath (Modifying Paths)
Re: NSBezierPath (Modifying Paths)
- Subject: Re: NSBezierPath (Modifying Paths)
- From: Quincey Morris <email@hidden>
- Date: Wed, 4 Feb 2009 09:59:08 -0800
On Feb 4, 2009, at 07:35, Joseph Crawford wrote:
Draw A straight line
click the line and drag to make that line curve
Now I have been able to get all of this to work aside from one
thing. If you draw a curve then go to draw another the first one is
not remembered.
Code: http://paste.lisp.org/display/74870
I know it is my call to removeAllPaths on line 59 of the code pasted
at the URL above.
I know that i need to use the elementsAtIndex: and
elementsAtIndex:index associatedPoints:points to modify the points
rather than remove them all
However what I do not know is where I would get this Index to use.
Your general approach doesn't make a lot of sense to me. 'drawRect' is
for drawing, and it's a really bad idea to be constructing parts of
your data model in that method. (In particular, drawRect can get
called multiple times without the mouse being dragged, and each time
it's going to add more points to the existing path. Not to mention the
fact that it'll add these points to *all* the paths, not just the
latest one.)
I'd suggest:
-- Keep your path array just for paths that are fully created. That
is, in mouseUp but not before, add the current path to the path array.
-- Don't bother trying to *change* the NSBezierPath object that's in
the process of being created, just create a brand new one each time
you go through mouseDragged. Performance would be the only reason not
to do this, but you're not going to have a performance problem anytime
soon. If you plan to be able to edit the paths later, then
NSBezierPath isn't the best choice as a data structure.
-- Do nothing in drawRect except drawing. If you keep the "in
progress" path out of the path array till it's done, you can also draw
it in (say) a different color, which would be a nice visual cue.
-- Change 'numberOfClicks' to something like
'numberOfControlPointsDrawn' (with values 0, 1 and 2) for clarity. The
number of clicks isn't actually important, but the number of control
points dragged out is.
While this approach to drawing paths isn't terrible, it *is* terribly
modal. If I was to draw a straight line and then wanted to draw
another path without making the first one a curve, how would do I do
that? If I started dragging out a path and wanted to get rid of it and
start a new one, how would I do that?
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden