|
From: Elias N. <eli...@us...> - 2005-04-29 15:08:31
|
Update of /cvsroot/java-game-lib/LWJGL/src/native/win32 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29229/src/native/win32 Modified Files: context.c context.h org_lwjgl_input_Mouse.c org_lwjgl_opengl_Display.c Log Message: Win32: Fix Mouse.setCursorLocation() Index: context.c =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/win32/context.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- context.c 30 Mar 2005 10:46:21 -0000 1.5 +++ context.c 29 Apr 2005 15:08:15 -0000 1.6 @@ -110,18 +110,8 @@ } } -/* - * 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 @@ 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) Index: org_lwjgl_opengl_Display.c =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/win32/org_lwjgl_opengl_Display.c,v retrieving revision 1.21 retrieving revision 1.22 diff -u -d -r1.21 -r1.22 --- org_lwjgl_opengl_Display.c 18 Apr 2005 07:31:07 -0000 1.21 +++ org_lwjgl_opengl_Display.c 29 Apr 2005 15:08:16 -0000 1.22 @@ -371,24 +371,14 @@ } 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: Index: org_lwjgl_input_Mouse.c =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/win32/org_lwjgl_input_Mouse.c,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- org_lwjgl_input_Mouse.c 12 Apr 2005 12:04:36 -0000 1.12 +++ org_lwjgl_input_Mouse.c 29 Apr 2005 15:08:16 -0000 1.13 @@ -354,14 +354,36 @@ 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"); } Index: context.h =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/win32/context.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- context.h 24 Feb 2005 13:24:08 -0000 1.2 +++ context.h 29 Apr 2005 15:08:16 -0000 1.3 @@ -79,6 +79,11 @@ */ 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 |