Changeset 5214 in josm for trunk/src/org/openstreetmap/josm


Ignore:
Timestamp:
2012-05-06T12:44:35+02:00 (12 years ago)
Author:
bastiK
Message:

mapcss: change semantics of casing-width: X;

Previously it was an absolute width, from now it's the width of the border on both sides of the main line, so:
width: 6; casing-width: 8 becomes width: 6; casing-width: 1; (or width: 6; casing-width: +2;).

This breaks existing styles! For compatibility with old JOSM versions use the "+" syntax (which is unchanged) or work around with "::layer".
Reason: For most of the other mapcss renderers, it works like this.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/mappaint/LineElemStyle.java

    r5213 r5214  
    1414import org.openstreetmap.josm.data.osm.visitor.paint.MapPainter;
    1515import org.openstreetmap.josm.data.osm.visitor.paint.PaintColors;
     16import org.openstreetmap.josm.gui.mappaint.mapcss.Instruction.RelativeFloat;
    1617import org.openstreetmap.josm.tools.Utils;
    1718
     
    9596        Cascade c = env.mc.getCascade(env.layer);
    9697        Cascade c_def = env.mc.getCascade("default");
    97         Float widthOnDefault = getWidth(c_def, "width", null);
    98         Float width = getWidth(c, "width", widthOnDefault);
    99         if (type != LineType.NORMAL) {
    100             width = getWidth(c, type.prefix + "width", width);
     98        Float width;
     99        switch (type) {
     100            case NORMAL:
     101            {
     102                Float widthOnDefault = getWidth(c_def, "width", null);
     103                width = getWidth(c, "width", widthOnDefault);
     104                break;
     105            }
     106            case CASING:
     107            {
     108                Float casingWidth = c.get(type.prefix + "width", null, Float.class, true);
     109                if (casingWidth == null) {
     110                    RelativeFloat rel_casingWidth = c.get(type.prefix + "width", null, RelativeFloat.class, true);
     111                    if (rel_casingWidth != null) {
     112                        casingWidth = rel_casingWidth.val / 2;
     113                    }
     114                }
     115                if (casingWidth == null)
     116                    return null;
     117                Float widthOnDefault = getWidth(c_def, "width", null);
     118                width = getWidth(c, "width", widthOnDefault);
     119                if (width == null) {
     120                    width = 0f;
     121                }
     122                width += 2 * casingWidth;
     123                break;
     124            }
     125            case LEFT_CASING:
     126            case RIGHT_CASING:
     127                width = getWidth(c, type.prefix + "width", null);
     128                break;
     129            default:
     130                throw new AssertionError();
    101131        }
    102132        if (width == null)
     
    120150        }
    121151
    122         Float offsetOnDefault = getWidth(c_def, "offset", null);
    123         Float offset = getWidth(c, "offset", offsetOnDefault);
    124         if (offset == null) {
    125             offset = 0f;
    126         }
    127         if (type != LineType.NORMAL) {
    128             /* pre-calculate an offset */
    129             Float base_offset = offset;
    130             if (type == LineType.LEFT_CASING || type == LineType.RIGHT_CASING) {
    131                 Float base_width = getWidth(c, "width", widthOnDefault);
    132                 if (base_width == null || base_width < 2f) {
    133                     base_width = 2f;
    134                 }
    135                 offset = base_width/2 + width/2;
    136             } else {
    137                 offset = 0f;
    138             }
    139             /* overwrites (e.g. "4") or adjusts (e.g. "+4") a prefixed -offset */
    140             if (getWidth(c, type.prefix + "offset", offset) != null) {
    141                 offset = getWidth(c, type.prefix + "offset", offset);
    142             }
    143             /* flip sign for the right-casing-offset */
    144             if (type == LineType.RIGHT_CASING) {
    145                 offset *= -1f;
    146             }
    147             /* use base_offset as the reference center */
    148             offset += base_offset;
     152        Float offset = c.get("offset", 0f, Float.class);
     153        switch (type) {
     154            case NORMAL:
     155                break;
     156            case CASING:
     157                offset += c.get(type.prefix + "offset", 0f, Float.class);
     158                break;
     159            case LEFT_CASING:
     160            case RIGHT_CASING:
     161            {
     162                Float baseWidthOnDefault = getWidth(c_def, "width", null);
     163                Float baseWidth = getWidth(c, "width", baseWidthOnDefault);
     164                if (baseWidth == null || baseWidth < 2f) {
     165                    baseWidth = 2f;
     166                }
     167                float casingOffset = c.get(type.prefix + "offset", 0f, Float.class);
     168                casingOffset += baseWidth / 2 + width / 2;
     169                /* flip sign for the right-casing-offset */
     170                if (type == LineType.RIGHT_CASING) {
     171                    casingOffset *= -1f;
     172                }
     173                offset += casingOffset;
     174                break;
     175            }
    149176        }
    150177
Note: See TracChangeset for help on using the changeset viewer.