tags:

views:

18

answers:

1

Hey all, I have a project that I am working on and I have noticed that my NSRect that I draw at a certain x, y coordinate that would be the center for the resolution I am working on, is not the center if the resolution changes. I understand how it all works.

The Issue is that my project is going to be displayed on multiple resolutions does anyone know of a possible solution to centering the NSrect regardless of what aspect or resolution the screen is in. I have my classes declared as NSPanels that have custom drawing. Any ideas on a possible solution would be helpful. Thanks all.

This is the NSRect x, y, width, height

NSRect windowFrame = NSMakeRect(400, 500, 500, 100);

then

window = [[Mainbox alloc] initWithContentRect:windowFrame 
                                          styleMask:NSBorderlessWindowMask 
                                            backing:NSBackingStoreBuffered 
                                              defer:NO];
+2  A: 

To center one rectangle within another, set the inner rect's origin to ((the outer rect's origin plus half the outer rect's size) minus half the inner rect's size).

But, you don't need to do that.

Send your window a center message before you order it in. It'll center itself HIG-appropriately.

You may want to initialize your window with a starting rect originating at 0,0 instead of some arbitrary point, in order to ensure that, if there's a main-menu screen, that's the screen the window will consider itself to be on.

Peter Hosey
Thanks for the response. Do you have an example of what the center message format would look like? I've been going over class references to see if I could find methods to call that would center the window. I get what your saying with the origins at 0, 0 I'm just not sure what the center message would look like.
Rugluds
Nevermind lol i just passed [window center]; and it worked sort of like I expected. Thanks for the help mate.
Rugluds