2828// //////////////////////////////////////////////////////////
2929#import < SFML/Window/OSX/SFViewController.h>
3030#import < SFML/Window/OSX/SFOpenGLView.h>
31+ #import < SFML/Window/OSX/SFApplication.h>
3132#include < SFML/System/Err.hpp>
3233#include < SFML/Window/OSX/WindowImplCocoa.hpp>
3334
@@ -107,7 +108,7 @@ -(void)setRequesterTo:(sf::priv::WindowImplCocoa *)requester
107108// //////////////////////////////////////////////////////
108109-(void )changeTitle : (NSString *)title
109110{
110- sf::err () << " Cannot change the title of the view ." << std::endl;
111+ sf::err () << " Cannot change the title of the SFML area when SFML is integrated in a NSView ." << std::endl;
111112}
112113
113114
@@ -156,7 +157,7 @@ -(void)showWindow
156157// //////////////////////////////////////////////////////
157158-(void )closeWindow
158159{
159- sf::err () << " Cannot close the view ." << std::endl;
160+ sf::err () << " Cannot close SFML area when SFML is integrated in a NSView ." << std::endl;
160161 [self setRequesterTo: 0 ];
161162}
162163
@@ -198,19 +199,14 @@ -(void)setCursorPositionToX:(unsigned int)x Y:(unsigned int)y
198199// //////////////////////////////////////////////////////////
199200-(NSPoint )position
200201{
201- NSPoint pos = [m_view frame ].origin ;
202-
203- // Flip screen coodinates
204- float const screenHeight = NSHeight ([[[m_view window ] screen ] frame ]);
205- pos.y = screenHeight - pos.y ;
206-
207- return pos;
202+ // Origin is bottom-left corner of the window
203+ return [m_view convertPoint: NSMakePoint (0 , 0 ) toView: nil ]; // nil means window
208204}
209205
210206// //////////////////////////////////////////////////////.
211207-(void )setWindowPositionToX : (unsigned int )x Y : (unsigned int )y
212208{
213- sf::err () << " Cannot move the view." << std::endl;
209+ sf::err () << " Cannot move SFML area when SFML is integrated in a NSView. Use the view hanlder directly instead ." << std::endl;
214210}
215211
216212
@@ -237,14 +233,30 @@ -(void)setIconTo:(unsigned int)width
237233 by : (unsigned int )height
238234 with : (sf::Uint8 const *)pixels
239235{
240- sf::err () << " Cannot set an icon to the view ." << std::endl;
236+ sf::err () << " Cannot set an icon when SFML is integrated in a NSView ." << std::endl;
241237}
242238
243239
244240// //////////////////////////////////////////////////////
245241-(void )processEvent
246242{
247- sf::err () << " Cannot process event from the view." << std::endl;
243+ // If we are not on the main thread we stop here and advice the user.
244+ if ([NSThread currentThread ] != [NSThread mainThread ]) {
245+ /*
246+ * See http://lists.apple.com/archives/cocoa-dev/2011/Feb/msg00460.html
247+ * for more information.
248+ */
249+ sf::err ()
250+ << " Cannot fetch event from a worker thread. (OS X restriction)"
251+ << std::endl;
252+
253+ return ;
254+ }
255+
256+ // If we don't have a requester we don't fetch event.
257+ if (m_requester != 0 ) {
258+ [SFApplication processEvent ];
259+ }
248260}
249261
250262
0 commit comments