Fix get/set window position on OS X

This commit is contained in:
Marco Antognini 2012-10-10 18:53:23 +02:00
parent 9fac5d74dc
commit b0333dfc16
3 changed files with 20 additions and 7 deletions

View File

@ -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; sf::err() << "Cannot move SFML area when SFML is integrated in a NSView. Use the view hanlder directly instead." << std::endl;
} }

View File

@ -292,17 +292,30 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
-(NSPoint)position -(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];
// Flip for SFML window coordinate system. // Then, convert it to window base system
pos.y = [self screenHeight] - pos.y; NSPoint const positionInWindow = [m_oglView convertPoint:positionInView toView:nil];
// here nil denotes the window containing the view
return pos; // Next, convert it to the screen base system
NSPoint const positionInScreen = [[m_oglView window] convertBaseToScreen:positionInWindow];
// 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 positionInSFML;
} }
////////////////////////////////////////////////////////. ////////////////////////////////////////////////////////.
-(void)setWindowPositionToX:(unsigned int)x Y:(unsigned int)y -(void)setWindowPositionToX:(int)x Y:(int)y
{ {
NSPoint point = NSMakePoint(x, y); NSPoint point = NSMakePoint(x, y);

View File

@ -104,7 +104,7 @@ namespace sf {
/// Move the window (not the view if we handle not a window) (SFML Coordinates). /// 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. /// Get window's size.