From cfc35549810d3a0fb5eeb866c9450417e48cd8a1 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Tue, 31 Jan 2023 04:49:43 +0100 Subject: NEWT Soft-PixelScale (p1): WindowImpl: Separate window and pixel units for size and position via atomic-replacable int arrays NEWT's Soft-PixelScale supports software pixel-scale by multiplying the underlying surface pixel-size with the scale-factor and dividing the window position and size by same scale-factor. Hence the window position and size space is kept virtually steady at virtually assumed DPI 96 at higher actual screen DPI and the surface size is adjusted. +++ This window- and pixel-unit separation also includes all callbacks for the native driver implementations, hence the changes native code - allowing to determine whether window- or pixel-units were given. --- .../jogamp/nativewindow/SurfaceScaleUtils.java | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/nativewindow') diff --git a/src/nativewindow/classes/jogamp/nativewindow/SurfaceScaleUtils.java b/src/nativewindow/classes/jogamp/nativewindow/SurfaceScaleUtils.java index c42dc613d..f5804cd12 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/SurfaceScaleUtils.java +++ b/src/nativewindow/classes/jogamp/nativewindow/SurfaceScaleUtils.java @@ -1,4 +1,5 @@ /** + * Copyright 2014-2023 Gothel Software e.K. All rights reserved. * Copyright 2014 JogAmp Community. All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are @@ -62,6 +63,34 @@ public class SurfaceScaleUtils { return (int) ( a / pixelScale + 0.5f ); } + /** + * Returns integer rounded product, i.e. {@code (int) ( a * pixelScale + 0.5f )} + * + * @param result the int[2] result, may be {@code a} for in-place operation + * @param a the int[2] values + * @param pixelScale the float[2] scale factors + * @return the result for chaining + */ + public static int[] scale(final int[] result, final int x, final int y, final float[] pixelScale) { + result[0] = (int) ( x * pixelScale[0] + 0.5f ); + result[1] = (int) ( y * pixelScale[1] + 0.5f ); + return result; + } + + /** + * Returns integer rounded product, i.e. {@code (int) ( a / pixelScale + 0.5f )} + * + * @param result the int[2] result, may be {@code a} for in-place operation + * @param a the int[2] values + * @param pixelScale the float[2] scale factors + * @return the result for chaining + */ + public static int[] scaleInv(final int[] result, final int x, final int y, final float[] pixelScale) { + result[0] = (int) ( x / pixelScale[0] + 0.5f ); + result[1] = (int) ( y / pixelScale[1] + 0.5f ); + return result; + } + /** * Returns integer rounded product, i.e. {@code (int) ( a * pixelScale + 0.5f )} * @@ -75,6 +104,7 @@ public class SurfaceScaleUtils { result[1] = (int) ( a[1] * pixelScale[1] + 0.5f ); return result; } + /** * Returns integer rounded product, i.e. {@code (int) ( a / pixelScale + 0.5f )} * -- cgit v1.2.3