From 19276a552e5c36a3673832f80efe21028d0db33d Mon Sep 17 00:00:00 2001 From: Marco Antognini Date: Tue, 10 Apr 2012 09:57:24 +0200 Subject: [PATCH] Improved Mac OS X implementation (Close #195) --- src/SFML/Window/OSX/SFViewController.mm | 36 ++++++++++++++++--------- src/SFML/Window/OSX/WindowImplCocoa.mm | 4 +-- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/SFML/Window/OSX/SFViewController.mm b/src/SFML/Window/OSX/SFViewController.mm index b5812162d..527748b5e 100644 --- a/src/SFML/Window/OSX/SFViewController.mm +++ b/src/SFML/Window/OSX/SFViewController.mm @@ -28,6 +28,7 @@ //////////////////////////////////////////////////////////// #import #import +#import #include #include @@ -107,7 +108,7 @@ //////////////////////////////////////////////////////// -(void)changeTitle:(NSString *)title { - sf::err() << "Cannot change the title of the view." << std::endl; + sf::err() << "Cannot change the title of the SFML area when SFML is integrated in a NSView." << std::endl; } @@ -156,7 +157,7 @@ //////////////////////////////////////////////////////// -(void)closeWindow { - sf::err() << "Cannot close the view." << std::endl; + sf::err() << "Cannot close SFML area when SFML is integrated in a NSView." << std::endl; [self setRequesterTo:0]; } @@ -198,19 +199,14 @@ //////////////////////////////////////////////////////////// -(NSPoint)position { - NSPoint pos = [m_view frame].origin; - - // Flip screen coodinates - float const screenHeight = NSHeight([[[m_view window] screen] frame]); - pos.y = screenHeight - pos.y; - - return pos; + // Origin is bottom-left corner of the window + return [m_view convertPoint:NSMakePoint(0, 0) toView:nil]; // nil means window } ////////////////////////////////////////////////////////. -(void)setWindowPositionToX:(unsigned int)x Y:(unsigned int)y { - sf::err() << "Cannot move the view." << std::endl; + sf::err() << "Cannot move SFML area when SFML is integrated in a NSView. Use the view hanlder directly instead." << std::endl; } @@ -237,14 +233,30 @@ by:(unsigned int)height with:(sf::Uint8 const *)pixels { - sf::err() << "Cannot set an icon to the view." << std::endl; + sf::err() << "Cannot set an icon when SFML is integrated in a NSView." << std::endl; } //////////////////////////////////////////////////////// -(void)processEvent { - sf::err() << "Cannot process event from the view." << std::endl; + // If we are not on the main thread we stop here and advice the user. + if ([NSThread currentThread] != [NSThread mainThread]) { + /* + * See http://lists.apple.com/archives/cocoa-dev/2011/Feb/msg00460.html + * for more information. + */ + sf::err() + << "Cannot fetch event from a worker thread. (OS X restriction)" + << std::endl; + + return; + } + + // If we don't have a requester we don't fetch event. + if (m_requester != 0) { + [SFApplication processEvent]; + } } diff --git a/src/SFML/Window/OSX/WindowImplCocoa.mm b/src/SFML/Window/OSX/WindowImplCocoa.mm index 87d47a92b..687f5b786 100644 --- a/src/SFML/Window/OSX/WindowImplCocoa.mm +++ b/src/SFML/Window/OSX/WindowImplCocoa.mm @@ -74,9 +74,7 @@ WindowImplCocoa::WindowImplCocoa(WindowHandle handle) } - // NO : - // [m_delegate setRequesterTo:this]; - // because we don't handle event. + [m_delegate setRequesterTo:this]; }