Skip to content

Commit

Permalink
Moves DPIHelper and ViewsHelper to ui.shared, PlatformHelper to core.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexisDrogoul committed Sep 17, 2021
1 parent 2917630 commit 89d50e2
Show file tree
Hide file tree
Showing 45 changed files with 1,028 additions and 584 deletions.
476 changes: 392 additions & 84 deletions msi.gama.core/src/msi/gama/common/geometry/GeometryUtils.java

Large diffs are not rendered by default.

124 changes: 124 additions & 0 deletions msi.gama.core/src/msi/gama/runtime/PlatformHelper.java
@@ -0,0 +1,124 @@
/*******************************************************************************************************
*
* PlatformHelper.java, in ummisco.gama.ui.shared, is part of the source code of the GAMA modeling and simulation
* platform (v.1.8.2).
*
* (c) 2007-2021 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU)
*
* Visit https://github.com/gama-platform/gama for license information and contacts.
*
********************************************************************************************************/

package msi.gama.runtime;

import org.eclipse.core.runtime.Platform;

/**
* The Class PlatformHelper.
*/
public class PlatformHelper {

/** The platform string. */
private static String platformString = Platform.getOS();

/** The is windows. */
private static boolean isWindows = "win32".equals(platformString);

/** The is mac. */
private static boolean isMac = "macosx".equals(platformString);

/** The is linux. */
private static boolean isLinux = "linux".equals(platformString);

/** The is developer. */
private static Boolean isDeveloper;

/**
* Instantiates a new platform helper.
*/
private PlatformHelper() {}

/**
* Checks if is windows.
*
* @return true, if is windows
*/
public static boolean isWindows() { return isWindows; }

/**
* Checks if is linux.
*
* @return true, if is linux
*/
public static boolean isLinux() { return isLinux; }

/**
* Checks if is mac.
*
* @return true, if is mac
*/
public static boolean isMac() { return isMac; }

/**
* Checks if is developer.
*
* @return true, if is developer
*/
public static boolean isDeveloper() { // NO_UCD (unused code)
if (isDeveloper == null) {
isDeveloper = Platform.getInstallLocation() == null
|| Platform.getInstallLocation().getURL().getPath().contains("org.eclipse.pde.core");
}
return isDeveloper;
}

/**
* The JAVA version
*/
public static final int JAVA_VERSION; // NO_UCD (unused code)
static {
JAVA_VERSION = parseVersion(System.getProperty("java.version")); //$NON-NLS-1$
}

/**
* Parses the version.
*
* @param version
* the version
* @return the int
*/
private static int parseVersion(final String version) {
if (version == null) return 0;
int major = 0, minor = 0, micro = 0;
final int length = version.length();
int index = 0, start = 0;
while (index < length && Character.isDigit(version.charAt(index))) { index++; }
try {
if (start < length) { major = Integer.parseInt(version.substring(start, index)); }
} catch (final NumberFormatException e) {}
start = ++index;
while (index < length && Character.isDigit(version.charAt(index))) { index++; }
try {
if (start < length) { minor = Integer.parseInt(version.substring(start, index)); }
} catch (final NumberFormatException e) {}
start = ++index;
while (index < length && Character.isDigit(version.charAt(index))) { index++; }
try {
if (start < length) { micro = Integer.parseInt(version.substring(start, index)); }
} catch (final NumberFormatException e) {}
return javaVersion(major, minor, micro);
}

/**
* Returns the Java version number as an integer.
*
* @param major
* @param minor
* @param micro
* @return the version
*/
public static int javaVersion(final int major, final int minor, final int micro) {
return (major << 16) + (minor << 8) + micro;
}

}
Expand Up @@ -15,8 +15,8 @@
import org.eclipse.swt.widgets.Composite;

import ummisco.gama.java2d.swing.SwingControl;
import ummisco.gama.ui.views.WorkaroundForIssue1353;
import ummisco.gama.ui.views.displays.LayeredDisplayView;
import ummisco.gama.ui.views.displays.WorkaroundForIssue1353;

