Quincey,

You make some very good points. Let me first start out by saying I was doing ALL the path work in drawRect: based on someone telling me that was the best practice, I then had a few people including you tell me that is not the case.

I am not worried about performance right now that is true. I am also not worried about you drawing a curve and then wanting to draw a straight line.

This is all just messing around trying to replicate the capabilities of the curve tool in many drawing applications, I already saw how to replicate the drawing of a line and that would be a different tool to choose from.

What would you suggest I look into for wanting to modify the points?

I had this working perfectly with a tempPath for the dragging and actually had it grey in color and when it was drawn it was done so in black (the visual queue) but was told that I could do it with only one path which is why I was looking into modifying the path elements. When I have one point the dragging operation always added more and more points which led to the line being drawn with every drag and that was not the wanted solution.

Thanks,
Joseph Crawford


On Feb 4, 2009, at 12:59 PM, Quincey Morris wrote:

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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/codebowl%40gmail.com

This email sent to codeb...@gmail.com

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to