Don't actually center cursor on setGrabbed(true)

This commit is contained in:
Elias Naur 2004-07-15 15:53:16 +00:00
parent 04c6671d23
commit b121cd0fc7
2 changed files with 15 additions and 14 deletions

View File

@ -253,8 +253,18 @@ public class Mouse {
initialized = true; 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. * "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 * @throws LWJGLException if the mouse could not be created for any reason
*/ */
@ -266,11 +276,6 @@ public class Mouse {
nCreate(); nCreate();
hasWheel = nHasWheel(); hasWheel = nHasWheel();
created = true; 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 // set mouse buttons
buttonCount = nGetButtonCount(); buttonCount = nGetButtonCount();
@ -587,9 +592,9 @@ public class Mouse {
/** /**
* Sets whether or not the mouse has grabbed the cursor * Sets whether or not the mouse has grabbed the cursor
* (and thus hidden). If grab is true, and isGrabbed() is * (and thus hidden). If grab is false, the getX() and getY()
* false, the native cursor position is reset to the middle * will return delta movement in pixels clamped to the display
* of the screen. * dimensions, from the center of the display.
* *
* @param grab whether the mouse should be grabbed * @param grab whether the mouse should be grabbed
*/ */
@ -597,10 +602,7 @@ public class Mouse {
isGrabbed = grab; isGrabbed = grab;
if (isCreated()) { if (isCreated()) {
nGrabMouse(isGrabbed); nGrabMouse(isGrabbed);
if(!isGrabbed) { resetMouse();
x = width / 2;
y = height / 2;
}
} }
} }

View File

@ -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) { JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nGrabMouse(JNIEnv * env, jclass clazz, jboolean new_grab) {
setGrab(new_grab == JNI_TRUE ? true : false); setGrab(new_grab == JNI_TRUE ? true : false);
if (created) resetCursor(getWindowWidth()/2, transformY(getWindowHeight()/2));
doWarpPointer();
} }