diff --git a/src/SFML/Window/OSX/SFViewController.mm b/src/SFML/Window/OSX/SFViewController.mm index efc3c012..e2ce3ebf 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 3511d752..c572a243 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 d0bf3415..ace49d81 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.