public class AWTDisplayView extends LayeredDisplayView {

Expand Down
Expand Up @@ -71,10 +71,11 @@
import msi.gama.precompiler.GamlAnnotations.doc;
import msi.gama.runtime.GAMA;
import msi.gama.runtime.IScope;
import msi.gama.runtime.PlatformHelper;
import msi.gaml.expressions.IExpression;
import msi.gaml.operators.Cast;
import ummisco.gama.dev.utils.DEBUG;
import ummisco.gama.ui.utils.PlatformHelper;
import ummisco.gama.ui.utils.DPIHelper;
import ummisco.gama.ui.views.displays.DisplaySurfaceMenu;

/**
Expand Down Expand Up @@ -214,8 +215,8 @@ public void dispatchKeyEvent(final char e) {
* @return the int
*/
int autoScaleUp(final int c) {
if (PlatformHelper.getDeviceZoom() > 100) return c;
return PlatformHelper.autoScaleUp(c);
if (DPIHelper.getDeviceZoom() > 100) return c;
return DPIHelper.autoScaleUp(c);
}

@Override
Expand Down Expand Up @@ -850,8 +851,8 @@ public void changed(final Changes property, final Object value) {
@Override
public Font computeFont(final Font f) {
if (f == null) return null;
if (PlatformHelper.isWindows() && PlatformHelper.isHiDPI())
return f.deriveFont(PlatformHelper.autoScaleUp(f.getSize()));
if (PlatformHelper.isWindows() && DPIHelper.isHiDPI())
return f.deriveFont(DPIHelper.autoScaleUp(f.getSize()));
return f;

}
Expand Down
Expand Up @@ -23,7 +23,7 @@ public class WorkaroundForIssue1594 {
public static void installOn(final AWTDisplayView view, final Composite parent, final Composite surfaceComposite,
final Java2DDisplaySurface displaySurface) {
// Install only on Windows
if (!ummisco.gama.ui.utils.PlatformHelper.isWindows()) { return; }
if (!msi.gama.runtime.PlatformHelper.isWindows()) { return; }
final IPartService ps = view.getSite().getService(IPartService.class);
ps.addPartListener(new IPartListener2() {

Expand Down
Expand Up @@ -33,7 +33,7 @@ private static void setMousePosition(final IDisplaySurface surface, final int x,

public static void installOn(final Panel applet, final IDisplaySurface surface) {
// Install only on Linux
if (!ummisco.gama.ui.utils.PlatformHelper.isLinux()) return;
if (!msi.gama.runtime.PlatformHelper.isLinux()) return;
applet.addMouseWheelListener(e -> {
if (e.getPreciseWheelRotation() > 0) {
surface.zoomOut();
Expand Down
Expand Up @@ -15,8 +15,8 @@
import org.eclipse.ui.IPartListener2;
import org.eclipse.ui.IWorkbenchPartReference;

import msi.gama.runtime.PlatformHelper;
import ummisco.gama.dev.utils.DEBUG;
import ummisco.gama.ui.utils.PlatformHelper;
import ummisco.gama.ui.utils.WorkbenchHelper;

public class WorkaroundForIssue2745 {
Expand Down
Expand Up @@ -23,10 +23,10 @@
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;

import msi.gama.runtime.PlatformHelper;
import ummisco.gama.dev.utils.DEBUG;
import ummisco.gama.java2d.Java2DDisplaySurface;
import ummisco.gama.java2d.WorkaroundForIssue2476;
import ummisco.gama.ui.utils.PlatformHelper;
import ummisco.gama.ui.utils.WorkbenchHelper;

public abstract class SwingControl extends Composite {
Expand Down
6 changes: 3 additions & 3 deletions ummisco.gama.opengl/src/ummisco/gama/opengl/OpenGL.java
Expand Up @@ -67,7 +67,7 @@
import ummisco.gama.opengl.scene.mesh.MeshDrawer;
import ummisco.gama.opengl.scene.resources.ResourceDrawer;
import ummisco.gama.opengl.scene.text.TextDrawer;
import ummisco.gama.ui.utils.PlatformHelper;
import ummisco.gama.ui.utils.DPIHelper;

/**
* A class that represents an intermediate state between the rendering and the opengl state. It captures all the
Expand Down Expand Up @@ -270,9 +270,9 @@ private void debugSizes(final int width, final int height, final double initialE
DEBUG.OUT("Ratio width/height in pixels ", 35, envWidth / envHeight);
DEBUG.OUT("Window pixels/env pixels ", 35, width / envWidth + " | " + height / envHeight);
DEBUG.OUT("Current XRatio pixels/env in units ", 35, xRatio + " | " + yRatio);
DEBUG.OUT("Device Zoom = " + PlatformHelper.getDeviceZoom());
DEBUG.OUT("Device Zoom = " + DPIHelper.getDeviceZoom());
DEBUG.OUT("AutoScale down = ", false);
DEBUG.OUT(" " + PlatformHelper.autoScaleDown(width) + " " + PlatformHelper.autoScaleDown(height));
DEBUG.OUT(" " + DPIHelper.autoScaleDown(width) + " " + DPIHelper.autoScaleDown(height));
// DEBUG.OUT("Client area of window:" + getRenderer().getCanvas().getClientArea());
}

Expand Down
Expand Up @@ -25,7 +25,7 @@
import ummisco.gama.opengl.renderer.IOpenGLRenderer;
import ummisco.gama.opengl.renderer.helpers.CameraHelper;
import ummisco.gama.ui.bindings.GamaKeyBindings;
import ummisco.gama.ui.utils.PlatformHelper;
import ummisco.gama.ui.utils.DPIHelper;

public abstract class AbstractCamera implements ICamera {

Expand Down Expand Up @@ -230,8 +230,8 @@ public final void mouseMove(final org.eclipse.swt.events.MouseEvent e) {
}

protected void internalMouseMove(final MouseEvent e) {
mousePosition.x = PlatformHelper.autoScaleUp(e.x);
mousePosition.y = PlatformHelper.autoScaleUp(e.y);
mousePosition.x = DPIHelper.autoScaleUp(e.x);
mousePosition.y = DPIHelper.autoScaleUp(e.y);
setCtrlPressed(GamaKeyBindings.ctrl(e));
setShiftPressed(GamaKeyBindings.shift(e));
}
Expand Down Expand Up @@ -298,8 +298,8 @@ protected GamaPoint getNormalizedCoordinates(final double x, final double y) {
private int clickOnKeystone(final MouseEvent e) {
// int x = e.x;
// int y = e.y;
final int x = PlatformHelper.autoScaleUp(e.x);
final int y = PlatformHelper.autoScaleUp(e.y);
final int x = DPIHelper.autoScaleUp(e.x);
final int y = DPIHelper.autoScaleUp(e.y);
// return the number of the corner clicked. Return -1 if no click on
// keystone.
// final GamaPoint p = getNormalizedCoordinates(e);
Expand All @@ -309,17 +309,17 @@ private int clickOnKeystone(final MouseEvent e) {
protected int hoverOnKeystone(final MouseEvent e) {
// int x = e.x;
// int y = e.y;
final int x = PlatformHelper.autoScaleUp(e.x);
final int y = PlatformHelper.autoScaleUp(e.y);
final int x = DPIHelper.autoScaleUp(e.x);
final int y = DPIHelper.autoScaleUp(e.y);
// return the number of the corner clicked. Return -1 if no click on
// keystone. Return 10 if click on the center.
// final GamaPoint p = getNormalizedCoordinates(e);
return renderer.getKeystoneHelper().cornerHovered(new GamaPoint(x, y));
}

protected void internalMouseDown(final MouseEvent e) {
final int x = PlatformHelper.autoScaleUp(e.x);
final int y = PlatformHelper.autoScaleUp(e.y);
final int x = DPIHelper.autoScaleUp(e.x);
final int y = DPIHelper.autoScaleUp(e.y);
if (firsttimeMouseDown) {
firstMousePressedPosition.setLocation(x, y, 0);
firsttimeMouseDown = false;
Expand Down Expand Up @@ -381,8 +381,8 @@ protected void internalMouseUp(final MouseEvent e) {
}

private void startROI(final org.eclipse.swt.events.MouseEvent e) {
getMousePosition().x = PlatformHelper.autoScaleUp(e.x);
getMousePosition().y = PlatformHelper.autoScaleUp(e.y);
getMousePosition().x = DPIHelper.autoScaleUp(e.x);
getMousePosition().y = DPIHelper.autoScaleUp(e.y);
renderer.getOpenGLHelper().defineROI(new GamaPoint(firstMousePressedPosition), new GamaPoint(mousePosition));
ROICurrentlyDrawn = true;
}
Expand Down
Expand Up @@ -20,7 +20,7 @@
import msi.gaml.operators.Maths;
import ummisco.gama.opengl.renderer.IOpenGLRenderer;
import ummisco.gama.ui.bindings.GamaKeyBindings;
import ummisco.gama.ui.utils.PlatformHelper;
import ummisco.gama.ui.utils.DPIHelper;

public class CameraArcBall extends AbstractCamera {

Expand Down Expand Up @@ -369,8 +369,8 @@ public void internalMouseMove(final org.eclipse.swt.events.MouseEvent e) {
final int selectedCorner = getRenderer().getKeystoneHelper().getCornerSelected();
if (selectedCorner != -1) {
final GamaPoint origin = getNormalizedCoordinates(getMousePosition().x, getMousePosition().y);
x = PlatformHelper.autoScaleUp(e.x);
y = PlatformHelper.autoScaleUp(e.y);
x = DPIHelper.autoScaleUp(e.x);
y = DPIHelper.autoScaleUp(e.y);
GamaPoint p = getNormalizedCoordinates(x, y);
final GamaPoint translation = origin.minus(p).yNegated();
p = getRenderer().getKeystoneHelper().getKeystoneCoordinates(selectedCorner).plus(-translation.x,
Expand All @@ -386,7 +386,7 @@ public void internalMouseMove(final org.eclipse.swt.events.MouseEvent e) {

super.internalMouseMove(e);
if ((e.stateMask & SWT.BUTTON_MASK) == 0) return;
final GamaPoint newPoint = new GamaPoint(PlatformHelper.autoScaleUp(x), PlatformHelper.autoScaleUp(y));
final GamaPoint newPoint = new GamaPoint(DPIHelper.autoScaleUp(x), DPIHelper.autoScaleUp(y));
if (cameraInteraction && GamaKeyBindings.ctrl(e)) {
final int horizMovement = (int) (newPoint.x - lastMousePressedPosition.x);
final int vertMovement = (int) (newPoint.y - lastMousePressedPosition.y);
Expand Down Expand Up @@ -444,8 +444,8 @@ public void internalMouseMove(final org.eclipse.swt.events.MouseEvent e) {
// phi = phi - vertMovement_real * get_sensivity();
updateCartesianCoordinatesFromAngles();
} else if (shiftPressed && isViewInXYPlan()) {
getMousePosition().x = PlatformHelper.autoScaleUp(x);
getMousePosition().y = PlatformHelper.autoScaleUp(y);
getMousePosition().x = DPIHelper.autoScaleUp(x);
getMousePosition().y = DPIHelper.autoScaleUp(y);
getRenderer().getOpenGLHelper().defineROI(
new GamaPoint(firstMousePressedPosition.x, firstMousePressedPosition.y),
new GamaPoint(getMousePosition().x, getMousePosition().y));
Expand All @@ -456,8 +456,8 @@ public void internalMouseMove(final org.eclipse.swt.events.MouseEvent e) {
getRenderer().getOpenGLHelper().getROIEnvelope().translate(p.x, p.y);

} else if (cameraInteraction) {
int horizMovement = (int) (PlatformHelper.autoScaleUp(x) - lastMousePressedPosition.x);
int vertMovement = (int) (PlatformHelper.autoScaleUp(y) - lastMousePressedPosition.y);
int horizMovement = (int) (DPIHelper.autoScaleUp(x) - lastMousePressedPosition.x);
int vertMovement = (int) (DPIHelper.autoScaleUp(y) - lastMousePressedPosition.y);
if (flipped) {
horizMovement = -horizMovement;
vertMovement = -vertMovement;
Expand Down

0 comments on commit 89d50e2

Please sign in to comment.