• 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: Bezier drawing tool suggestions?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bezier drawing tool suggestions?


  • Subject: Re: Bezier drawing tool suggestions?
  • From: Scott Thompson <email@hidden>
  • Date: Sat, 4 Mar 2006 22:04:29 -0600


On Mar 3, 2006, at 2:30 PM, Dave Hersey wrote:

I'm trying to write a bezier path drawing tool in Cocoa (to draw and edit
closed shapes bounded by bezier paths), and I'm looking for some advice.


Has anyone come across a good framework, reference, sample, etc. for a
bezier shape-drawing tool? Basically what I want is to draw closed shapes
using a series of beziers and move control points, etc. to modify the
shapes. Before I write a gob of code to do this, I wanted to see what's out
there. I didn't find anything of use in the archives.

The best example I've seen is Macromedia (now Adobe) FreeHand, but I can't get to that code any more :-).


I've worked on other samples like this. One of the most convenient used a system that went something like this:

1) Create a class to represent a bezier curve. The class represents the curve as point triples. Each triple represents a "left-side" control point, an on-curve point, and a right-side control point. The class also has to deal with things like "isClosed" (though if your shapes are always closed... that could simplify things a bit.

The triplets can understand how to do things like move the BCPs so that the curve stays nice and smooth. It also lets others know when the control polygon of the curve changes

The Bezier curve class should either know how to draw itself on a view, or return a NSBezierPath representation of itself so someone else can draw it on a view.

Obviously, this is the model in the MVC world

2) Create a "manipulator" class. The manipulator class works with the view system to effect changes to the model. It hit-tests the curve handles, participates in drags, stuff like that. The manipulator can also draw itself on a view (or accept a visitor that can draw it). When drawn, the manipulator is the guy that draws the curve's handles and control polygon.

This is the controller portion

3) The view is your graph view. It is responsible for collecting events from the user and tranlsating them into commands for the manipulator. It should be able to draw the curves, and the manipulator in their respective drawing layers.

The application which used this hierarchy had a suite of graphics shapes and manipulators. The abstraction made it pretty easy to add a new type of graphic shape and the decoupling of the model from the manipulator displayed it's elegance in small, subtle ways. All in all it was an almost painfully straightforward implementation of the MVC pattern, but it worked out pretty darn well.

Scott


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: Bezier drawing tool suggestions?
      • From: "John C. Randolph" <email@hidden>
References: 
 >Bezier drawing tool suggestions? (From: Dave Hersey <email@hidden>)

  • Prev by Date: Re: NSTableView and background color
  • Next by Date: Re: NSXMLDocument question
  • Previous by thread: Re: Bezier drawing tool suggestions?
  • Next by thread: Re: Bezier drawing tool suggestions?
  • Index(es):
    • Date
    • Thread