Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Difference Between Frame Size and Bounds Size in NSView?

Difference Between Frame Size and Bounds Size in NSView?
Thread Tools
Professional Poster
Join Date: Apr 2001
Location: Long Beach, CA
Status: Offline
Reply With Quote
Aug 4, 2002, 10:14 PM
 
I know this is all in the documentation, but the documentation is so detailed that it makes very little sense. Here's my understanding from the description of certain functions:

The frame is the rectangle that defines the NSView with respect to its superview.

The bounds rect is the range of values that define that NSView's coordinate system. i.e. anything in this rectangle will actually display in the NSView.


So, if I make a small frame, put an image in it, and make the bounds the size of the image, the image will be the size of the frame. That is, if I make a big bounds rectangle, things will shrink. If I make a small bounds rectangle, things get bigger.

This is what the definition of the functions seems to imply. However, it doesn't quite seem to work that way. I've finally gotten all of my images to display properly, but I haven't figured out why what I did worked. If I set the frame size and the bounds size to be the same thing, the Image will squeeze itself inside (not what I expected). However, if I don't touch the frame size and I set the bounds size to the size of the Image, the Image displays full size in proper proportions... even if it goes outside of the NSView that I have defined.

Am I missing something important here??
(Last edited by Detrius; Aug 4, 2002 at 10:25 PM. )

ACSA 10.4/10.3, ACTC 10.3, ACHDS 10.3
     
Senior User
Join Date: Mar 2000
Location: Ithaca, NY
Status: Offline
Reply With Quote
Aug 5, 2002, 04:10 PM
 
How exactly are you drawing the image?
     
Detrius  (op)
Professional Poster
Join Date: Apr 2001
Location: Long Beach, CA
Status: Offline
Reply With Quote
Aug 6, 2002, 12:34 AM
 
[[theNSImage bestRepresentationForDevice: nil] draw]

inside of drawRect:

ACSA 10.4/10.3, ACTC 10.3, ACHDS 10.3
     
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status: Offline
Reply With Quote
Aug 6, 2002, 02:44 PM
 
So, if I make a small frame, put an image in it, and make the bounds the size of the image, the image will be the size of the frame.
I don't think so. The bounds rect doesn't effect the size of the image. Imagine there's a plane with your image on it. If your bounds rect overlaps with your image, that part of your image is displayed. The frame rect specifies two things: where in its superview (usually an NSWindow's content view, but not always) the view appears, and how big that frame is, sort of like a picture frame. The frame controls the size of what's visible, the bounds controls what is visible.

If you first have your frame, and then you draw your image inside of it, you'll only see the part of your image that fits in the default bounds (which is roughly the frame rect with an x and y coordinate of (0,0)). Setting the bounds rect to be the image size will have no visual effect if the bounds rect is larger than the frame rect, but if the bounds rect is smaller than the frame rect, then you'll end up seeing only a portion of what your drawing. In fact, try setting your bounds rect to be something like (1000,1000,100,100). My guess is your NSView won't draw anything at all. It really is, but you can't see it, because its drawing way to the right.

So, make a frame rect with the size of your image (x and y are for where in you superview you want it to appear) and set the bounds rect to be the size of your image (x and y both 0) (although I think it auto sets your bounds rect for you, but I could be mistaken). Now draw your image, and it will look fine.

If you end up changing the frame size, be wary that it autoresizes any subviews, which would explain why your NSImage sizes to fit.

I think that makes sense
Matt Fahrenbacher
     
Mac Elite
Join Date: Feb 2001
Location: Vancouver, WA
Status: Offline
Reply With Quote
Aug 6, 2002, 03:03 PM
 
Eek. Use -[NSImage drawInRect: fromRect: operation: fraction:] instead. Pass bounds for inRect and NSZeroRect for fromRect.
Rick Roe
icons.cx | weblog
     
Detrius  (op)
Professional Poster
Join Date: Apr 2001
Location: Long Beach, CA
Status: Offline
Reply With Quote
Aug 6, 2002, 11:09 PM
 
Originally posted by Rickster:
Eek. Use -[NSImage drawInRect: fromRect: operation: fraction:] instead. Pass bounds for inRect and NSZeroRect for fromRect.
OOH, very nice.

So, for everyone else out there (like me) that's a little lost at this point for what's done for the operation: field, the options are in the NSGraphics.h file in the AppKit.

Then to my NEXT question: How do I get the pictures full size? I have a few pictures that think they are 600dpi, so they don't like showing up really big when I draw them on the monitor. I can figure out a way to zoom by hand (I think by changing frame size, inside of a scroll view), but is there a way to get all images to default at on pixel in the image == one pixel on the screen?
(Last edited by Detrius; Aug 6, 2002 at 11:18 PM. )

ACSA 10.4/10.3, ACTC 10.3, ACHDS 10.3
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 06:08 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2