]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Customizable terminal pick distance 08/4408/1 09/4409/1
authorJussi Koskela <jussi.koskela@semantum.fi>
Fri, 28 Aug 2020 10:55:43 +0000 (13:55 +0300)
committerJussi Koskela <jussi.koskela@semantum.fi>
Fri, 28 Aug 2020 10:55:43 +0000 (13:55 +0300)
gitlab simantics/platform#592
Change-Id: Ia81d791ced9e954c1eb0ec8811d27183de831dfa

bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/participant/TerminalPainter.java
bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/participant/pointertool/PointerInteractor.java
bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/TerminalInformer.java

index d9c707993798974e4bb5ffce2fef813fce57f5df..2fd03aa6c9992c944baec544fd57c515e27edf79 100644 (file)
@@ -273,13 +273,13 @@ public class TerminalPainter extends AbstractDiagramParticipant {
     }
     
     public Rectangle2D getTerminalShape() {
-       double pickDist = pointerInteractor.getPickDistance();
+       double pickDist = pointerInteractor.getTerminalPickDistance();
        return new Rectangle2D.Double(-pickDist - 0.5, -pickDist - 0.5, pickDist * 2 + 1, pickDist * 2 + 1);
     }
     
     public Rectangle2D getPickRectangle(double x, double y) {
-       double pickDist = pointerInteractor.getPickDistance();
-        Rectangle2D controlPickRect = new Rectangle2D.Double(x-pickDist, y-pickDist, pickDist*2+1, pickDist*2+1);
+       double pickDist = pointerInteractor.getTerminalPickDistance();
+        Rectangle2D controlPickRect = new Rectangle2D.Double(x-pickDist, y-pickDist, pickDist*2, pickDist*2);
         return controlPickRect;
     }
 
index 940579ebe82e17ad0f961d8622b57a666869a2a3..9a03adab4ed2cff35146b995c6ea1b8f742fc027 100644 (file)
@@ -92,16 +92,18 @@ import org.simantics.utils.threads.ThreadUtils;
 public class PointerInteractor extends AbstractDiagramParticipant {
 
     /**
-     * A hint key for terminal pick distance in control pixels.
+     * Hint keys for pick distances in control pixels.
      * @see #PICK_DIST
      */
     public static final Key KEY_PICK_DISTANCE = new KeyOf(Double.class, "PICK_DISTANCE");
+    public static final Key KEY_TERMINAL_PICK_DISTANCE = new KeyOf(Double.class, "TERMINAL_PICK_DISTANCE");
 
     /**
-     * Default terminal pick distance in control pixels.
+     * Default pick distances in control pixels.
      * @see #DEFAULT_PICK_DISTANCE
      */
-    public static final double PICK_DIST = 10;
+    public static final double PICK_DIST = 5;
+    public static final double TERMINAL_PICK_DIST = 15;
 
     /**
      * @see #altToggled(KeyEvent)
@@ -315,9 +317,24 @@ public class PointerInteractor extends AbstractDiagramParticipant {
         return canvasShape;
     }
 
+    /**
+     * @param controlPos
+     * @return <code>null</code> if current canvas transform is not invertible
+     */
+    public Shape getTerminalCanvasPickShape(Point2D controlPos) {
+        AffineTransform inverse = util.getInverseTransform();
+        if (inverse == null)
+            return null;
+
+        double      pd              = getTerminalPickDistance();
+        Rectangle2D controlPickRect = new Rectangle2D.Double(controlPos.getX()-pd, controlPos.getY()-pd, pd*2, pd*2);
+        Shape       canvasShape     = GeometryUtils.transformShape(controlPickRect, inverse);
+        return canvasShape;
+    }
+
     public List<TerminalInfo> pickTerminals(Point2D controlPos)
     {
-        Shape canvasPickRect = getCanvasPickShape(controlPos);
+        Shape canvasPickRect = getTerminalCanvasPickShape(controlPos);
         if (canvasPickRect == null)
             return Collections.emptyList();
         return TerminalUtil.pickTerminals(getContext(), diagram, canvasPickRect, true, true);
@@ -325,7 +342,7 @@ public class PointerInteractor extends AbstractDiagramParticipant {
 
     public TerminalInfo pickTerminal(Point2D controlPos)
     {
-        Shape canvasPickRect = getCanvasPickShape(controlPos);
+        Shape canvasPickRect = getTerminalCanvasPickShape(controlPos);
         if (canvasPickRect == null)
             return null;
         TerminalInfo ti = TerminalUtil.pickTerminal(getContext(), diagram, canvasPickRect);
@@ -827,6 +844,11 @@ public class PointerInteractor extends AbstractDiagramParticipant {
         return pickDistance == null ? PICK_DIST : Math.max(pickDistance, 0);
     }
 
+    public double getTerminalPickDistance() {
+        Double pickDistance = getHint(KEY_TERMINAL_PICK_DISTANCE);
+        return pickDistance == null ? TERMINAL_PICK_DIST : Math.max(pickDistance, 0);
+    }
+
     public PickPolicy getBoxSelectMode() {
         return boxSelectMode;
     }
index c646d769256f661e7babfeb38a8b4aac08538b67..421a7d97cd2c10e875e9e7f370154ff90f496b2b 100644 (file)
@@ -141,7 +141,7 @@ public class TerminalInformer extends AbstractDiagramParticipant {
 
     @EventHandler(priority = 0)
     public boolean handleMove(MouseMovedEvent me) {
-        double pickDist = pointerInteractor.getPickDistance();
+        double pickDist = pointerInteractor.getTerminalPickDistance();
         p1.setLocation(me.controlPosition.getX() - pickDist, me.controlPosition.getY() - pickDist);
         p2.setLocation(me.controlPosition.getX() + pickDist, me.controlPosition.getY() + pickDist);
         util.controlToCanvas(p1, p1);