• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Bounds questions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bounds questions


  • Subject: Re: Bounds questions
  • From: Shawn Erickson <email@hidden>
  • Date: Mon, 13 Nov 2006 08:42:30 -0800


On Nov 13, 2006, at 8:12 AM, Aychamo Aychamo wrote:

Hi Shawn,

I am using a full-screen, borderless window.  I set the window's frame
to  [[NSScreen mainScreen] frame].  I have hidden the dock and
menubar, so since my resolution is 1280x854, the window's frame rect
returns a size of 1280x854.

My window's contentView, mainView, is sized at 1280x854.  I have
designed my application (a pretty lame graphical thing) to draw itself
within this mainView (there are other subviews within my mainView).

When you say "draw itself" can you outline what you mean? It sounds like this view has a mix of NSViews and some custom drawing?


Now, what I want to do is be able to scale my mainView to fit whatever
size screen (ie, if the screen is 800x600, or 1980x1080 (or whatever
it is).

If mainView is the content view (and not some subview) then it should automatically be resized if the window gets resized. You shouldn't need to change it yourself.


I've found that I can use -setBoundsSize to scale the view.

In my application, I've tested it, and found that if I set my
resolution of my screen to 800x600, that if I use setBoundsSize(2050,
1175), my interface scales to fit the screen nicely (even though my
interface is designed to fit a 1280x854 view).  Also, I've found that
I can scale my interface to fit larger resolution monitors by setting
setBoundsSize to something smaller than 1280x854.

The numbers you outline don't make sense to me. This sounds like a bug in how you do your custom drawing (sounds like you are doing some)... some math is likely wrong down in your code. I don't think we can help more without understanding how your UI is drawn.


I guess in short, I've designed a view that goes in a full screen
window, and the view is custom designed to 1280x854, and I need to
figure out how to issue the setBoundsSize so that the view will scale
to fit whatever size screen I put it on (ie, on a larger resolution
monitor, it will get larger and fill the screen, and on a smaller
resolution monitor, it will get smaller and fill the screen.)

It should be as simple as having your custom drawing understand the bounds of the view is living in and drawing its content as needed to fill that sizing. You shouldn't have to play around with setting bounds to something other then what the content view's sizing is of your full screen window.


Now if you want your drawing to maintain a certain aspect ratio then you will have to do a little math to find which axis when fixed at the screen edge (left-right or top-bottom) results in the smallest gap for the other axis (attempting a best fit sizing for the screen). Once you find that then divide the size of the gap by two and adjust your drawings origin as needed along that axis. Once you have this rectangle (likely calculated in window/screen coordinates) you will need to convert it to view coordinates and then set your mainView frame to this rectangle.

To do that coordinate conversion use the following ...
rect = [mainView convertRect:rect fromView:nil]; //convert from window/screen to local coord.


-Shawn
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Bounds questions (From: "Aychamo Aychamo" <email@hidden>)
 >Re: Bounds questions (From: Scott Stevenson <email@hidden>)
 >Re: Re: Bounds questions (From: "Aychamo Aychamo" <email@hidden>)
 >Re: Bounds questions (From: Scott Stevenson <email@hidden>)
 >Re: Bounds questions (From: "Aychamo Aychamo" <email@hidden>)
 >Re: Bounds questions (From: Shawn Erickson <email@hidden>)
 >Re: Re: Bounds questions (From: "Aychamo Aychamo" <email@hidden>)

  • Prev by Date: Opening a closed window
  • Next by Date: Re: Re: Bounds questions
  • Previous by thread: Re: Re: Bounds questions
  • Next by thread: Re: Re: Bounds questions
  • Index(es):
    • Date
    • Thread