From b0333dfc1666d313e1e543e9fed92842dbb9912b Mon Sep 17 00:00:00 2001 From: Marco Antognini Date: Wed, 10 Oct 2012 18:53:23 +0200 Subject: [PATCH] Fix get/set window position on OS X --- src/SFML/Window/OSX/SFViewController.mm | 2 +- src/SFML/Window/OSX/SFWindowController.mm | 23 +++++++++++++++---- .../Window/OSX/WindowImplDelegateProtocol.h | 2 +- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/SFML/Window/OSX/SFViewController.mm b/src/SFML/Window/OSX/SFViewController.mm index efc3c0122..e2ce3ebf4 100644 --- a/src/SFML/Window/OSX/SFViewController.mm +++ b/src/SFML/Window/OSX/SFViewController.mm @@ -138,7 +138,7 @@ ////////////////////////////////////////////////////////. --(void)setWindowPositionToX:(unsigned int)x Y:(unsigned int)y +-(void)setWindowPositionToX:(int)x Y:(int)y { sf::err() << "Cannot move SFML area when SFML is integrated in a NSView. Use the view hanlder directly instead." << std::endl; } diff --git a/src/SFML/Window/OSX/SFWindowController.mm b/src/SFML/Window/OSX/SFWindowController.mm index 3511d752c..c572a2437 100644 --- a/src/SFML/Window/OSX/SFWindowController.mm +++ b/src/SFML/Window/OSX/SFWindowController.mm @@ -292,17 +292,30 @@ //////////////////////////////////////////////////////////// -(NSPoint)position { - NSPoint pos = [m_oglView frame].origin; + // First, get the top left corner of the view in its own base system + NSPoint const origin = [m_oglView frame].origin; + NSSize const size = [m_oglView frame].size; + NSPoint const topLeftCornerOfView = NSMakePoint(origin.x, origin.y + size.height); + NSPoint const positionInView = [m_oglView convertPointToBase:topLeftCornerOfView]; + + // Then, convert it to window base system + NSPoint const positionInWindow = [m_oglView convertPoint:positionInView toView:nil]; + // here nil denotes the window containing the view + + // Next, convert it to the screen base system + NSPoint const positionInScreen = [[m_oglView window] convertBaseToScreen:positionInWindow]; - // Flip for SFML window coordinate system. - pos.y = [self screenHeight] - pos.y; + // Finally, flip for SFML window coordinate system + // Don't forget to discard the title bar ! + NSPoint const positionInSFML = NSMakePoint(positionInScreen.x, + ([self screenHeight] - [self titlebarHeight]) - positionInScreen.y); - return pos; + return positionInSFML; } ////////////////////////////////////////////////////////. --(void)setWindowPositionToX:(unsigned int)x Y:(unsigned int)y +-(void)setWindowPositionToX:(int)x Y:(int)y { NSPoint point = NSMakePoint(x, y); diff --git a/src/SFML/Window/OSX/WindowImplDelegateProtocol.h b/src/SFML/Window/OSX/WindowImplDelegateProtocol.h index d0bf34157..ace49d819 100644 --- a/src/SFML/Window/OSX/WindowImplDelegateProtocol.h +++ b/src/SFML/Window/OSX/WindowImplDelegateProtocol.h @@ -104,7 +104,7 @@ namespace sf { /// Move the window (not the view if we handle not a window) (SFML Coordinates). /// //////////////////////////////////////////////////////////// --(void)setWindowPositionToX:(unsigned int)x Y:(unsigned int)y; +-(void)setWindowPositionToX:(int)x Y:(int)y; //////////////////////////////////////////////////////////// /// Get window's size.