1
Window / sf::Window::SetCursorPosition in OSX troubles
« on: May 16, 2011, 10:11:13 pm »
I believe I've solved the issue now by changing the source code for WindowImplCocoa::SetCursorPosition() and compiling it myself on a virtual OS X install. I managed to get my friend to test it for me on his native OS X and according to him the function works as intended, only now it doesn't cause the cursor to freeze momentarily.
I'm not sure if the call to CGSetLocalEventsSuppressionInterval() is necessary because I forgot to ask my friend to test the code without that.
Thanks Ceylo for your advice to use CGWarpMouseCursorPosition()!
FPS mouse controlled camera in OS X with SFML! Hurray!
Code: [Select]
void WindowImplCocoa::SetCursorPosition(unsigned int Left, unsigned int Top)
{
NSPoint pos = NSMakePoint ((float) Left, (float) Top);
if (myWrapper) {
// Flip for SFML window coordinate system
pos.y = [[myWrapper window] frame].size.height - pos.y;
// Adjust for view reference instead of window
pos.y -= [[myWrapper window] frame].size.height - [[myWrapper view] frame].size.height;
// Convert to screen coordinates
NSPoint absolute = [[myWrapper window] convertBaseToScreen:pos];
// Flip screen coodinates
absolute.y = [[NSScreen mainScreen] frame].size.height - absolute.y;
// Move cursor
CGSetLocalEventsSuppressionInterval(0);
CGWarpMouseCursorPosition(CGPointMake(absolute.x, absolute.y));
}
}
I'm not sure if the call to CGSetLocalEventsSuppressionInterval() is necessary because I forgot to ask my friend to test the code without that.
Thanks Ceylo for your advice to use CGWarpMouseCursorPosition()!
FPS mouse controlled camera in OS X with SFML! Hurray!