aboutsummaryrefslogtreecommitdiffstats
path: root/src/nativewindow/classes/jogamp
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2015-01-23 01:20:33 +0100
committerSven Gothel <[email protected]>2015-01-23 01:20:33 +0100
commit1341fe0216e4f12d7243e98290cc97824b1c0b5c (patch)
tree202dd91558731f9164e5f050b7aa9db50fc3c5b6 /src/nativewindow/classes/jogamp
parentdb775658a7f5d6614ae716b7492af8210f5e5f18 (diff)
Bug 1120 - Add OSXUtil.GetPixelScale(final RectangleImmutable r, final int[] screenIndexOut) ( Part-1 )
Diffstat (limited to 'src/nativewindow/classes/jogamp')
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java
index cf163bd82..9af74d9f5 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java
@@ -31,6 +31,8 @@ import javax.media.nativewindow.NativeWindowException;
import javax.media.nativewindow.NativeWindowFactory;
import javax.media.nativewindow.util.Insets;
import javax.media.nativewindow.util.Point;
+import javax.media.nativewindow.util.Rectangle;
+import javax.media.nativewindow.util.RectangleImmutable;
import com.jogamp.common.util.Function;
import com.jogamp.common.util.FunctionTask;
@@ -107,6 +109,58 @@ public class OSXUtil implements ToolkitProperties {
return (Insets) GetInsets0(windowOrView);
}
+ /**
+ * Returns the pixel-scale of the NSScreen, with the highest
+ * {@link RectangleImmutable#coverage(RectangleImmutable) coverage} of the given rectangle in window units.
+ * <p>
+ * If no coverage is detected the pixel-scale of the first NSScreen is returned.
+ * </p>
+ * @param r arbitrary rectangle in window units
+ * @param screenIndexOut storage returning the native screen index containing the given rectangle
+ */
+ public static double GetPixelScale(final RectangleImmutable r, final int[] screenIndexOut) {
+ if( DEBUG ) {
+ System.err.printf("GetPixelScale covering %s%n", r.toString());
+ }
+ final int screenCount;
+ final RectangleImmutable[] screenBounds;
+ final double[] pixelScales;
+ {
+ final double[] sd = GetScreenData0();
+ if( 0 != sd.length % 5 ) {
+ throw new InternalError("GetScreenData0 didn't return multiple of 5 but "+sd.length);
+ }
+ screenCount = sd.length / 5;
+ screenBounds = new RectangleImmutable[screenCount];
+ pixelScales = new double[screenCount] ;
+ for(int i=0; i<screenCount; i++) {
+ final int j = i*5;
+ pixelScales[i] = sd[j+0];
+ screenBounds[i] = new Rectangle((int)sd[j+1], (int)sd[j+2], (int)sd[j+3], (int)sd[j+4]);
+ if( DEBUG ) {
+ System.err.printf("GetPixelScale.Screen[%d]: scale %f, bounds[%f / %f %f x %f]%n",
+ i, pixelScales[i], sd[j+1], sd[j+2], sd[j+3], sd[j+4]);
+ }
+ }
+ }
+ double pixelScale = pixelScales[0];
+ screenIndexOut[0] = 0;
+ float maxCoverage = Float.MIN_VALUE;
+ for(int i=screenCount-1; i>=0; i--) {
+ final RectangleImmutable sb = screenBounds[i];
+ final float coverage = sb.coverage(r);
+ if( coverage > maxCoverage ) {
+ maxCoverage = coverage;
+ screenIndexOut[0] = i;
+ pixelScale = pixelScales[i];
+ }
+ }
+ if( DEBUG ) {
+ System.err.printf("GetPixelScale Result: screen %d, scale %f%n%n", screenIndexOut[0], pixelScale);
+ }
+ return pixelScale;
+ }
+
public static double GetPixelScale(final int screenIndex) {
return GetPixelScale0(screenIndex);
}
@@ -393,6 +447,7 @@ public class OSXUtil implements ToolkitProperties {
private static native boolean isNSWindow0(long object);
private static native Object GetLocationOnScreen0(long windowOrView, int src_x, int src_y);
private static native Object GetInsets0(long windowOrView);
+ private static native double[] GetScreenData0();
private static native double GetPixelScale0(int screenIndex);
private static native double GetPixelScale1(long windowOrView);
private static native long CreateNSWindow0(int x, int y, int width, int height);