Implement Display.getX() and Display.getY() for OS X

This commit is contained in:
kappaOne 2012-12-16 16:02:40 +00:00
parent 970fc2d7d9
commit 70842b92aa
2 changed files with 25 additions and 12 deletions

View File

@ -79,10 +79,6 @@ final class MacOSXDisplay implements DisplayImplementation {
private MacOSXNativeKeyboard keyboard;
private ByteBuffer window;
private ByteBuffer context;
private int x;
private int y;
private int width;
private int height;
private boolean close_requested;
@ -102,6 +98,10 @@ final class MacOSXDisplay implements DisplayImplementation {
private native boolean nWasResized(ByteBuffer window_handle);
private native int nGetX(ByteBuffer window_handle);
private native int nGetY(ByteBuffer window_handle);
private native int nGetWidth(ByteBuffer window_handle);
private native int nGetHeight(ByteBuffer window_handle);
@ -124,10 +124,6 @@ final class MacOSXDisplay implements DisplayImplementation {
window = nCreateWindow(x, y, mode.getWidth(), mode.getHeight(),
fullscreen, isUndecorated(), resizable,
parented, peer_handle, window);
this.x = x;
this.y = y;
this.width = mode.getWidth();
this.height = mode.getHeight();
this.canvas = parent;
if (fullscreen) {
@ -135,8 +131,8 @@ final class MacOSXDisplay implements DisplayImplementation {
skipViewportValue = true;
// if starting in fullscreen then set initial viewport to displaymode size
if (current_viewport.get(2) == 0 && current_viewport.get(3) == 0) {
current_viewport.put(2, width);
current_viewport.put(3, height);
current_viewport.put(2, mode.getWidth());
current_viewport.put(3, mode.getHeight());
}
}
} catch (LWJGLException e) {
@ -453,11 +449,11 @@ final class MacOSXDisplay implements DisplayImplementation {
}
public int getX() {
return x;
return nGetX(window);
}
public int getY() {
return y;
return nGetY(window);
}
public int getWidth() {

View File

@ -396,6 +396,23 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXDisplay_nSetResizable(JNIEnv
[window_info->window setStyleMask:style_mask];
}
JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_MacOSXDisplay_nGetX(JNIEnv *env, jobject this, jobject window_handle) {
MacOSXWindowInfo *window_info = (MacOSXWindowInfo *)(*env)->GetDirectBufferAddress(env, window_handle);
jint x = [[window_info->view window] frame].origin.x;
return x;
}
JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_MacOSXDisplay_nGetY(JNIEnv *env, jobject this, jobject window_handle) {
MacOSXWindowInfo *window_info = (MacOSXWindowInfo *)(*env)->GetDirectBufferAddress(env, window_handle);
NSRect screenRect = [[NSScreen mainScreen] frame];
NSRect winRect = [[window_info->view window] frame];
// get top corner of window frame, also flip coords so origin is in top left
jint y = screenRect.size.height - (winRect.origin.y + winRect.size.height) - 1;
return y;
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXDisplay_nSetTitle(JNIEnv *env, jobject this, jobject window_handle, jobject title_buffer) {
MacOSXWindowInfo *window_info = (MacOSXWindowInfo *)(*env)->GetDirectBufferAddress(env, window_handle);
const char *title_cstr = (const char *)(*env)->GetDirectBufferAddress(env, title_buffer);