From: Antti Villberg Date: Wed, 7 Feb 2018 06:16:18 +0000 (+0200) Subject: Customisable selection padding on diagrams X-Git-Tag: v1.43.0~136^2~602^2 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=f29c665f426c5d85d11ce1467b158f10c633728b;p=simantics%2Fplatform.git Customisable selection padding on diagrams refs #7747 Change-Id: I884be9b927a35e77ef23167c06eb7b836297002d --- diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/DiagramHints.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/DiagramHints.java index 6152c168e..367cebcce 100644 --- a/bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/DiagramHints.java +++ b/bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/DiagramHints.java @@ -179,4 +179,11 @@ public class DiagramHints { */ public static final Key POPUP_MENU_HIDDEN = new KeyOf(Long.class, "POPUP_MENU_HIDDEN"); + /** + * For specifying a user-defined padding for selections + * + * @since 1.33.0 + */ + public static final Key SELECTION_PADDING_SCALE_FACTOR = new KeyOf(Double.class, "SELECTION_PADDING_SCALE_FACTOR"); + } diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/participant/ElementPainter.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/participant/ElementPainter.java index d35bfadb0..ba575c630 100644 --- a/bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/participant/ElementPainter.java +++ b/bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/participant/ElementPainter.java @@ -1090,6 +1090,9 @@ public class ElementPainter extends AbstractDiagramParticipant implements Compos } else { SelectionNode s = selectionNode.getOrCreateNode(getNodeId("shape", e), SelectionNode.class); s.init(selectionTransform, bounds, color); + Double paddingFactor = diagram.getHint(DiagramHints.SELECTION_PADDING_SCALE_FACTOR); + if (paddingFactor != null) + s.setPaddingFactor(paddingFactor); } } diff --git a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/SelectionNode.java b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/SelectionNode.java index 445a66fe3..bd09c4574 100644 --- a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/SelectionNode.java +++ b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/SelectionNode.java @@ -36,10 +36,15 @@ public class SelectionNode extends G2DNode implements Decoration { protected transient BasicStroke scaledStroke; protected transient double previousScaleRecip = Double.NaN; private boolean ignore = false; + private double paddingFactor = 5.0; public void setIgnore(boolean value) { ignore = value; } + + public void setPaddingFactor(double factor) { + paddingFactor = factor; + } @SyncField({"transform", "bounds", "color"}) public void init(AffineTransform transform, Rectangle2D bounds, Color color) { @@ -78,7 +83,7 @@ public class SelectionNode extends G2DNode implements Decoration { } g.setStroke(scaledStroke); - double padding = 5.0 * scaleRecip; + double padding = paddingFactor * scaleRecip; double paddingX = padding; double paddingY = padding;