Skip to content

Commit 19276a5

Browse files
committed
Improved Mac OS X implementation (Close SFML#195)
1 parent be7bcae commit 19276a5

2 files changed

Lines changed: 25 additions & 15 deletions

File tree

src/SFML/Window/OSX/SFViewController.mm

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
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

src/SFML/Window/OSX/WindowImplCocoa.mm

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,7 @@
7474

7575
}
7676

77-
// NO :
78-
// [m_delegate setRequesterTo:this];
79-
// because we don't handle event.
77+
[m_delegate setRequesterTo:this];
8078
}
8179

8280

0 commit comments

Comments
 (0)