Win32: Mouse native cursor fixes
This commit is contained in:
parent
f661aaa22b
commit
d9ea16fbf7
|
@ -59,7 +59,7 @@ static bool mFirstTimeInitialization = true; // boolean to determine first time
|
||||||
|
|
||||||
static POINT cursorPos;
|
static POINT cursorPos;
|
||||||
static RECT windowRect;
|
static RECT windowRect;
|
||||||
static bool usingNativeCursor;
|
static bool mouse_grabbed;
|
||||||
static int mouseMask = DISCL_NONEXCLUSIVE | DISCL_FOREGROUND;
|
static int mouseMask = DISCL_NONEXCLUSIVE | DISCL_FOREGROUND;
|
||||||
|
|
||||||
// Function prototypes (defined in the cpp file, since header file is generic across platforms
|
// Function prototypes (defined in the cpp file, since header file is generic across platforms
|
||||||
|
@ -81,6 +81,17 @@ static void getScreenClientRect(RECT* clientRect, RECT* windowRect)
|
||||||
clientRect->right += clientRect->left;
|
clientRect->right += clientRect->left;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void resetCursorPos(void) {
|
||||||
|
/* Reset cursor position to middle of the window */
|
||||||
|
RECT clientRect;
|
||||||
|
GetWindowRect(display_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);
|
||||||
|
GetCursorPos(&cursorPos);
|
||||||
|
}
|
||||||
|
|
||||||
JNIEXPORT jboolean JNICALL Java_org_lwjgl_input_Mouse_nHasWheel(JNIEnv *, jclass) {
|
JNIEXPORT jboolean JNICALL Java_org_lwjgl_input_Mouse_nHasWheel(JNIEnv *, jclass) {
|
||||||
return mHaswheel;
|
return mHaswheel;
|
||||||
}
|
}
|
||||||
|
@ -205,22 +216,12 @@ JNIEXPORT jint JNICALL Java_org_lwjgl_input_Mouse_nRead
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Class: org_lwjgl_input_Mouse
|
|
||||||
* Method: nIsNativeCursorSupported
|
|
||||||
* Signature: ()I
|
|
||||||
*/
|
|
||||||
JNIEXPORT jint JNICALL Java_org_lwjgl_input_Mouse_nGetNativeCursorCaps
|
JNIEXPORT jint JNICALL Java_org_lwjgl_input_Mouse_nGetNativeCursorCaps
|
||||||
(JNIEnv *env, jclass clazz)
|
(JNIEnv *env, jclass clazz)
|
||||||
{
|
{
|
||||||
return org_lwjgl_input_Mouse_CURSOR_ONE_BIT_TRANSPARENCY;
|
return org_lwjgl_input_Mouse_CURSOR_ONE_BIT_TRANSPARENCY;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Class: org_lwjgl_input_Mouse
|
|
||||||
* Method: nSetNativeCursor
|
|
||||||
* Signature: (I)V
|
|
||||||
*/
|
|
||||||
JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nSetNativeCursor
|
JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nSetNativeCursor
|
||||||
(JNIEnv *env, jclass clazz, jlong cursor_handle)
|
(JNIEnv *env, jclass clazz, jlong cursor_handle)
|
||||||
{
|
{
|
||||||
|
@ -230,83 +231,52 @@ JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nSetNativeCursor
|
||||||
HCURSOR cursor = (HCURSOR)cursor_handle;
|
HCURSOR cursor = (HCURSOR)cursor_handle;
|
||||||
SetClassLong(display_hwnd, GCL_HCURSOR, (LONG)cursor);
|
SetClassLong(display_hwnd, GCL_HCURSOR, (LONG)cursor);
|
||||||
SetCursor(cursor);
|
SetCursor(cursor);
|
||||||
if (!usingNativeCursor) {
|
|
||||||
usingNativeCursor = true;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (usingNativeCursor) {
|
SetClassLong(display_hwnd, GCL_HCURSOR, (LONG)NULL);
|
||||||
SetClassLong(display_hwnd, GCL_HCURSOR, (LONG)NULL);
|
SetCursor(LoadCursor(NULL, IDC_ARROW));
|
||||||
SetCursor(LoadCursor(NULL, IDC_ARROW));
|
|
||||||
usingNativeCursor = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Class: org_lwjgl_input_Mouse
|
|
||||||
* Method: nGetMaxCursorSize
|
|
||||||
* Signature: ()I
|
|
||||||
*/
|
|
||||||
JNIEXPORT jint JNICALL Java_org_lwjgl_input_Mouse_nGetMaxCursorSize
|
JNIEXPORT jint JNICALL Java_org_lwjgl_input_Mouse_nGetMaxCursorSize
|
||||||
(JNIEnv *env, jclass clazz)
|
(JNIEnv *env, jclass clazz)
|
||||||
{
|
{
|
||||||
return GetSystemMetrics(SM_CXCURSOR);
|
return GetSystemMetrics(SM_CXCURSOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Class: org_lwjgl_input_Mouse
|
|
||||||
* Method: nGetMaxCursorSize
|
|
||||||
* Signature: ()I
|
|
||||||
*/
|
|
||||||
JNIEXPORT jint JNICALL Java_org_lwjgl_input_Mouse_nGetMinCursorSize
|
JNIEXPORT jint JNICALL Java_org_lwjgl_input_Mouse_nGetMinCursorSize
|
||||||
(JNIEnv *env, jclass clazz)
|
(JNIEnv *env, jclass clazz)
|
||||||
{
|
{
|
||||||
return GetSystemMetrics(SM_CXCURSOR);
|
return GetSystemMetrics(SM_CXCURSOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Class: org_lwjgl_input_Mouse
|
|
||||||
* Method: nDestroy
|
|
||||||
* Signature: ()V
|
|
||||||
*/
|
|
||||||
JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nDestroy(JNIEnv *env, jclass clazz) {
|
JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nDestroy(JNIEnv *env, jclass clazz) {
|
||||||
ShutdownMouse();
|
ShutdownMouse();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Class: org_lwjgl_input_Mouse
|
|
||||||
* Method: nPoll
|
|
||||||
* Signature: ()V
|
|
||||||
*/
|
|
||||||
JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nPoll(JNIEnv * env, jclass clazz, jobject coord_buffer_obj, jobject button_buffer_obj) {
|
JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nPoll(JNIEnv * env, jclass clazz, jobject coord_buffer_obj, jobject button_buffer_obj) {
|
||||||
mDIDevice->Acquire();
|
mDIDevice->Acquire();
|
||||||
UpdateMouseFields(env, clazz, coord_buffer_obj, button_buffer_obj);
|
UpdateMouseFields(env, clazz, coord_buffer_obj, button_buffer_obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Class: org_lwjgl_input_Mouse
|
|
||||||
* Method: nGrabMouse
|
|
||||||
* Signature: (Z)Z
|
|
||||||
*/
|
|
||||||
JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nGrabMouse
|
JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nGrabMouse
|
||||||
(JNIEnv * env, jclass clazz, jboolean grab) {
|
(JNIEnv * env, jclass clazz, jboolean grab) {
|
||||||
|
|
||||||
if(grab) {
|
mDIDevice->Unacquire();
|
||||||
mouseMask = DISCL_EXCLUSIVE | DISCL_FOREGROUND;
|
if(grab) {
|
||||||
ShowCursor(false);
|
if (!mouse_grabbed) {
|
||||||
} else {
|
mouse_grabbed = true;
|
||||||
mouseMask = DISCL_NONEXCLUSIVE | DISCL_FOREGROUND;
|
ShowCursor(false);
|
||||||
ShowCursor(true);
|
mouseMask = DISCL_EXCLUSIVE | DISCL_FOREGROUND;
|
||||||
|
}
|
||||||
/* Reset cursor position to middle of the window */
|
} else {
|
||||||
RECT clientRect;
|
if (mouse_grabbed) {
|
||||||
GetWindowRect(display_hwnd, &windowRect);
|
mouse_grabbed = false;
|
||||||
getScreenClientRect(&clientRect, &windowRect);
|
ShowCursor(true);
|
||||||
cursorPos.x = (clientRect.left + clientRect.right)/2;
|
mouseMask = DISCL_NONEXCLUSIVE | DISCL_FOREGROUND;
|
||||||
cursorPos.y = clientRect.bottom - 1 - (clientRect.bottom - clientRect.top)/2;
|
}
|
||||||
SetCursorPos(cursorPos.x, cursorPos.y);
|
resetCursorPos();
|
||||||
}
|
}
|
||||||
mDIDevice->Unacquire();
|
mDIDevice->Unacquire();
|
||||||
if(mDIDevice->SetCooperativeLevel(display_hwnd, mouseMask) != DI_OK) {
|
if(mDIDevice->SetCooperativeLevel(display_hwnd, mouseMask) != DI_OK) {
|
||||||
throwException(env, "Could not set the CooperativeLevel.");
|
throwException(env, "Could not set the CooperativeLevel.");
|
||||||
return;
|
return;
|
||||||
|
@ -409,14 +379,7 @@ static void SetupMouse() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mCreate_success = true;
|
mCreate_success = true;
|
||||||
|
resetCursorPos();
|
||||||
/* Reset cursor position to middle of the window */
|
|
||||||
RECT clientRect;
|
|
||||||
GetWindowRect(display_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) {
|
||||||
|
@ -488,11 +451,11 @@ static void UpdateMouseFields(JNIEnv *env, jclass clsMouse, jobject coord_buffer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (usingNativeCursor) {
|
if (mouse_grabbed) {
|
||||||
getGDICursorDelta(&dx, &dy);
|
|
||||||
} else {
|
|
||||||
dx = diMouseState.lX;
|
dx = diMouseState.lX;
|
||||||
dy = diMouseState.lY;
|
dy = diMouseState.lY;
|
||||||
|
} else {
|
||||||
|
getGDICursorDelta(&dx, &dy);
|
||||||
}
|
}
|
||||||
dy = -dy;
|
dy = -dy;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue