Changeset 11758 in josm for trunk/src


Ignore:
Timestamp:
2017-03-21T13:39:51+01:00 (7 years ago)
Author:
michael2402
Message:

See #13309: Use cached preferences for map drawing; align box text to full pixels if not rotated.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java

    r11755 r11758  
    6161import org.openstreetmap.josm.data.osm.visitor.paint.relations.Multipolygon.PolyData;
    6262import org.openstreetmap.josm.data.osm.visitor.paint.relations.MultipolygonCache;
     63import org.openstreetmap.josm.data.preferences.AbstractProperty;
     64import org.openstreetmap.josm.data.preferences.BooleanProperty;
     65import org.openstreetmap.josm.data.preferences.IntegerProperty;
     66import org.openstreetmap.josm.data.preferences.StringProperty;
    6367import org.openstreetmap.josm.gui.MapViewState.MapViewPoint;
    6468import org.openstreetmap.josm.gui.NavigatableComponent;
     
    263267    private static final double cosPHI = Math.cos(PHI);
    264268    private static final double sinPHI = Math.sin(PHI);
     269    /**
     270     * If we should use left hand traffic.
     271     */
     272    private static final AbstractProperty<Boolean> PREFERENCE_LEFT_HAND_TRAFFIC
     273            = new BooleanProperty("mappaint.lefthandtraffic", false).cached();
     274    /**
     275     * Indicates that the renderer should enable anti-aliasing
     276     * @since 11758
     277     */
     278    public static final AbstractProperty<Boolean> PREFERENCE_ANTIALIASING_USE
     279            = new BooleanProperty("mappaint.use-antialiasing", true).cached();
     280    /**
     281     * The mode that is used for anti-aliasing
     282     * @since 11758
     283     */
     284    public static final AbstractProperty<String> PREFERENCE_TEXT_ANTIALIASING
     285            = new StringProperty("mappaint.text-antialiasing", "default").cached();
     286
     287    /**
     288     * The line with to use for highlighting
     289     */
     290    private static final AbstractProperty<Integer> HIGHLIGHT_LINE_WIDTH = new IntegerProperty("mappaint.highlight.width", 4).cached();
     291    private static final AbstractProperty<Integer> HIGHLIGHT_POINT_RADIUS = new IntegerProperty("mappaint.highlight.radius", 7).cached();
     292    private static final AbstractProperty<Integer> WIDER_HIGHLIGHT = new IntegerProperty("mappaint.highlight.bigger-increment", 5).cached();
     293    private static final AbstractProperty<Integer> HIGHLIGHT_STEP = new IntegerProperty("mappaint.highlight.step", 4).cached();
    265294
    266295    private Collection<WaySegment> highlightWaySegments;
    267 
    268     // highlight customization fields
    269     private int highlightLineWidth;
    270     private int highlightPointRadius;
    271     private int widerHighlight;
    272     private int highlightStep;
    273296
    274297    //flag that activate wider highlight mode
     
    783806    /**
    784807     * highlights a given GeneralPath using the settings from BasicStroke to match the line's
    785      * style. Width of the highlight is hard coded.
     808     * style. Width of the highlight can be changed by user preferences
    786809     * @param path path to draw
    787810     * @param line line style
     
    791814            return;
    792815        g.setColor(highlightColorTransparent);
    793         float w = line.getLineWidth() + highlightLineWidth;
    794         if (useWiderHighlight) w += widerHighlight;
     816        float w = line.getLineWidth() + HIGHLIGHT_LINE_WIDTH.get();
     817        if (useWiderHighlight) {
     818            w += WIDER_HIGHLIGHT.get();
     819        }
     820        int step = Math.max(HIGHLIGHT_STEP.get(), 1);
    795821        while (w >= line.getLineWidth()) {
    796822            g.setStroke(new BasicStroke(w, line.getEndCap(), line.getLineJoin(), line.getMiterLimit()));
    797823            g.draw(path);
    798             w -= highlightStep;
     824            w -= step;
    799825        }
    800826    }
     
    808834    private void drawPointHighlight(Point2D p, int size) {
    809835        g.setColor(highlightColorTransparent);
    810         int s = size + highlightPointRadius;
    811         if (useWiderHighlight) s += widerHighlight;
     836        int s = size + HIGHLIGHT_POINT_RADIUS.get();
     837        if (useWiderHighlight) {
     838            s += WIDER_HIGHLIGHT.get();
     839        }
     840        int step = Math.max(HIGHLIGHT_STEP.get(), 1);
    812841        while (s >= size) {
    813842            int r = (int) Math.floor(s/2d);
    814843            g.fill(new RoundRectangle2D.Double(p.getX()-r, p.getY()-r, s, s, r, r));
    815             s -= highlightStep;
     844            s -= step;
    816845        }
    817846    }
     
    10411070    private void displayText(OsmPrimitive osm, TextLabel text, String name, Rectangle2D nb,
    10421071            MapViewPositionAndRotation center) {
    1043         AffineTransform at = AffineTransform.getTranslateInstance(center.getPoint().getInViewX(), center.getPoint().getInViewY());
    1044         at.rotate(center.getRotation());
    1045         at.translate(-nb.getCenterX(), -nb.getCenterY());
     1072        AffineTransform at = new AffineTransform();
     1073        if (Math.abs(center.getRotation()) < .01) {
     1074            // Explicitly no rotation: move to full pixels.
     1075            at.setToTranslation(Math.round(center.getPoint().getInViewX() - nb.getCenterX()),
     1076                    Math.round(center.getPoint().getInViewY() - nb.getCenterY()));
     1077        } else {
     1078            at.setToTranslation(center.getPoint().getInViewX(), center.getPoint().getInViewY());
     1079            at.rotate(center.getRotation());
     1080            at.translate(-nb.getCenterX(), -nb.getCenterY());
     1081        }
    10461082        displayText(() -> {
    10471083            AffineTransform defaultTransform = g.getTransform();
     
    12611297        scale = nc.getScale();
    12621298
    1263         leftHandTraffic = Main.pref.getBoolean("mappaint.lefthandtraffic", false);
     1299        leftHandTraffic = PREFERENCE_LEFT_HAND_TRAFFIC.get();
    12641300
    12651301        useStrokes = paintSettings.getUseStrokesDistance() > circum;
     
    12681304        isOutlineOnly = paintSettings.isOutlineOnly();
    12691305
    1270         antialiasing = Main.pref.getBoolean("mappaint.use-antialiasing", true) ?
     1306        antialiasing = PREFERENCE_ANTIALIASING_USE.get() ?
    12711307                        RenderingHints.VALUE_ANTIALIAS_ON : RenderingHints.VALUE_ANTIALIAS_OFF;
    12721308        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, antialiasing);
    12731309
    12741310        Object textAntialiasing;
    1275         switch (Main.pref.get("mappaint.text-antialiasing", "default")) {
     1311        switch (PREFERENCE_TEXT_ANTIALIASING.get()) {
    12761312            case "on":
    12771313                textAntialiasing = RenderingHints.VALUE_TEXT_ANTIALIAS_ON;
     
    12991335        }
    13001336        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, textAntialiasing);
    1301 
    1302         highlightLineWidth = Main.pref.getInteger("mappaint.highlight.width", 4);
    1303         highlightPointRadius = Main.pref.getInteger("mappaint.highlight.radius", 7);
    1304         widerHighlight = Main.pref.getInteger("mappaint.highlight.bigger-increment", 5);
    1305         highlightStep = Main.pref.getInteger("mappaint.highlight.step", 4);
    13061337    }
    13071338
Note: See TracChangeset for help on using the changeset viewer.