[Drawkit] zoom to bounding box
Mike Caron
michael.r.caron at gmail.com
Fri Apr 3 07:36:47 PDT 2009
Hi Graham,
"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."
Does "slightly harder" mean less efficient? At the point of zooming, I've
already built an array containing all drawable objects in the drawing
document. At that point, it seems pretty easy, but if there's less
efficiency with getting the bounds through the array than through the layer,
I'll switch it over.
At any rate, I missed that method in the layer class, thanks for pointing it
out to me.
Your feedback has been much appreciated, Graham. Thank you!
------------------------------------------------------------
Mike Caron
http://techrad.wordpress.com
On Thu, Apr 2, 2009 at 8:28 PM, Graham Cox <graham.cox at bigpond.com> wrote:
>
> 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
>
>
> _______________________________________________
> Drawkit mailing list
> Drawkit at lists.apptree.net
> http://lists.apptree.net/listinfo.cgi/drawkit-apptree.net
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.apptree.net/pipermail/drawkit-apptree.net/attachments/20090403/303a36a1/attachment-0001.htm>
More information about the Drawkit
mailing list