From: Jussi Koskela Date: Fri, 28 Aug 2020 10:55:43 +0000 (+0300) Subject: Customizable terminal pick distance X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=cee6a77315e6f680b562863b3d89536314f236e7;p=simantics%2Fplatform.git Customizable terminal pick distance gitlab simantics/platform#592 Change-Id: Ia81d791ced9e954c1eb0ec8811d27183de831dfa --- diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/participant/TerminalPainter.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/participant/TerminalPainter.java index d9c707993..2fd03aa6c 100644 --- a/bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/participant/TerminalPainter.java +++ b/bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/participant/TerminalPainter.java @@ -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; } diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/participant/pointertool/PointerInteractor.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/participant/pointertool/PointerInteractor.java index 940579ebe..9a03adab4 100644 --- a/bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/participant/pointertool/PointerInteractor.java +++ b/bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/participant/pointertool/PointerInteractor.java @@ -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 null 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 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; } diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/TerminalInformer.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/TerminalInformer.java index c646d7692..421a7d97c 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/TerminalInformer.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/TerminalInformer.java @@ -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);