[Drawkit] Changing grid snapping position of DKDrawableShape
Graham Cox
graham.cox at bigpond.com
Mon Nov 3 16:44:29 PST 2008
On 4 Nov 2008, at 10:08 am, Brad Larson wrote:
> I have a rectangular shape and I noticed that when I drag this shape
> it snaps the center of the rectangle to the grid, not one of the
> corners. Is there a way to change the default grid snapping
> behavior of DKDrawableShapes so that I could use the upper-left-hand
> corner of the rectangle as the snapping point?
>
> I tracked this down to the setLocation: method, but I'm not sure how
> the center of the shape gets assigned to be its location or how to
> override that. I'm hoping it's something simple that I'm missing.
>
> Thanks in advance for any pointers.
Hi Brad,
The location datum of a shape is set by default to be its centre. You
can change this using -setOffset: which accepts a NSSize argument that
is in terms of the original unit rect. In other words, passing {-0.5,
-0.5} will set the origin of the shape to its top, left corner,
regardless of its actual width and height. This will affect the
snapping behaviour so you get snapping to the top, left point. It will
*also* affect the centre of rotation of the shape, so if that's not
desirable, you might prefer to set the offset on the fly only when
dragging. This isn't all that easy - you'd need to subclass, or just
modify the -mouseDraggedAtPoint:inPart:event: method in place.
any help?
Graham
More information about the Drawkit
mailing list