I'm working on a project where I'm reading in a file that contains a list of coordinates that are used to define a stitch pattern for embroidery machines. Think of those machines you see at the mall that stitch names and logos on hats and t-shirts. To display the images, I created a document based application that uses each coordinate to build up a NSBezierPath and draw the image using NSBezierPath and lineToPoint. It seems pretty straight forward but there are a few wrinkles that are causing me problems so I thought I would ask for help. I tried to find some answers online with no luck so I apologize if this is basic stuff!

The first issue is the actual drawing of the lines. Since I'm trying to represent stitch patterns, I want to be able to show layers such that if one stitch crosses over another that there is some indication of which line is over the other. Think of way the laces in your shoes look, and that is the effect I am looking for. I thought I could solve it by finding a way to stroke the line with an outline but I couldn't figure out a way to do that. My first solution was to stroke the path in black a couple extra pixels wide and then to stroke the path again with a lighter color. This gave me a nice 3-D effect and was pretty close to what I wanted but it wasn't quite perfect. The problem was in the mitered ends. The stitches are typically back and forth with very narrow angles and the outline only showed up on the edges, but I really needed it to follow the full length of each stitch if that makes sense. My next solution was to create a NSBezierPath for each stitch. This solution gave me the look I wanted but I'm worried that it is a very expensive solution. Since a design can be made up of potentially tens of thousands of stitches I'm creating a huge amount of NSBezierPaths which strikes me as a problem.

The next problem is that once I've got the design drawn, I want to be able to zoom in and out and do other types of dynamic modifications of the image. For example, I may want to show or hide individual colors in the design. And of course, the image should be able to be scrolled if it is too big for the window. I had originally used -readFromURL to parse the file and store the line segments in my own internal structure. I then used -drawRect of the NSView to build the NSBezierPaths and draw the image. While this basically worked, I'm pretty sure this is the wrong way to do it. For starters, I think I'm recreating/drawing the image way too much by doing it in -drawRect. Should I be doing my drawing in -initWithFrame instead? Also, I'm struggling with zooming. Since I have all the x/y coordinates stored in an internal structure, should I be recreating the path with an appropriate scale factor? Or should I be trying to scale the created image? If I had all of the image in a single path it would be easy to transform it but how would I do it if I have thousands of paths?

Any help or suggestions would be greatly appreciated!

_______________________________________________

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