Re: Coordinate system question
Re: Coordinate system question
- Subject: Re: Coordinate system question
- From: email@hidden
- Date: Tue, 19 Mar 2002 14:00:25 -0800
I'm curious. Why are the coordinate systems in Cocoa based on the
bottom/left rather than top/left? Did NeXT, by default, open new
windows relative to the bottom of the screen instead of the top, since
there wasn't a menubar at the top? It seems backwards to me, because
the desktop and windows are "anchored" at the top/left and are resized
towards the bottom/right.
Well, I'd guess there are many answers here. One might be that it's
Descartes' fault, since he used a "positive Y goes upwards on the page"
system in his original treatise on what came to be the Cartesian
coordinate system, I believe. A more modern culprit would be Adobe's
PostScript implementation, which defined (0,0) as the bottom left of the
page; NeXT really just inherited that coordinate system from the Display
PostScript engine, I think.
I ask, because I recently increased my screen resolution, and now the
windows in my app open up in the middle of the screen rather than at
the top. Turns out, I modified something in IB, and it saved the
windows with the new (actually, the same, but now wrong) positions
which is not at all what I want. Is there a way to force windows in
IB to remain relative to the top/left corner?
The size inspector in IB can, I believe, be used to specify springs
and struts for window placement. Nowadays I generally make my windows
get positioned in code, though; I don't rely on the position set in IB,
because it's too common to want to move windows around while editing a
nib. I gather IB has added a "lock position" feature that addresses
this concern, but I haven't tried using it yet. Programmatic window
positioning is more precise anyway. For example:
@implementation NSWindow (WindowCentering)
- (void)centerOnScreen:(NSScreen *)screen
{
NSRect visRect = [screen visibleFrame];
NSRect currentFrame = [self frame];
[self setFrameOrigin:NSMakePoint(floor(visRect.origin.x +
(visRect.size.width - currentFrame.size.width) / 2.0),
floor(visRect.origin.y + (visRect.size.height -
currentFrame.size.height) / 1.5))];
}
@end
Good luck!
Ben Haller
Stick Software
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.