From: thefiddler Date: Fri, 2 May 2014 13:13:38 +0000 (+0200) Subject: [Mac] Fixed initial window position X-Git-Tag: 2.0-0~146^2~42 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=674cd54c2942b40d230addf0a60df1d02e8d8abc;p=platform%2Fcore%2Fcsapi%2Fopentk.git [Mac] Fixed initial window position Cocoa sets the desktop origin at the bottom-left of the main screen, with +y going up. OpenTK is setting the origin at the top-left of the main screen, so we need to invert the y-axis. --- diff --git a/Source/OpenTK/Platform/MacOS/CocoaNativeWindow.cs b/Source/OpenTK/Platform/MacOS/CocoaNativeWindow.cs index 53fb296..fd662e4 100644 --- a/Source/OpenTK/Platform/MacOS/CocoaNativeWindow.cs +++ b/Source/OpenTK/Platform/MacOS/CocoaNativeWindow.cs @@ -173,7 +173,17 @@ namespace OpenTK.Platform.MacOS Class.RegisterClass(viewClass); // Create window instance - var contentRect = new System.Drawing.RectangleF(x, y, width, height); + // Note: The coordinate system of Cocoa places (0,0) at the bottom left. + // We need to get the height of the main screen and flip that in order + // to place the window at the correct position. + // Note: NSWindows are laid out relative to the main screen. + var screenRect = + Cocoa.SendRect( + Cocoa.SendIntPtr( + Cocoa.SendIntPtr(Class.Get("NSScreen"), Selector.Get("screens")), + Selector.Get("objectAtIndex:"), 0), + Selector.Get("frame")); + var contentRect = new System.Drawing.RectangleF(x, screenRect.Height - height - y, width, height); var style = GetStyleMask(windowBorder); var bufferingType = NSBackingStore.Buffered;