From 7a1dbd0d87a15f582f568a20adbbe42505bdca33 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sat, 1 Mar 2014 12:27:59 +0100 Subject: NEWT MonitorDevice: Add convenient getPixelsPerMM(..) method to retrieve the pixels-per-millimeter (Requires manual Conversion to dpi) --- .../classes/com/jogamp/newt/MonitorDevice.java | 28 +++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'src/newt/classes/com/jogamp') diff --git a/src/newt/classes/com/jogamp/newt/MonitorDevice.java b/src/newt/classes/com/jogamp/newt/MonitorDevice.java index 28d9f53a1..2d1d912c7 100644 --- a/src/newt/classes/com/jogamp/newt/MonitorDevice.java +++ b/src/newt/classes/com/jogamp/newt/MonitorDevice.java @@ -33,7 +33,7 @@ import java.util.List; import javax.media.nativewindow.util.DimensionImmutable; import javax.media.nativewindow.util.Rectangle; import javax.media.nativewindow.util.RectangleImmutable; - +import javax.media.nativewindow.util.SurfaceSize; import com.jogamp.common.util.ArrayHashSet; /** @@ -118,6 +118,32 @@ public abstract class MonitorDevice { return sizeMM; } + /** + * Stores the pixels per millimeter value according to current {@link MonitorMode} + * {@link SurfaceSize#getResolution() SurfaceSize's resolution} in the given storage ppmmStore. + *

+ * To convert the result to dpi, i.e. dots-per-inch, multiply both components with 25.4f. + *

+ */ + public final void getPixelsPerMM(final float[] ppmmStore) { + final MonitorMode mode = getCurrentMode(); + getPixelsPerMM(mode, ppmmStore); + } + + /** + * Stores the pixels per millimeter value according to the given {@link MonitorMode} + * {@link SurfaceSize#getResolution() SurfaceSize's resolution} in the given storage ppmmStore. + *

+ * To convert the result to dpi, i.e. dots-per-inch, multiply both components with 25.4f. + *

+ */ + public final void getPixelsPerMM(final MonitorMode mode, final float[] ppmmStore) { + final DimensionImmutable sdim = getSizeMM(); + final DimensionImmutable spix = mode.getSurfaceSize().getResolution(); + ppmmStore[0] = (float)spix.getWidth() / (float)sdim.getWidth(); + ppmmStore[1] = (float)spix.getHeight() / (float)sdim.getHeight(); + } + /** * Returns the immutable original {@link com.jogamp.newt.MonitorMode}, as used at NEWT initialization. *

-- cgit v1.2.3