From: Tuukka Lehtonen Date: Tue, 18 Sep 2018 21:45:25 +0000 (+0300) Subject: Fixed diagram mouse wheel zooming for HiDPI monitors with zoom X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F02%2F2202%2F1;p=simantics%2Fplatform.git Fixed diagram mouse wheel zooming for HiDPI monitors with zoom SWTMouseEventAdapter now upscales coordinates which previously were just passed to G2D as SWT API coordinates, not pixel coordinates. gitlab #119 Change-Id: Icd3e00d1e515007f8573f7910783762a26916615 --- diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/event/adapter/SWTMouseEventAdapter.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/event/adapter/SWTMouseEventAdapter.java index bb8560c30..924c7c252 100644 --- a/bundles/org.simantics.g2d/src/org/simantics/g2d/event/adapter/SWTMouseEventAdapter.java +++ b/bundles/org.simantics.g2d/src/org/simantics/g2d/event/adapter/SWTMouseEventAdapter.java @@ -34,6 +34,7 @@ import org.simantics.scenegraph.g2d.events.MouseEvent.MouseExitEvent; import org.simantics.scenegraph.g2d.events.MouseEvent.MouseMovedEvent; import org.simantics.scenegraph.g2d.events.MouseEvent.MouseWheelMovedEvent; import org.simantics.scenegraph.g2d.events.adapter.AbstractEventAdapter; +import org.simantics.utils.ui.SWTDPIUtil; public class SWTMouseEventAdapter extends AbstractEventAdapter implements MouseListener, MouseMoveListener, MouseTrackListener, MouseWheelListener { @@ -64,12 +65,12 @@ public class SWTMouseEventAdapter extends AbstractEventAdapter implements MouseL private Point2D getControlPosition(MouseEvent e) { - return new Point2D.Double(e.x, e.y); + return new Point2D.Double(SWTDPIUtil.upscaleSwt(e.x), SWTDPIUtil.upscaleSwt(e.y)); } private Point2D getScreenPosition(MouseEvent e) { - Point p = e.display.getCursorLocation(); + Point p = SWTDPIUtil.upscaleSwt(e.display.getCursorLocation()); return new Point2D.Double(p.x, p.y); } diff --git a/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/SWTDPIUtil.java b/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/SWTDPIUtil.java index 43d19efb2..0fe51a9f2 100644 --- a/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/SWTDPIUtil.java +++ b/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/SWTDPIUtil.java @@ -218,7 +218,8 @@ public class SWTDPIUtil { } public static Point2D upscaleSwt(Point2D p) { - return upscaleSwt(p.getX(), p.getY()); + initialize(); + return (hasSwtScale && p != null) ? upscaleSwt(p.getX(), p.getY()) : p; } public static Point upscaleSwtToInteger(Point2D p) { @@ -227,7 +228,8 @@ public class SWTDPIUtil { } public static Point upscaleSwt(Point p) { - return upscaleSwt(p.x, p.y); + initialize(); + return (hasSwtScale && p != null) ? upscaleSwt(p.x, p.y) : p; } public static Rectangle2D upscaleSwt(Rectangle2D r, Rectangle2D target) {