fixed mouse issues, setGrabbed & native cursor now works (afaik ;))
This commit is contained in:
parent
b21e4a7f93
commit
a9506354ee
|
@ -181,11 +181,10 @@ public class Mouse {
|
||||||
Cursor oldCursor = currentCursor;
|
Cursor oldCursor = currentCursor;
|
||||||
currentCursor = cursor;
|
currentCursor = cursor;
|
||||||
if (currentCursor != null) {
|
if (currentCursor != null) {
|
||||||
|
if(currentCursor != oldCursor) {
|
||||||
nSetNativeCursor(currentCursor.getHandle());
|
nSetNativeCursor(currentCursor.getHandle());
|
||||||
currentCursor.setTimeout();
|
currentCursor.setTimeout();
|
||||||
x = Window.getWidth() / 2;
|
}
|
||||||
y = Window.getHeight() / 2;
|
|
||||||
isGrabbed = false;
|
|
||||||
} else {
|
} else {
|
||||||
nSetNativeCursor(0);
|
nSetNativeCursor(0);
|
||||||
}
|
}
|
||||||
|
@ -255,6 +254,8 @@ public class Mouse {
|
||||||
created = true;
|
created = true;
|
||||||
currentCursor = null;
|
currentCursor = null;
|
||||||
dx = dy = dwheel = 0;
|
dx = dy = dwheel = 0;
|
||||||
|
x = Window.getWidth() / 2;
|
||||||
|
y = Window.getHeight() / 2;
|
||||||
|
|
||||||
// set mouse buttons
|
// set mouse buttons
|
||||||
buttonCount = nGetButtonCount();
|
buttonCount = nGetButtonCount();
|
||||||
|
@ -553,12 +554,18 @@ public class Mouse {
|
||||||
public static void setGrabbed(boolean grab) {
|
public static void setGrabbed(boolean grab) {
|
||||||
isGrabbed = grab;
|
isGrabbed = grab;
|
||||||
nGrabMouse(isGrabbed);
|
nGrabMouse(isGrabbed);
|
||||||
|
|
||||||
|
if(!grab) {
|
||||||
|
x = Window.getWidth() / 2;
|
||||||
|
y = Window.getHeight() / 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
private static native void nGrabMouse(boolean grab);
|
private static native void nGrabMouse(boolean grab);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the cursor, so that animation can be changed if needed.
|
* Updates the cursor, so that animation can be changed if needed.
|
||||||
* This method is called automatically by the window on its update.
|
* This method is called automatically by the window on its update, and
|
||||||
|
* shouldn't be called otherwise
|
||||||
*/
|
*/
|
||||||
public static void updateCursor() {
|
public static void updateCursor() {
|
||||||
if (Display.getPlatform() == Display.PLATFORM_WGL && currentCursor != null && currentCursor.hasTimedOut()) {
|
if (Display.getPlatform() == Display.PLATFORM_WGL && currentCursor != null && currentCursor.hasTimedOut()) {
|
||||||
|
|
|
@ -89,8 +89,6 @@ public class HWCursorTest {
|
||||||
|
|
||||||
glInit();
|
glInit();
|
||||||
|
|
||||||
Keyboard.create();
|
|
||||||
Mouse.create();
|
|
||||||
initNativeCursors();
|
initNativeCursors();
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -106,10 +104,6 @@ public class HWCursorTest {
|
||||||
|
|
||||||
cursor = new Cursor[3];
|
cursor = new Cursor[3];
|
||||||
|
|
||||||
// center
|
|
||||||
mouse_x = 400;
|
|
||||||
mouse_y = 300;
|
|
||||||
|
|
||||||
int cursorImageCount = 1;
|
int cursorImageCount = 1;
|
||||||
int cursorWidth = Mouse.getMaxCursorSize();
|
int cursorWidth = Mouse.getMaxCursorSize();
|
||||||
int cursorHeight = cursorWidth;
|
int cursorHeight = cursorWidth;
|
||||||
|
@ -214,6 +208,7 @@ public class HWCursorTest {
|
||||||
if (Window.isVisible()) {
|
if (Window.isVisible()) {
|
||||||
// check keyboard input
|
// check keyboard input
|
||||||
processKeyboard();
|
processKeyboard();
|
||||||
|
processMouse();
|
||||||
|
|
||||||
render();
|
render();
|
||||||
} else {
|
} else {
|
||||||
|
@ -256,28 +251,32 @@ public class HWCursorTest {
|
||||||
GL11.glPopMatrix();
|
GL11.glPopMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void processMouse() {
|
||||||
|
int dx = Mouse.getDX();
|
||||||
|
int dy = Mouse.getDY();
|
||||||
|
|
||||||
|
if (dx != 0 || dy != 0) {
|
||||||
|
//mouse_x += dx;
|
||||||
|
//mouse_y += dy;
|
||||||
|
}
|
||||||
|
mouse_x = Mouse.getX();
|
||||||
|
mouse_y = Mouse.getY();
|
||||||
|
|
||||||
|
while(Mouse.next()) {
|
||||||
|
if(Mouse.getEventButtonState() && Mouse.getEventButton() < 3) {
|
||||||
|
mouse_btn = Mouse.getEventButton();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes keyboard input
|
* Processes keyboard input
|
||||||
*/
|
*/
|
||||||
private void processKeyboard() {
|
private void processKeyboard() {
|
||||||
if (Mouse.getDX() != 0 || Mouse.getDY() != 0) {
|
|
||||||
mouse_x += Mouse.getDX() / 2;
|
|
||||||
mouse_y += Mouse.getDY() / 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(Mouse.isButtonDown(0)) {
|
|
||||||
mouse_btn = 0;
|
|
||||||
} else if(Mouse.isButtonDown(1)) {
|
|
||||||
mouse_btn = 1;
|
|
||||||
} else if(Mouse.isButtonDown(2)) {
|
|
||||||
mouse_btn = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
//check for fullscreen key
|
//check for fullscreen key
|
||||||
if (Keyboard.isKeyDown(Keyboard.KEY_F)) {
|
if (Keyboard.isKeyDown(Keyboard.KEY_F)) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Keyboard.destroy();
|
|
||||||
try {
|
try {
|
||||||
Mouse.setNativeCursor(null);
|
Mouse.setNativeCursor(null);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -287,7 +286,6 @@ public class HWCursorTest {
|
||||||
for(int i=0; i<cursor.length; i++) {
|
for(int i=0; i<cursor.length; i++) {
|
||||||
cursor[i].destroy();
|
cursor[i].destroy();
|
||||||
}
|
}
|
||||||
Mouse.destroy();
|
|
||||||
Window.destroy();
|
Window.destroy();
|
||||||
|
|
||||||
Display.setDisplayMode(mode);
|
Display.setDisplayMode(mode);
|
||||||
|
@ -295,7 +293,6 @@ public class HWCursorTest {
|
||||||
|
|
||||||
glInit();
|
glInit();
|
||||||
|
|
||||||
Keyboard.create();
|
|
||||||
initNativeCursors();
|
initNativeCursors();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -305,7 +302,6 @@ public class HWCursorTest {
|
||||||
//check for window key
|
//check for window key
|
||||||
if (Keyboard.isKeyDown(Keyboard.KEY_W)) {
|
if (Keyboard.isKeyDown(Keyboard.KEY_W)) {
|
||||||
try {
|
try {
|
||||||
Keyboard.destroy();
|
|
||||||
try {
|
try {
|
||||||
Mouse.setNativeCursor(null);
|
Mouse.setNativeCursor(null);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -315,7 +311,6 @@ public class HWCursorTest {
|
||||||
for(int i=0; i<cursor.length; i++) {
|
for(int i=0; i<cursor.length; i++) {
|
||||||
cursor[i].destroy();
|
cursor[i].destroy();
|
||||||
}
|
}
|
||||||
Mouse.destroy();
|
|
||||||
Window.destroy();
|
Window.destroy();
|
||||||
|
|
||||||
Display.resetDisplayMode();
|
Display.resetDisplayMode();
|
||||||
|
@ -323,7 +318,6 @@ public class HWCursorTest {
|
||||||
|
|
||||||
glInit();
|
glInit();
|
||||||
|
|
||||||
Keyboard.create();
|
|
||||||
initNativeCursors();
|
initNativeCursors();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -340,16 +334,18 @@ public class HWCursorTest {
|
||||||
|
|
||||||
if (Keyboard.isKeyDown(Keyboard.KEY_N)) {
|
if (Keyboard.isKeyDown(Keyboard.KEY_N)) {
|
||||||
try {
|
try {
|
||||||
cursor[mouse_btn].resetAnimation();
|
|
||||||
Mouse.setNativeCursor(cursor[mouse_btn]);
|
Mouse.setNativeCursor(cursor[mouse_btn]);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Keyboard.isKeyDown(Keyboard.KEY_SPACE)) {
|
while(Keyboard.next()) {
|
||||||
|
if(Keyboard.getEventKey() == Keyboard.KEY_SPACE && Keyboard.getEventKeyState()) {
|
||||||
Mouse.setGrabbed(!Mouse.isGrabbed());
|
Mouse.setGrabbed(!Mouse.isGrabbed());
|
||||||
System.out.println("Grabbed: " + Mouse.isGrabbed());
|
//mouse_x = Mouse.getX();
|
||||||
|
//mouse_y = Mouse.getY();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -357,7 +353,6 @@ public class HWCursorTest {
|
||||||
* Cleans up the test
|
* Cleans up the test
|
||||||
*/
|
*/
|
||||||
private void cleanup() {
|
private void cleanup() {
|
||||||
Keyboard.destroy();
|
|
||||||
try {
|
try {
|
||||||
Mouse.setNativeCursor(null);
|
Mouse.setNativeCursor(null);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -367,7 +362,6 @@ public class HWCursorTest {
|
||||||
for(int i=0; i<cursor.length; i++) {
|
for(int i=0; i<cursor.length; i++) {
|
||||||
cursor[i].destroy();
|
cursor[i].destroy();
|
||||||
}
|
}
|
||||||
Mouse.destroy();
|
|
||||||
Display.resetDisplayMode();
|
Display.resetDisplayMode();
|
||||||
Window.destroy();
|
Window.destroy();
|
||||||
}
|
}
|
||||||
|
|
|
@ -238,26 +238,31 @@ public class MouseTest {
|
||||||
private void updateState() {
|
private void updateState() {
|
||||||
direction = -1;
|
direction = -1;
|
||||||
|
|
||||||
|
int dx = Mouse.getDX();
|
||||||
|
int dy = Mouse.getDY();
|
||||||
|
int dw = Mouse.getDWheel();
|
||||||
|
|
||||||
|
|
||||||
// get out if no movement
|
// get out if no movement
|
||||||
if (Mouse.getDX() == Mouse.getDY() && Mouse.getDX() == 0 && Mouse.getDWheel() == 0) {
|
if (dx == dy && dx == 0 && dw == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// determine direction moved
|
// determine direction moved
|
||||||
// ============================
|
// ============================
|
||||||
if(Mouse.getDX() > 0) {
|
if(dx > 0) {
|
||||||
direction = 3;
|
direction = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Mouse.getDX() < 0) {
|
if(dx < 0) {
|
||||||
direction = 1;
|
direction = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Mouse.getDY() > 0) {
|
if(dy > 0) {
|
||||||
direction = 0;
|
direction = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Mouse.getDY() < 0) {
|
if(dy < 0) {
|
||||||
direction = 2;
|
direction = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -287,11 +292,11 @@ public class MouseTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
// get direction to update in
|
// get direction to update in
|
||||||
if (Mouse.getDWheel() > 0) {
|
if (dw > 0) {
|
||||||
lastScrollDirection++;
|
lastScrollDirection++;
|
||||||
} else if (Mouse.getDWheel() < 0) {
|
} else if (dw < 0) {
|
||||||
lastScrollDirection--;
|
lastScrollDirection--;
|
||||||
} else if (Mouse.getDWheel() == 0) {
|
} else if (dw == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -313,15 +318,18 @@ public class MouseTest {
|
||||||
* Handles the keyboard
|
* Handles the keyboard
|
||||||
*/
|
*/
|
||||||
private void handleKeyboard() {
|
private void handleKeyboard() {
|
||||||
|
|
||||||
|
while(Keyboard.next()) {
|
||||||
// closing on ESCAPE
|
// closing on ESCAPE
|
||||||
if(Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) {
|
if(Keyboard.getEventKey() == Keyboard.KEY_ESCAPE && Keyboard.getEventKeyState()) {
|
||||||
closing = true;
|
closing = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Keyboard.isKeyDown(Keyboard.KEY_SPACE)) {
|
if(Keyboard.getEventKey() == Keyboard.KEY_SPACE && Keyboard.getEventKeyState()) {
|
||||||
Mouse.setGrabbed(!Mouse.isGrabbed());
|
Mouse.setGrabbed(!Mouse.isGrabbed());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Does the "model logic"
|
* Does the "model logic"
|
||||||
|
|
|
@ -227,32 +227,13 @@ JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nSetNativeCursor
|
||||||
SetClassLong(hwnd, GCL_HCURSOR, (LONG)cursor);
|
SetClassLong(hwnd, GCL_HCURSOR, (LONG)cursor);
|
||||||
SetCursor(cursor);
|
SetCursor(cursor);
|
||||||
if (!usingNativeCursor) {
|
if (!usingNativeCursor) {
|
||||||
mDIDevice->Unacquire();
|
|
||||||
if(mDIDevice->SetCooperativeLevel(hwnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND) != DI_OK) {
|
|
||||||
throwException(env, "Could not set the CooperativeLevel.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
/* Reset cursor position to middle of the window */
|
|
||||||
RECT clientRect;
|
|
||||||
GetWindowRect(hwnd, &windowRect);
|
|
||||||
getScreenClientRect(&clientRect, &windowRect);
|
|
||||||
cursorPos.x = (clientRect.left + clientRect.right)/2;
|
|
||||||
cursorPos.y = clientRect.bottom - 1 - (clientRect.bottom - clientRect.top)/2;
|
|
||||||
SetCursorPos(cursorPos.x, cursorPos.y);
|
|
||||||
usingNativeCursor = true;
|
usingNativeCursor = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (usingNativeCursor) {
|
if (usingNativeCursor) {
|
||||||
SetClassLong(hwnd, GCL_HCURSOR, (LONG)NULL);
|
SetClassLong(hwnd, GCL_HCURSOR, (LONG)NULL);
|
||||||
SetCursor(LoadCursor(NULL, IDC_ARROW));
|
SetCursor(LoadCursor(NULL, IDC_ARROW));
|
||||||
mDIDevice->Unacquire();
|
|
||||||
if(mDIDevice->SetCooperativeLevel(hwnd, mouseMask) != DI_OK) {
|
|
||||||
throwException(env, "Could not set the CooperativeLevel.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
usingNativeCursor = false;
|
usingNativeCursor = false;
|
||||||
mDIDevice->Acquire();
|
|
||||||
ShowCursor(TRUE);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -308,8 +289,18 @@ JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nGrabMouse
|
||||||
|
|
||||||
if(grab) {
|
if(grab) {
|
||||||
mouseMask = DISCL_EXCLUSIVE | DISCL_FOREGROUND;
|
mouseMask = DISCL_EXCLUSIVE | DISCL_FOREGROUND;
|
||||||
|
ShowCursor(false);
|
||||||
} else {
|
} else {
|
||||||
mouseMask = DISCL_NONEXCLUSIVE | DISCL_FOREGROUND;
|
mouseMask = DISCL_NONEXCLUSIVE | DISCL_FOREGROUND;
|
||||||
|
ShowCursor(true);
|
||||||
|
|
||||||
|
/* Reset cursor position to middle of the window */
|
||||||
|
RECT clientRect;
|
||||||
|
GetWindowRect(hwnd, &windowRect);
|
||||||
|
getScreenClientRect(&clientRect, &windowRect);
|
||||||
|
cursorPos.x = (clientRect.left + clientRect.right)/2;
|
||||||
|
cursorPos.y = clientRect.bottom - 1 - (clientRect.bottom - clientRect.top)/2;
|
||||||
|
SetCursorPos(cursorPos.x, cursorPos.y);
|
||||||
}
|
}
|
||||||
mDIDevice->Unacquire();
|
mDIDevice->Unacquire();
|
||||||
if(mDIDevice->SetCooperativeLevel(hwnd, mouseMask) != DI_OK) {
|
if(mDIDevice->SetCooperativeLevel(hwnd, mouseMask) != DI_OK) {
|
||||||
|
@ -408,6 +399,14 @@ void SetupMouse() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mCreate_success = true;
|
mCreate_success = true;
|
||||||
|
|
||||||
|
/* Reset cursor position to middle of the window */
|
||||||
|
RECT clientRect;
|
||||||
|
GetWindowRect(hwnd, &windowRect);
|
||||||
|
getScreenClientRect(&clientRect, &windowRect);
|
||||||
|
cursorPos.x = (clientRect.left + clientRect.right)/2;
|
||||||
|
cursorPos.y = clientRect.bottom - 1 - (clientRect.bottom - clientRect.top)/2;
|
||||||
|
SetCursorPos(cursorPos.x, cursorPos.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cap(int val, int min, int max) {
|
static int cap(int val, int min, int max) {
|
||||||
|
@ -487,6 +486,7 @@ static void UpdateMouseFields(JNIEnv *env, jclass clsMouse, jobject coord_buffer
|
||||||
coords[0] = dx;
|
coords[0] = dx;
|
||||||
coords[1] = dy;
|
coords[1] = dy;
|
||||||
coords[2] = diMouseState.lZ;
|
coords[2] = diMouseState.lZ;
|
||||||
|
|
||||||
for (int i = 0; i < mButtoncount; i++) {
|
for (int i = 0; i < mButtoncount; i++) {
|
||||||
if (diMouseState.rgbButtons[i] != 0) {
|
if (diMouseState.rgbButtons[i] != 0) {
|
||||||
diMouseState.rgbButtons[i] = JNI_TRUE;
|
diMouseState.rgbButtons[i] = JNI_TRUE;
|
||||||
|
|
Loading…
Reference in New Issue