]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Customisable selection padding on diagrams 25/1425/2
authorAntti Villberg <antti.villberg@semantum.fi>
Wed, 7 Feb 2018 06:16:18 +0000 (08:16 +0200)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Wed, 7 Feb 2018 07:01:44 +0000 (09:01 +0200)
refs #7747

Change-Id: I884be9b927a35e77ef23167c06eb7b836297002d

bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/DiagramHints.java
bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/participant/ElementPainter.java
bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/SelectionNode.java

index 6152c168e70f09e57d517249c92d8c9a01804972..367cebcce67fb91caba55ad502c9c1050e75508e 100644 (file)
@@ -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");
+
 }
index d35bfadb04ba2fd7e92eefaaa4b5f7feda40440d..ba575c630ffb1aff08024fe8e482d2f5423c8116 100644 (file)
@@ -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);
         }
     }
 
index 445a66fe3e9b5a7d431042c677f7323f12ee1ba5..bd09c45745be9ab675d25f0bb073caca8cc85b0d 100644 (file)
@@ -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;