X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.g2d%2Fsrc%2Forg%2Fsimantics%2Fg2d%2Fparticipant%2FRulerPainter.java;h=dc9f5f5a73ec0a0f97383c5499ce6f2622e5a688;hp=bffe0c9df4862a160f95ac0e61610dffb1d2a1e1;hb=bc195f999a0a3f4571ff45342327223b4b480750;hpb=fe1a2f532761669e67da4db4ae15096ced8a04db diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/participant/RulerPainter.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/participant/RulerPainter.java index bffe0c9df..dc9f5f5a7 100644 --- a/bundles/org.simantics.g2d/src/org/simantics/g2d/participant/RulerPainter.java +++ b/bundles/org.simantics.g2d/src/org/simantics/g2d/participant/RulerPainter.java @@ -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);