From b121cd0fc747d0587338cf5a40b83ad2e8ee7199 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Thu, 15 Jul 2004 15:53:16 +0000 Subject: [PATCH] Don't actually center cursor on setGrabbed(true) --- src/java/org/lwjgl/input/Mouse.java | 26 ++++++++++++---------- src/native/linux/org_lwjgl_input_Mouse.cpp | 3 +-- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/java/org/lwjgl/input/Mouse.java b/src/java/org/lwjgl/input/Mouse.java index d7ad718b..cfcbbb00 100644 --- a/src/java/org/lwjgl/input/Mouse.java +++ b/src/java/org/lwjgl/input/Mouse.java @@ -253,8 +253,18 @@ public class Mouse { initialized = true; } + private static void resetMouse() { + dx = dy = dwheel = 0; + width = Display.getDisplayMode().getWidth() << 16; + height = Display.getDisplayMode().getHeight() << 16; + x = width / 2; + y = height / 2; + } + /** * "Create" the mouse. The display must first have been created. + * Initially, the mouse is not grabbed and the delta values are reported + * with respect to the center of the display. * * @throws LWJGLException if the mouse could not be created for any reason */ @@ -266,11 +276,6 @@ public class Mouse { nCreate(); hasWheel = nHasWheel(); created = true; - dx = dy = dwheel = 0; - width = Display.getDisplayMode().getWidth() << 16; - height = Display.getDisplayMode().getHeight() << 16; - x = width / 2; - y = height / 2; // set mouse buttons buttonCount = nGetButtonCount(); @@ -587,9 +592,9 @@ public class Mouse { /** * Sets whether or not the mouse has grabbed the cursor - * (and thus hidden). If grab is true, and isGrabbed() is - * false, the native cursor position is reset to the middle - * of the screen. + * (and thus hidden). If grab is false, the getX() and getY() + * will return delta movement in pixels clamped to the display + * dimensions, from the center of the display. * * @param grab whether the mouse should be grabbed */ @@ -597,10 +602,7 @@ public class Mouse { isGrabbed = grab; if (isCreated()) { nGrabMouse(isGrabbed); - if(!isGrabbed) { - x = width / 2; - y = height / 2; - } + resetMouse(); } } diff --git a/src/native/linux/org_lwjgl_input_Mouse.cpp b/src/native/linux/org_lwjgl_input_Mouse.cpp index 9e5b38d5..bacd9c24 100644 --- a/src/native/linux/org_lwjgl_input_Mouse.cpp +++ b/src/native/linux/org_lwjgl_input_Mouse.cpp @@ -352,6 +352,5 @@ JNIEXPORT jint JNICALL Java_org_lwjgl_input_Mouse_nRead(JNIEnv *env, jclass claz JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nGrabMouse(JNIEnv * env, jclass clazz, jboolean new_grab) { setGrab(new_grab == JNI_TRUE ? true : false); - if (created) - doWarpPointer(); + resetCursor(getWindowWidth()/2, transformY(getWindowHeight()/2)); }