Implement OS X Mouse.setCursorPosition() when in fullscreen mode

This commit is contained in:
kappaOne 2012-12-09 22:12:02 +00:00
parent 2a820ed94f
commit ccf738dfaf
3 changed files with 21 additions and 9 deletions

View File

@ -334,7 +334,7 @@ final class MacOSXDisplay implements DisplayImplementation {
public void setCursorPosition(int x, int y) {
if (mouse != null) {
mouse.warpCursor(x, y);
mouse.setCursorPosition(x, y);
}
//MacOSXMouseEventQueue.nWarpCursor(x, y);
}

View File

@ -80,7 +80,7 @@ final class MacOSXNativeMouse extends EventQueue {
this.window_handle = window_handle;
}
private native void nWarpCursor(ByteBuffer window_handle, int x, int y);
private native void nSetCursorPosition(ByteBuffer window_handle, int x, int y);
public static native void nGrabMouse(boolean grab);
@ -92,8 +92,8 @@ final class MacOSXNativeMouse extends EventQueue {
nRegisterMouseListener(window_handle);
}
public synchronized void warpCursor(int x, int y) {
nWarpCursor(window_handle, x, y);
public synchronized void setCursorPosition(int x, int y) {
nSetCursorPosition(window_handle, x, y);
}
public synchronized void unregister() {

View File

@ -55,13 +55,25 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXNativeMouse_nGrabMouse(JNIEnv
CGDisplayShowCursor(kCGDirectMainDisplay);
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXNativeMouse_nWarpCursor(JNIEnv *env, jclass this, jobject window_handle, jint x, jint y) {
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXNativeMouse_nSetCursorPosition(JNIEnv *env, jclass this, jobject window_handle, jint x, jint y) {
MacOSXWindowInfo *window_info = (MacOSXWindowInfo *)(*env)->GetDirectBufferAddress(env, window_handle);
NSPoint point = NSMakePoint(x, y);
point = [window_info->view convertPoint:point fromView:window_info->view];
CGPoint p;
p.x = point.x;
p.y = point.y;
if (window_info->fullscreen) {
NSSize screenSize = [[NSScreen mainScreen] frame].size;
NSSize displaySize = window_info->display_rect.size;
p.x = (screenSize.width / displaySize.width) * x;
p.y = (screenSize.height / displaySize.height) * y;
}
else {
NSPoint point = NSMakePoint(x, y);
p.x = point.x;
p.y = point.y;
}
CGWarpMouseCursorPosition(p);
}