fixed issue with win32 get x/y returning client-area coords

This commit is contained in:
Brian Matzon 2012-07-14 23:29:21 +00:00
parent 2168369bda
commit b4cc6176e7
2 changed files with 26 additions and 5 deletions

View file

@ -52,6 +52,7 @@ import org.lwjgl.opengles.EGL;
final class WindowsDisplay implements DisplayImplementation {
private static final int GAMMA_LENGTH = 256;
private static final int WM_WINDOWPOSCHANGED = 0x0047;
private static final int WM_MOVE = 0x0003;
private static final int WM_CANCELMODE = 0x001F;
private static final int WM_MOUSEMOVE = 0x0200;
@ -1012,15 +1013,22 @@ final class WindowsDisplay implements DisplayImplementation {
captureMouse = -1;
}
return 0;
case WM_MOVE:
x = (int)(short)(lParam & 0xFFFF);
y = (int)(short)(lParam >> 16);
return defWindowProc(hwnd, msg, wParam, lParam);
case WM_WINDOWPOSCHANGED:
if(getWindowRect(hwnd, rect_buffer)) {
rect.copyFromBuffer(rect_buffer);
x = rect.top;
y = rect.bottom;
} else {
LWJGLUtil.log("WM_WINDOWPOSCHANGED: Unable to get window rect");
}
return defWindowProc(hwnd, msg, wParam, lParam);
default:
return defWindowProc(hwnd, msg, wParam, lParam);
}
}
private native boolean getWindowRect(long hwnd, IntBuffer rectBuffer);
public int getX() {
return x;
}

View file

@ -199,6 +199,18 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_WindowsDisplay_clientToScreen(JNIEn
buffer[1] = point.y;
}
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_WindowsDisplay_getWindowRect(JNIEnv *env, jclass unused, jlong hwnd_int, jobject buffer_handle) {
HWND hwnd = (HWND)(INT_PTR)hwnd_int;
RECT *buffer = (RECT *)(*env)->GetDirectBufferAddress(env, buffer_handle);
jlong size = (*env)->GetDirectBufferCapacity(env, buffer_handle);
if (size < 4) {
throwFormattedRuntimeException(env, "Buffer size < 4", size);
return false;
}
return GetWindowRect(hwnd, buffer);
}
JNIEXPORT jlong JNICALL Java_org_lwjgl_opengl_WindowsDisplay_getForegroundWindow(JNIEnv *env, jclass unused) {
return (INT_PTR)GetForegroundWindow();
}
@ -509,4 +521,5 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_WindowsDisplay_nTrackMouseEvent
tme.dwFlags = TME_LEAVE;
tme.hwndTrack = hwnd;
return TrackMouseEvent(&tme);
}
}