summaryrefslogtreecommitdiffstats
path: root/src/nativewindow
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2011-10-12 02:58:57 +0200
committerSven Gothel <[email protected]>2011-10-12 02:58:57 +0200
commitdde34c4961822fb5551730331dbcbe713ef73044 (patch)
treee6ab5b4b8e55f5a5d9c13e37f3e04035b2ccca48 /src/nativewindow
parentf74e98c9471cd08573ac656a39eeaf09bdf4b24e (diff)
Fix Nativewindow GetLocationOnScreen OSX impl. - Transform OSX origin bottom-left to our top-left origin.
Diffstat (limited to 'src/nativewindow')
-rw-r--r--src/nativewindow/native/macosx/OSXmisc.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/nativewindow/native/macosx/OSXmisc.c b/src/nativewindow/native/macosx/OSXmisc.c
index 24cb8d48f..46a853844 100644
--- a/src/nativewindow/native/macosx/OSXmisc.c
+++ b/src/nativewindow/native/macosx/OSXmisc.c
@@ -76,30 +76,41 @@ Java_jogamp_nativewindow_macosx_OSXUtil_initIDs0(JNIEnv *env, jclass _unused) {
JNIEXPORT jobject JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_GetLocationOnScreen0
(JNIEnv *env, jclass unused, jlong winOrView, jint src_x, jint src_y)
{
+ /**
+ * return location in 0/0 top-left space,
+ * OSX is 0/0 bottom-left space naturally
+ */
+ NSScreen* screen = [NSScreen mainScreen];
+ NSRect screenRect = [screen frame];
+
NSRect r;
int dest_x=-1;
int dest_y=-1;
NSObject *nsObj = (NSObject*) ((intptr_t) winOrView);
NSWindow* win = NULL;
+ NSView* view = NULL;
if( [nsObj isKindOfClass:[NSWindow class]] ) {
win = (NSWindow*) nsObj;
+ view = [win contentView];
} else if( nsObj != NULL && [nsObj isKindOfClass:[NSView class]] ) {
- NSView* view = (NSView*) nsObj;
+ view = (NSView*) nsObj;
win = [view window];
} else {
NativewindowCommon_throwNewRuntimeException(env, "neither win not view %p\n", nsObj);
}
+ NSRect viewFrame = [view frame];
+
r.origin.x = src_x;
- r.origin.y = src_x;
+ r.origin.y = viewFrame.size.height - src_y; // y-flip for 0/0 top-left
r.size.width = 0;
r.size.height = 0;
// NSRect rS = [win convertRectToScreen: r]; // 10.7
NSPoint oS = [win convertBaseToScreen: r.origin];
dest_x = (int) oS.x;
- dest_y = (int) oS.y;
+ dest_y = (int) screenRect.origin.y + screenRect.size.height - oS.y;
return (*env)->NewObject(env, pointClz, pointCstr, (jint)dest_x, (jint)dest_y);
}