[Drawkit] Drawkit Digest, Vol 9, Issue 1

Graham Cox graham.cox at bigpond.com
Thu Nov 6 16:16:33 PST 2008


On 6 Nov 2008, at 5:20 pm, Bill Monk wrote:

> Hi. I've been following this list with interest since its inception,  
> but have only now had a chance to use DrawKit in a project.
>
> I'd like to use it as a rather basic "polygon editor" for four  
> NSPoints supplied by the user. Using DrawkitSimplerDemo, I've got a  
> window up which works fine. (Fine? It works great! The number of  
> features is amazing - most of my work was in removing things not  
> required but this simple editor.)
>
> What I need to do now is
> 1) programmatically create an initial polygon from the supplied  
> points users.
> 2) When the window closes, I need to get the (possibly edited)  
> points back out.



Hi Bill,

This should be straightforward. Essentially what you need to do is:

a) create a drawable object from your points. If you want to be able  
to freely adjust the points, use DKDrawablePath. If you want to keep  
the shape the same and just scale it, rotate it, etc. as a unit, use  
DKDrawableShape.

b) add the object to the drawing in a drawing layer (by default a  
suitable layer is created for you)

c) let the user manipulate the object.

d) as needed, extract the points you want.

For parts a) and d), you can most easily use NSBezierPath - form a  
path from the points you have then use that to initialise the object.  
To get the points back, use [theObject renderingPath] to get the  
object's path and then you can get the points using the usual Cocoa  
methods. Methods of DKDrawing (which also inherits from DKLayerGroup)  
can be used to access the layer that contains the object, and of  
course it's probably easiest to retain a reference to it in your  
controller as well.

Unless you subclass one of the standard drawable classes, you won't  
find existing properties such as 'topLeft' and so on. Instead each  
drawable maintains a path using NSBezierPath which stores the points  
in the standard way. Of course you could subclass to add these  
properties or add them using a category on one of the standard objects.

You don't need to set the polygon tool at any time. The tool is only  
used when creating new shapes/paths interactively. When manipulating  
the points of an existing shape, the select/edit tool is used and that  
is set by default.


hth,


Graham


More information about the Drawkit mailing list