From fdcf050747cb4cfd7e0d35a879f9468f66822566 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Fri, 29 Apr 2005 15:08:16 +0000 Subject: [PATCH] Win32: Fix Mouse.setCursorLocation() --- src/native/win32/context.c | 32 +++++++++++++-------- src/native/win32/context.h | 5 ++++ src/native/win32/org_lwjgl_input_Mouse.c | 26 +++++++++++++++-- src/native/win32/org_lwjgl_opengl_Display.c | 14 ++------- 4 files changed, 51 insertions(+), 26 deletions(-) diff --git a/src/native/win32/context.c b/src/native/win32/context.c index 8e550e89..9e85c3f1 100644 --- a/src/native/win32/context.c +++ b/src/native/win32/context.c @@ -110,18 +110,8 @@ void closeWindow(HWND *hwnd, HDC *hdc) } } -/* - * Create a window with the specified title, position, size, and - * fullscreen attribute. The window will have DirectInput associated - * with it. - * - * Returns true for success, or false for failure - */ -HWND createWindow(LPCTSTR window_class_name, int x, int y, int width, int height, bool fullscreen, bool undecorated) -{ - RECT clientSize; - int exstyle, windowflags; - HWND new_hwnd; +void getWindowFlags(DWORD *windowflags_return, DWORD *exstyle_return, bool fullscreen, bool undecorated) { + DWORD exstyle, windowflags; if (fullscreen) { exstyle = WS_EX_APPWINDOW | WS_EX_TOPMOST; windowflags = WS_POPUP; @@ -133,6 +123,24 @@ HWND createWindow(LPCTSTR window_class_name, int x, int y, int width, int height windowflags = WS_OVERLAPPED | WS_BORDER | WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU; } windowflags = windowflags | WS_CLIPCHILDREN | WS_CLIPSIBLINGS; + *windowflags_return = windowflags; + *exstyle_return = exstyle; +} + +/* + * Create a window with the specified title, position, size, and + * fullscreen attribute. The window will have DirectInput associated + * with it. + * + * Returns true for success, or false for failure + */ +HWND createWindow(LPCTSTR window_class_name, int x, int y, int width, int height, bool fullscreen, bool undecorated) +{ + RECT clientSize; + DWORD exstyle, windowflags; + HWND new_hwnd; + + getWindowFlags(&windowflags, &exstyle, fullscreen, indecorated); // If we're not a fullscreen window, adjust the height to account for the // height of the title bar (unless undecorated) diff --git a/src/native/win32/context.h b/src/native/win32/context.h index a86a54d0..0de000bd 100644 --- a/src/native/win32/context.h +++ b/src/native/win32/context.h @@ -79,6 +79,11 @@ extern void closeWindow(HWND *hwnd, HDC *hdc); */ extern HWND createDummyWindow(int x, int y); +/** + * Return appropriate window and extended style flags from the given fullscreen and undecorated property + */ +extern void getWindowFlags(DWORD *windowflags_return, DWORD *exstyle_return, bool fullscreen, bool undecorated); + /* * Create a window with the specified position, size, and * fullscreen attribute. The window will have DirectInput associated diff --git a/src/native/win32/org_lwjgl_input_Mouse.c b/src/native/win32/org_lwjgl_input_Mouse.c index ea4ec5be..24129bc9 100644 --- a/src/native/win32/org_lwjgl_input_Mouse.c +++ b/src/native/win32/org_lwjgl_input_Mouse.c @@ -354,14 +354,36 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_pollMouse(JNIEnv * env JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_setCursorPosition (JNIEnv * env, jobject self, jint x, jint y) { + DWORD windowflags, exstyle; int transformed_x, transformed_y; RECT window_rect; + RECT client_rect; + RECT adjusted_client_rect; + + int left_border_width; + int bottom_border_width; + + getWindowFlags(&windowflags, &extyle, isFullscreen, getBooleanProperty(env, "org.lwjgl.opengl.Window.undecorated")); + if (!GetClientRect(getCurrentHWND(), &client_rect)) { + printfDebugJava(env, "GetClientRect failed"); + return; + } + + adjusted_client_rect = client_rect; + if (!AdjustWindowRectEx(&adjusted_client_rect, windowflags, FALSE, exstyle)) { + printfDebugJava(env, "AdjustWindowRectEx failed"); + return; + } + if (!GetWindowRect(getCurrentHWND(), &window_rect)) { printfDebugJava(env, "GetWindowRect failed"); return; } - transformed_x = window_rect.left + x; - transformed_y = window_rect.bottom - y; + left_border_width = -adjusted_client_rect.left; + bottom_border_width = adjusted_client_rect.bottom - client_rect.bottom; + + transformed_x = window_rect.left + left_border_width + x; + transformed_y = window_rect.bottom - bottom_border_width - y; if (!SetCursorPos(transformed_x, transformed_y)) printfDebugJava(env, "SetCursorPos failed"); } diff --git a/src/native/win32/org_lwjgl_opengl_Display.c b/src/native/win32/org_lwjgl_opengl_Display.c index 3911e86f..d07b68d3 100644 --- a/src/native/win32/org_lwjgl_opengl_Display.c +++ b/src/native/win32/org_lwjgl_opengl_Display.c @@ -371,24 +371,14 @@ JNIEXPORT jobject JNICALL Java_org_lwjgl_opengl_Win32Display_init(JNIEnv *env, j } JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_reshape(JNIEnv *env, jobject self, jint x, jint y, jint width, jint height) { - int exstyle, windowflags; + DWORD exstyle, windowflags; RECT clientSize; if (isFullScreen) { return; } - if (isFullScreen) { - exstyle = WS_EX_APPWINDOW | WS_EX_TOPMOST; - windowflags = WS_POPUP; - } else if (getBooleanProperty(env, "org.lwjgl.opengl.Window.undecorated")) { - exstyle = WS_EX_APPWINDOW; - windowflags = WS_POPUP; - } else { - exstyle = WS_EX_APPWINDOW; - windowflags = WS_OVERLAPPED | WS_BORDER | WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU; - } - windowflags = windowflags | WS_CLIPCHILDREN | WS_CLIPSIBLINGS; + getWindowFlags(&windowflags, &exstyle, isFullscreen, getBooleanProperty(env, "org.lwjgl.opengl.Window.undecorated")); // If we're not a fullscreen window, adjust the height to account for the // height of the title bar: