]> gerrit.simantics Code Review - simantics/district.git/commitdiff
Eliminate scaling of arrow widths based on dynamic edge thickness. 95/2795/1
authorReino Ruusu <reino.ruusu@semantum.fi>
Thu, 21 Mar 2019 10:50:55 +0000 (12:50 +0200)
committerReino Ruusu <reino.ruusu@semantum.fi>
Thu, 21 Mar 2019 10:50:55 +0000 (12:50 +0200)
gitlab #39

Change-Id: Iafd81090cdb6a793e983f0c00d1ccafacd64913b

org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkEdgeNode.java

index 21f3d741e77d81755376faa7047b3762266d0a92..74e8acdc575fa79a833ab38e92e56d2fda0324e2 100644 (file)
@@ -77,8 +77,9 @@ public class DistrictNetworkEdgeNode extends G2DParentNode implements ISelection
         BasicStroke oldStroke = (BasicStroke) g2d.getStroke();
 
         BasicStroke bs = null;
+        double scale = 1.0;
         if (scaleStroke) {
-            double scale = GeometryUtils.getScale(g2d.getTransform());
+            scale = GeometryUtils.getScale(g2d.getTransform());
             scale = Math.max(10000, Math.min(scale, 50000));
             double str = stroke != null ? Math.abs(stroke) : 1.0;
             bs = GeometryUtils.scaleStroke(STROKE, (float) (str / scale));
@@ -101,12 +102,13 @@ public class DistrictNetworkEdgeNode extends G2DParentNode implements ISelection
         // Draw arrow
         if (arrowLength != null) {
             g2d.setColor(Color.BLACK);
-            g2d.setStroke(new BasicStroke(bs.getLineWidth(), BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
+            float lw = STROKE.getLineWidth() / (float)scale;
+            g2d.setStroke(new BasicStroke(lw, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
             
             double l = arrowLength;
-            double w = 2 * (double) bs.getLineWidth() * Math.signum(l);
+            double w = 2 * (double) lw * Math.signum(l);
             if (Math.abs(w) > Math.abs(l)) w = l;
-            double offset = 2 * (double) bs.getLineWidth();
+            double offset = 2 * (double) lw;
             
             double centerX = (startX + endX) / 2, centerY = (startY + endY) / 2;
             double deltaX = endX - startX, deltaY = endY - startY;
@@ -136,8 +138,6 @@ public class DistrictNetworkEdgeNode extends G2DParentNode implements ISelection
         // Render SVG symbol
         double viewScaleRecip = 10;
         if (scaleStroke) {
-            double scale = GeometryUtils.getScale(g2d.getTransform());
-            scale = Math.max(10000, Math.min(scale, 50000));
             viewScaleRecip /= scale;
         }