On Aug 18, 2010, at 15:01, Brian Postow wrote:

> The two things that IKImageView gave me that I'm having trouble making 
> NSImageView do a similar thing are 1) zooming and 2) the mouse-tools.
> 
> 1) I can see how to use scaleUnitSquareToSize to zoom, but that doesn't tell 
> me the CURRENT zoom, so that if I want to, say zoom into 1-1 mode (one image 
> pixel = one screen pixel assuming 72DPI screen) or I want to know how zoomed 
> in I currently am, I can't seem to figure this out...

You'll likely do much better to track the current *desired* display scale, and 
make the image conform to that, rather than vice versa. Even if you want to 
have a "zoom to fit" function or mode, there's still a desired display factor 
derived from the ratio of the size of the image vs the size of the space you 
have to display it in.

Orthogonally, you have a choice for your 1-1 mode, whether it means 1 image 
pixel == 1 screen pixel, or 1 image point == 1 point on the display. 
Personally, I'd go for the latter, since it's going to handle display 
resolution independence better going forward. If you need the former, you can 
always add a menu function to get that scale.

> 2) I don't see how to change the mouse cursor, or make a select box, or 
> implement the grab tool... can someone point me at some sample code for this?

For changing the mouse cursor, NSTrackingArea/cursorUpdate: is the best bet. 
Selection boxes are just a matter of drawing in a view placed above your image 
view OR (probably simpler once you get into this) not using NSImageView at all, 
but a custom view that's responsible for drawing both the image and the 
selection box. Or possibly you can use CALayers, but the custom view is 
probably easier for this.

The grabber tool is harder, because you need to implement autoscroll, which 
turns out to be a lot kinkier than it seems like it ought to be.

For all of these, you might want to take a look at the Sketch sample code, but 
be aware that it originated quite a long time ago, and may still do some things 
that are easier with a more recent technology.

> Also, and this WASN'T easy on IKImageView, but with a lot of help, I got it 
> to work, but is there a trick to getting the scrollView to function? 
> Currently, I zoom in, and it doesn't make the scroll bars appear.
> 
> I made the view by creating an NSScrollView, and then changing the content 
> view of the scrollview to be NSImageView... 

If you really did that, don't. The actual "content" of the scroll view is its 
document view, not its content view. The content view is the view that clips 
the document view, and you shouldn't mess with that unnecessarily.

If you really meant to say the document view, then double check your "hides 
scrollers automatically" options in IB. Otherwise, the most likely cause is 
that you've calculated the overall size of the document view incorrectly., so 
that it *looks* right, but doesn't scroll properly.


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to