Changeset 5206 in josm for trunk/src


Ignore:
Timestamp:
2012-04-29T22:23:26+02:00 (12 years ago)
Author:
bastiK
Message:

applied #7624 - Allow MapCSS to style right and left side casings differently (patch by cmuelle8)

Location:
trunk/src/org/openstreetmap/josm
Files:
4 edited

Legend:

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

    r5054 r5206  
    127127     * @param onewayReversed for oneway=-1 and similar
    128128     */
    129     public void drawWay(Way way, Color color, BasicStroke line, BasicStroke dashes, Color dashedColor, int offset,
     129    public void drawWay(Way way, Color color, BasicStroke line, BasicStroke dashes, Color dashedColor, float offset,
    130130            boolean showOrientation, boolean showHeadArrowOnly,
    131131            boolean showOneway, boolean onewayReversed) {
     
    259259
    260260        private List<Node> nodes;
    261         private int offset;
     261        private float offset;
    262262        private int idx;
    263263
     
    269269        private int x_prev0, y_prev0;
    270270
    271         public OffsetIterator(List<Node> nodes, int offset) {
     271        public OffsetIterator(List<Node> nodes, float offset) {
    272272            this.nodes = nodes;
    273273            this.offset = offset;
     
    282282        @Override
    283283        public Point next() {
    284             if (offset == 0) return nc.getPoint(nodes.get(idx++));
     284            if (Math.abs(offset) < 0.1f) return nc.getPoint(nodes.get(idx++));
    285285
    286286            Point current = nc.getPoint(nodes.get(idx));
     
    861861            if ((pb.width >= nb.getWidth() && pb.height >= nb.getHeight()) && // quick check
    862862                    area.contains(centeredNBounds) // slow but nice
    863                     ) {
     863            ) {
    864864                g.setColor(text.color);
    865865                Font defaultFont = g.getFont();
  • trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java

    r5054 r5206  
    311311                addIfNotNull(sl, LinePatternElemStyle.create(env));
    312312                addIfNotNull(sl, LineElemStyle.createLine(env));
     313                addIfNotNull(sl, LineElemStyle.createLeftCasing(env));
     314                addIfNotNull(sl, LineElemStyle.createRightCasing(env));
    313315                addIfNotNull(sl, LineElemStyle.createCasing(env));
    314316                addIfNotNull(sl, LineTextElemStyle.create(env));
     
    347349     */
    348350    private boolean isDefaultNodes() {
    349         if (defaultNodesIdx == cacheIdx) {
     351        if (defaultNodesIdx == cacheIdx)
    350352            return defaultNodes;
    351         }
    352353        defaultNodes = fromCanvas("default-points", true, Boolean.class);
    353354        defaultNodesIdx = cacheIdx;
     
    359360     */
    360361    private boolean isDefaultLines() {
    361         if (defaultLinesIdx == cacheIdx) {
     362        if (defaultLinesIdx == cacheIdx)
    362363            return defaultLines;
    363         }
    364364        defaultLines = fromCanvas("default-lines", true, Boolean.class);
    365365        defaultLinesIdx = cacheIdx;
     
    420420     */
    421421    public static AreaElemStyle getAreaElemStyle(OsmPrimitive p, boolean pretendWayIsClosed) {
    422         if (MapPaintStyles.getStyles() == null) {
     422        if (MapPaintStyles.getStyles() == null)
    423423            return null;
    424         }
    425424        for (ElemStyle s : MapPaintStyles.getStyles().generateStyles(p, 1.0, null, pretendWayIsClosed).a) {
    426             if (s instanceof AreaElemStyle) {
     425            if (s instanceof AreaElemStyle)
    427426                return (AreaElemStyle) s;
    428             }
    429427        }
    430428        return null;
  • trunk/src/org/openstreetmap/josm/gui/mappaint/LineElemStyle.java

    r4871 r5206  
    3333    public Color color;
    3434    public Color dashesBackground;
    35     public int offset;
     35    public float offset;
    3636    public float realWidth; // the real width of this line in meter
    3737
    3838    private BasicStroke dashesLine;
    3939
    40     protected LineElemStyle(Cascade c, BasicStroke line, Color color, BasicStroke dashesLine, Color dashesBackground, int offset, float realWidth) {
     40    protected LineElemStyle(Cascade c, BasicStroke line, Color color, BasicStroke dashesLine, Color dashesBackground, float offset, float realWidth) {
    4141        super(c, 0f);
    4242        this.line = line;
     
    4949
    5050    public static LineElemStyle createLine(Environment env) {
    51         return createImpl(env, false);
     51        return createImpl(env, "");
     52    }
     53
     54    public static LineElemStyle createLeftCasing(Environment env) {
     55        LineElemStyle leftCasing = createImpl(env, "left-casing-");
     56        if (leftCasing != null) {
     57            leftCasing.z_index += -90;
     58            leftCasing.isModifier = true;
     59        }
     60        return leftCasing;
     61    }
     62
     63    public static LineElemStyle createRightCasing(Environment env) {
     64        LineElemStyle rightCasing = createImpl(env, "right-casing-");
     65        if (rightCasing != null) {
     66            rightCasing.z_index += -90;
     67            rightCasing.isModifier = true;
     68        }
     69        return rightCasing;
    5270    }
    5371
    5472    public static LineElemStyle createCasing(Environment env) {
    55         LineElemStyle casing =  createImpl(env, true);
     73        LineElemStyle casing = createImpl(env, "casing-");
    5674        if (casing != null) {
    5775            casing.z_index += -100;
     
    6179    }
    6280
    63     private static LineElemStyle createImpl(Environment env, boolean casing) {
     81    private static LineElemStyle createImpl(Environment env, String prefix) {
    6482        Cascade c = env.mc.getCascade(env.layer);
    6583        Cascade c_def = env.mc.getCascade("default");
    6684
    67         String prefix = casing ? "casing-" : "";
    68 
    69         Float width;
    70         if (casing) {
    71             Float widthOnDefault = getWidth(c_def, "width", null);
    72             Float widthLine = getWidth(c, "width", widthOnDefault);
    73             width = getWidth(c, "casing-width", widthLine);
    74         } else {
    75             Float widthOnDefault = getWidth(c_def, "width", null);
    76             width = getWidth(c, "width", widthOnDefault);
    77         }
    78 
     85        Float widthOnDefault = getWidth(c_def, "width", null);
     86        Float width = getWidth(c, "width", widthOnDefault);
     87        if (!prefix.isEmpty()) {
     88            width = getWidth(c, prefix + "width", width);
     89        }
    7990        if (width == null)
    8091            return null;
     
    97108        }
    98109
     110        Float offsetOnDefault = getWidth(c_def, "offset", null);
     111        Float offset = getWidth(c, "offset", offsetOnDefault);
     112        if (offset == null) {
     113            offset = 0f;
     114        }
     115        if (!prefix.isEmpty()) {
     116            Float base_width = getWidth(c, "width", widthOnDefault);
     117            Float base_offset = offset;
     118            if (base_width == null || base_width < 2f) {
     119                base_width = 2f;
     120            }
     121            /* pre-calculate an offset */
     122            if (prefix.startsWith("left") || prefix.startsWith("right")) {
     123                offset = base_width/2 + width/2;
     124            } else {
     125                offset = 0f;
     126            }
     127            /* overwrites (e.g. "4") or adjusts (e.g. "+4") a prefixed -offset */
     128            if (getWidth(c, prefix + "offset", offset) != null) {
     129                offset = getWidth(c, prefix + "offset", offset);
     130            }
     131            /* flip sign for the right-casing-offset */
     132            if (prefix.startsWith("right")) {
     133                offset *= -1f;
     134            }
     135            /* use base_offset as the reference center */
     136            offset += base_offset;
     137        }
     138
    99139        Color color = c.get(prefix + "color", null, Color.class);
    100         if (!casing && color == null) {
     140        if (prefix.isEmpty() && color == null) {
    101141            color = c.get("fill-color", null, Color.class);
    102142        }
     
    177217        BasicStroke dashesLine = null;
    178218
    179         float offset = c.get("offset", 0f, Float.class);
    180 
    181219        if (dashes != null && dashesBackground != null) {
    182220            float[] dashes2 = new float[dashes.length];
     
    186224        }
    187225
    188         return new LineElemStyle(c, line, color, dashesLine, dashesBackground, (int) offset, realWidth);
     226        return new LineElemStyle(c, line, color, dashesLine, dashesBackground, offset, realWidth);
    189227    }
    190228
     
    273311        hash = 29 * hash + (dashesLine != null ? dashesLine.hashCode() : 0);
    274312        hash = 29 * hash + (dashesBackground != null ? dashesBackground.hashCode() : 0);
    275         hash = 29 * hash + offset;
     313        hash = 29 * hash + Float.floatToIntBits(offset);
    276314        hash = 29 * hash + Float.floatToIntBits(realWidth);
    277315        return hash;
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Expression.java

    r4401 r5206  
    2020import org.openstreetmap.josm.gui.mappaint.Environment;
    2121import org.openstreetmap.josm.tools.CheckParameterUtil;
     22import org.openstreetmap.josm.tools.ColorHelper;
    2223import org.openstreetmap.josm.tools.Utils;
    2324
     
    114115                }
    115116                return c;
     117            }
     118
     119            public Color html2color(String html) {
     120                return ColorHelper.html2color(html);
     121            }
     122
     123            public String color2html(Color c) {
     124                return ColorHelper.color2html(c);
    116125            }
    117126
Note: See TracChangeset for help on using the changeset viewer.