diff options
author | Sven Gothel <[email protected]> | 2020-01-15 08:02:18 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2020-01-15 08:02:18 +0100 |
commit | d671b2ab3badbcfdbe0ff57f55ff997ba7bcb060 (patch) | |
tree | 8a3bb1994d69cb3b58d84e8607b9ae17c05db612 /src/nativewindow | |
parent | 9bcc384e66e40706225b86e9750c5822cb8f8c57 (diff) |
Bug 1422: Emulate DPI Scaling on non-native DPI autoscale platforms (!MacOS)
Bug 1422 shows that it seems to be desired to emulate DPI scaling where
the native toolkit does not implmement the same.
On GTK, DPIUtil.mapDPIToZoom (int dpi) reads:
double zoom = (double) dpi * 100 / 96;
int roundedZoom = (int) Math.round (zoom);
return roundedZoom;
While having dpi calculated as:
dpi = 96 * GDK.gdk_monitor_get_scale_factor(monitor);
Well, this seems to exist to allow 96 dpi fixed layout to
'look' OK on high-dpi screens.
However, you get in trouble if you layout high-dpi aware,
i.e. using percentages etc.
There is one exception: If DPIUtil.useCairoAutoScale() is true, scalingFactor is 1f
and hence the scaling emulation dropped.
'DPIUtil.setUseCairoAutoScale((sx[0]*100) == scaleFactor || OS.isGNOME);'
Diffstat (limited to 'src/nativewindow')
-rw-r--r-- | src/nativewindow/classes/com/jogamp/nativewindow/swt/SWTAccessor.java | 48 |
1 files changed, 43 insertions, 5 deletions
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/swt/SWTAccessor.java b/src/nativewindow/classes/com/jogamp/nativewindow/swt/SWTAccessor.java index b2428f7fa..0cf56c0c9 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/swt/SWTAccessor.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/swt/SWTAccessor.java @@ -29,16 +29,19 @@ package com.jogamp.nativewindow.swt; import com.jogamp.common.os.Platform; +import java.io.PrintStream; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.security.AccessController; import java.security.PrivilegedAction; +import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.GCData; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.internal.DPIUtil; import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Scrollable; import com.jogamp.nativewindow.AbstractGraphicsScreen; @@ -288,11 +291,6 @@ public class SWTAccessor { OS_gdk_window_set_background_pattern = mb; isX11GTK = isX11 && null != OS_gtk_class; - - if(DEBUG) { - System.err.println("SWTAccessor.<init>: isX11 "+isX11+", isX11GTK "+isX11GTK+" (GTK Version: "+OS_gtk_version+")"); - System.err.println("SWTAccessor.<init>: isOSX "+isOSX+", isWindows "+isWindows); - } } private static Number getIntOrLong(final long arg) { @@ -394,6 +392,46 @@ public class SWTAccessor { // // Common any toolkit // + public static void printInfo(final PrintStream out, final Display d) { + out.println("SWT: Platform: "+SWT.getPlatform()+", Version "+SWT.getVersion()); + out.println("SWT: isX11 "+isX11+", isX11GTK "+isX11GTK+" (GTK Version: "+OS_gtk_version+")"); + out.println("SWT: isOSX "+isOSX+", isWindows "+isWindows); + out.println("SWT: Display.DPI "+d.getDPI()+", DPIUtil: scalingFactor "+getScalingFactor()+", deviceZoom "+DPIUtil.getDeviceZoom()+ + ", useCairoAutoScale "+DPIUtil.useCairoAutoScale()); + } + + public static float getScalingFactor() { + final int deviceZoom = DPIUtil.getDeviceZoom(); + if ( 100 == deviceZoom || DPIUtil.useCairoAutoScale() ) { + return 1f; + } + return deviceZoom/100f; + } + public static int autoScaleUp (final int v) { + final int deviceZoom = DPIUtil.getDeviceZoom(); + if (100 == deviceZoom || DPIUtil.useCairoAutoScale()) { + return v; + } + final float scaleFactor = deviceZoom/100f; + return Math.round (v * scaleFactor); + } + public static com.jogamp.nativewindow.util.Point autoScaleUp (final com.jogamp.nativewindow.util.Point v) { + final int deviceZoom = DPIUtil.getDeviceZoom(); + if (100 == deviceZoom || DPIUtil.useCairoAutoScale() || null == v) { + return v; + } + final float scaleFactor = deviceZoom/100f; + return v.set(Math.round(v.getX() * scaleFactor), Math.round(v.getY() * scaleFactor)); + } + public static com.jogamp.nativewindow.util.Rectangle autoScaleUp (final com.jogamp.nativewindow.util.Rectangle v) { + final int deviceZoom = DPIUtil.getDeviceZoom(); + if (100 == deviceZoom || DPIUtil.useCairoAutoScale() || null == v) { + return v; + } + final float scaleFactor = deviceZoom/100f; + return v.set(Math.round(v.getX() * scaleFactor), Math.round(v.getY() * scaleFactor), + Math.round(v.getWidth() * scaleFactor), Math.round(v.getHeight() * scaleFactor)); + } /** * Returns the unscaled {@link Scrollable#getClientArea()} in pixels. |