]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.g2d/src/org/simantics/g2d/participant/RulerPainter.java
HiDPI scaling for diagram ruler and model activity tracker
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / participant / RulerPainter.java
index bffe0c9df4862a160f95ac0e61610dffb1d2a1e1..dc9f5f5a73ec0a0f97383c5499ce6f2622e5a688 100644 (file)
@@ -56,6 +56,11 @@ public class RulerPainter extends AbstractCanvasParticipant {
 
     public static final Key KEY_RULER_ENABLED = new KeyOf(Boolean.class, "RULER_ENABLED");
 
+    /**
+     * Size of ruler in normalized (non-zoomed or 100% zoom) coordinates, not screen pixel coordinates.
+     */
+    public static final Key KEY_RULER_SIZE = new KeyOf(Double.class, "RULER_SIZE");
+
     /** Background color */
     public static final Key KEY_RULER_BACKGROUND_COLOR = new KeyOf(Color.class, "RULER_BACKGROUND_COLOR");
 
@@ -78,7 +83,12 @@ public class RulerPainter extends AbstractCanvasParticipant {
     @Override
     public void addedToContext(ICanvasContext ctx) {
         super.addedToContext(ctx);
+
+        if (!hasHint(KEY_RULER_SIZE))
+            setHint(KEY_RULER_SIZE, RULER_WIDTH);
+
         getHintStack().addKeyHintListener(getThread(), KEY_RULER_ENABLED, hintListener);
+        getHintStack().addKeyHintListener(getThread(), KEY_RULER_SIZE, hintListener);
         getHintStack().addKeyHintListener(getThread(), KEY_RULER_BACKGROUND_COLOR, hintListener);
         getHintStack().addKeyHintListener(getThread(), KEY_RULER_TEXT_COLOR, hintListener);
         getHintStack().addKeyHintListener(getThread(), GridPainter.KEY_GRID_SIZE, hintListener);
@@ -88,6 +98,7 @@ public class RulerPainter extends AbstractCanvasParticipant {
     @Override
     public void removedFromContext(ICanvasContext ctx) {
         getHintStack().removeKeyHintListener(getThread(), KEY_RULER_ENABLED, hintListener);
+        getHintStack().removeKeyHintListener(getThread(), KEY_RULER_SIZE, hintListener);
         getHintStack().removeKeyHintListener(getThread(), KEY_RULER_BACKGROUND_COLOR, hintListener);
         getHintStack().removeKeyHintListener(getThread(), KEY_RULER_TEXT_COLOR, hintListener);
         getHintStack().removeKeyHintListener(getThread(), GridPainter.KEY_GRID_SIZE, hintListener);
@@ -119,6 +130,7 @@ public class RulerPainter extends AbstractCanvasParticipant {
     protected void updateNode() {
         node.setEnabled(isPaintingEnabled());
         node.setGridSize(getGridSize());
+        node.setRulerSize(getRulerSize());
     }
 
     private double getGridSize() {
@@ -139,6 +151,11 @@ public class RulerPainter extends AbstractCanvasParticipant {
         return !Boolean.FALSE.equals(b);
     }
 
+    private double getRulerSize() {
+        Double d = getHint(KEY_RULER_SIZE);
+        return d != null ? d : RULER_WIDTH;
+    }
+
     public Color getRulerTextColor()
     {
         Color c = getHint(KEY_RULER_TEXT_COLOR);