Win32: Fix Mouse.setCursorLocation()

This commit is contained in:
Elias Naur 2005-04-29 15:08:16 +00:00
parent 019a1418c6
commit fdcf050747
4 changed files with 51 additions and 26 deletions

View File

@ -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)

View File

@ -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

View File

@ -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");
}

View File

@ -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: