[Drawkit] Changing grid snapping position of DKDrawableShape
Brad Larson
larson at sonoplot.com
Mon Nov 3 17:10:24 PST 2008
On Nov 3, 2008, at 6:44 PM, Graham Cox wrote:
>
> 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
>
I see. I had misread setOffset: and thought it was in absolute
coordinates, which you had to recalculate at each resize of the
shape. Yes, doing a [rectangle setOffset:NSMakeSize(-0.5, -0.5)] does
exactly what I was looking for.
Thanks a lot for the quick fix.
______________________
Brad Larson
SonoPlot, Inc.
3030 Laura Lane, Suite 120
Middleton, WI 53562
More information about the Drawkit
mailing list