]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Fixed diagram mouse wheel zooming for HiDPI monitors with zoom 02/2202/1
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Tue, 18 Sep 2018 21:45:25 +0000 (00:45 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Tue, 18 Sep 2018 21:45:25 +0000 (00:45 +0300)
SWTMouseEventAdapter now upscales coordinates which previously were just
passed to G2D as SWT API coordinates, not pixel coordinates.

gitlab #119

Change-Id: Icd3e00d1e515007f8573f7910783762a26916615

bundles/org.simantics.g2d/src/org/simantics/g2d/event/adapter/SWTMouseEventAdapter.java
bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/SWTDPIUtil.java

index bb8560c306a1da6091adca58c1c104b50405ed1a..924c7c252b47a929183cfcb4403784486d5f1615 100644 (file)
@@ -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);
                
        }
index 43d19efb2571cd987d380de84f9b8d0b824b795e..0fe51a9f2688b0b4957e6b433c8efd9b7bfe0793 100644 (file)
@@ -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) {