From abbc95745b69dcd7f5f84c7a56bf32947c23e74d Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Mon, 6 Jan 2020 18:16:47 +0100 Subject: Bug 1421: OSXUtil: Add GetLocation(..), simply returning the view's frame position --- .../jogamp/nativewindow/macosx/OSXUtil.java | 8 +++++ src/nativewindow/native/macosx/OSXmisc.m | 36 ++++++++++++++++++++++ 2 files changed, 44 insertions(+) (limited to 'src') diff --git a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java index e06a68953..1197f059d 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java +++ b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java @@ -115,6 +115,13 @@ public class OSXUtil implements ToolkitProperties { return 0 != object ? isNSWindow0(object) : false; } + /** + * @param windowOrView + * @return top-left client-area position in window units + */ + public static Point GetLocation(final long windowOrView) { + return (Point) GetLocation0(windowOrView); + } /** * @param windowOrView * @param src_x @@ -436,6 +443,7 @@ public class OSXUtil implements ToolkitProperties { private static native boolean initIDs0(); private static native boolean isNSView0(long object); private static native boolean isNSWindow0(long object); + private static native Object GetLocation0(long windowOrView); private static native Object GetLocationOnScreen0(long windowOrView, int src_x, int src_y); private static native Object GetInsets0(long windowOrView); private static native float GetScreenPixelScale1(int displayID); diff --git a/src/nativewindow/native/macosx/OSXmisc.m b/src/nativewindow/native/macosx/OSXmisc.m index 091b1a67e..6c13d9c05 100644 --- a/src/nativewindow/native/macosx/OSXmisc.m +++ b/src/nativewindow/native/macosx/OSXmisc.m @@ -178,6 +178,42 @@ static NSScreen * OSXUtil_getNSScreenByCGDirectDisplayID(CGDirectDisplayID displ return NULL; } +/* + * Class: Java_jogamp_nativewindow_macosx_OSXUtil + * Method: getLocation0 + * Signature: (J)Lcom/jogamp/nativewindow/util/Point; + */ +JNIEXPORT jobject JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_GetLocation0 + (JNIEnv *env, jclass unused, jlong winOrView) +{ + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + + /** + * return location in 0/0 top-left space, + * OSX is 0/0 bottom-left space naturally + */ + 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]] ) { + view = (NSView*) nsObj; + win = [view window]; + } else { + NativewindowCommon_throwNewRuntimeException(env, "neither win nor view %p\n", nsObj); + } + NSRect viewFrame = [view frame]; + + jobject res = (*env)->NewObject(env, pointClz, pointCstr, (jint)viewFrame.origin.x, (jint)viewFrame.origin.y); + + [pool release]; + + return res; +} + /* * Class: Java_jogamp_nativewindow_macosx_OSXUtil * Method: getLocationOnScreen0 -- cgit v1.2.3