[Drawkit] zoom to bounding box
Graham Cox
graham.cox at bigpond.com
Thu Apr 2 18:28:05 PDT 2009
On 03/04/2009, at 12:16 PM, Michael Caron wrote:
> Hi Graham,
>
> I've been looking through the DrawKit code to figure out how to zoom
> to a bounding box, or perhaps crop the drawing to the bounding box
> of the drawable objects.
>
> There's the DKDrawableObject class method,
>
> + (NSRect) unionOfBoundsOfDrawablesInArray:(NSArray*) array;
>
> and the scrollToRect:(NSRect)r method on DKDrawing, but I haven't
> found anything that would zoom to a box. Glad to add it, but being
> new to the framework I don't want to do something that's already
> done in a different way.
>
> For a use case, consider a bounding box on a group of objects with
> top left corner at (110, 130) and bottom right corner at (300, 390).
> so everything to the left of 110 on the x-axis and everything above
> 130 on the y axis (in a flipped coordinate system), is blank. I'd
> like to zoom to the bounding box so that the drawing itself is not
> resized, but the scale is set appropriately so the object collection
> is nicely centered in the view.
>
> Any tips?
>
Michael,
It sounds like what you want is the -zoomViewToRect: method
implemented by GCZoomView and inherited by DKDrawingView. This only
affects the way the drawing is presented - it doesn't alter anything
about the content of the drawing, so it's not a permanent crop, for
example.
To determine the rect bounding all possible drawables, you'll need to
examine each layer that contains drawables and find their bounds using
-unionOfAllObjectBounds (see DKObjectOwnerLayer), then union the
results from all layers. The method you mention is really a general
utility method which in this case would be slightly harder to use than
just asking each layer to tell you the bounds of its objects.
--Graham
More information about the Drawkit
mailing list