Changeset 5217 in josm for trunk


Ignore:
Timestamp:
2012-05-06T21:23:18+02:00 (7 years ago)
Author:
bastiK
Message:

mapcss: change z-index handling

In contrast to previous default z-index of 1000 for nodes and -1000 for areas, the default z-index is
now always 0. An additional "major-z-index" is used to sort elemstyles by category, this property
can be adjusted in the style, so icons can be rendered below lines, if you want to.

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

Legend:

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

    r4327 r5217  
    2828/**
    2929 * <p>A map renderer which renders a map according to style rules in a set of style sheets.</p>
    30  * 
     30 *
    3131 */
    3232public class StyledMapRenderer extends AbstractMapRenderer{
     
    3939    private static int FLAG_NORMAL = 0;
    4040    private static int FLAG_DISABLED = 1;
    41     private static int FLAG_SELECTED = 2;
    42     private static int FLAG_MEMBER_OF_SELECTED = 4;
     41    private static int FLAG_MEMBER_OF_SELECTED = 2;
     42    private static int FLAG_SELECTED = 4;
    4343
    4444    private static class StyleRecord implements Comparable<StyleRecord> {
     
    5959            if ((this.flags & FLAG_DISABLED) == 0 && (other.flags & FLAG_DISABLED) != 0)
    6060                return 1;
    61             float z_index1 = this.style.z_index;
    62             if ((this.flags & FLAG_SELECTED) != 0) {
    63                 z_index1 += 700f;
    64             } else if ((this.flags & FLAG_MEMBER_OF_SELECTED) != 0) {
    65                 z_index1 += 600f;
    66             }
    67             float z_index2 = other.style.z_index;
    68             if ((other.flags & FLAG_SELECTED) != 0) {
    69                 z_index2 += 700f;
    70             } else if ((other.flags & FLAG_MEMBER_OF_SELECTED) != 0) {
    71                 z_index2 += 600f;
    72             }
    73 
    74             int d1 = Float.compare(z_index1, z_index2);
    75             if (d1 != 0)
    76                 return d1;
     61
     62            int d0 = Float.compare(this.style.major_z_index, other.style.major_z_index);
     63            if (d0 != 0)
     64                return d0;
     65
     66            // selected on top of member of selected on top of unselected
     67            // FLAG_DISABLED bit is the same at this point
     68            if (this.flags > other.flags)
     69                return 1;
     70            if (this.flags < other.flags)
     71                return -1;
     72
     73            int dz = Float.compare(this.style.z_index, other.style.z_index);
     74            if (dz != 0)
     75                return dz;
    7776
    7877            // simple node on top of icons and shapes
  • trunk/src/org/openstreetmap/josm/gui/mappaint/AreaElemStyle.java

    r5054 r5217  
    2828
    2929    protected AreaElemStyle(Cascade c, Color color, MapImage fillImage, TextElement text) {
    30         super(c, -1000f);
     30        super(c, 1f);
    3131        CheckParameterUtil.ensureParameterNotNull(color);
    3232        this.color = color;
  • trunk/src/org/openstreetmap/josm/gui/mappaint/BoxTextElemStyle.java

    r5054 r5217  
    9090
    9191    public BoxTextElemStyle(Cascade c, TextElement text, BoxProvider boxProvider, Rectangle box, HorizontalTextAlignment hAlign, VerticalTextAlignment vAlign) {
    92         super(c, 2000f);
     92        super(c, 5f);
    9393        CheckParameterUtil.ensureParameterNotNull(text);
    9494        CheckParameterUtil.ensureParameterNotNull(hAlign);
     
    197197        if (boxProvider != null) {
    198198            if (!boxProvider.equals(other.boxProvider)) return false;
    199         } else if (other.boxProvider != null) {
     199        } else if (other.boxProvider != null)
    200200            return false;
    201         } else {
     201        else {
    202202            if (!box.equals(other.box)) return false;
    203203        }
  • trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyle.java

    r4040 r5217  
    1616abstract public class ElemStyle {
    1717
     18    public float major_z_index;
    1819    public float z_index;
    1920    public float object_z_index;
     
    2122    // primitive; true, if it is a highlight or modifier
    2223
    23     public ElemStyle(float z_index, float object_z_index, boolean isModifier) {
     24    public ElemStyle(float major_z_index, float z_index, float object_z_index, boolean isModifier) {
     25        this.major_z_index = major_z_index;
    2426        this.z_index = z_index;
    2527        this.object_z_index = object_z_index;
     
    2729    }
    2830
    29     protected ElemStyle(Cascade c, float default_z_index) {
    30         z_index = c.get("z-index", default_z_index, Float.class);
     31    protected ElemStyle(Cascade c, float default_major_z_index) {
     32        major_z_index = c.get("major-z-index", default_major_z_index, Float.class);
     33        z_index = c.get("z-index", 0f, Float.class);
    3134        object_z_index = c.get("object-z-index", 0f, Float.class);
    3235        isModifier = c.get("modifier", false, Boolean.class);
     
    8184     * expensive lookups and to avoid too many font objects
    8285     * (in analogy to flyweight pattern).
    83      * 
     86     *
    8487     * FIXME: cached preference values are not updated if the user changes them during
    8588     * a JOSM session. Should have a listener listening to preference changes.
     
    170173            return false;
    171174        ElemStyle s = (ElemStyle) o;
    172         return z_index == s.z_index && object_z_index == s.object_z_index && isModifier == s.isModifier;
     175        return major_z_index == s.major_z_index &&
     176                z_index == s.z_index &&
     177                object_z_index == s.object_z_index &&
     178                isModifier == s.isModifier;
    173179    }
    174180
     
    176182    public int hashCode() {
    177183        int hash = 5;
     184        hash = 41 * hash + Float.floatToIntBits(this.major_z_index);
    178185        hash = 41 * hash + Float.floatToIntBits(this.z_index);
    179186        hash = 41 * hash + Float.floatToIntBits(this.object_z_index);
     
    184191    @Override
    185192    public String toString() {
    186         if (z_index != 0f || object_z_index != 0f)
    187             return String.format("z_idx=%s/%s ", z_index, object_z_index) + (isModifier ? "modifier " : "");
    188         return "";
     193        return String.format("z_idx=[%s/%s/%s] ", major_z_index, z_index, object_z_index) + (isModifier ? "modifier " : "");
    189194    }
    190195}
  • trunk/src/org/openstreetmap/josm/gui/mappaint/LineElemStyle.java

    r5214 r5217  
    4040
    4141    protected enum LineType {
    42         NORMAL(""),
    43         CASING("casing-"),
    44         LEFT_CASING("left-casing-"),
    45         RIGHT_CASING("right-casing-");
    46 
    47         public String prefix;
    48 
    49         LineType(String prefix) {
     42        NORMAL("", 3f),
     43        CASING("casing-", 2f),
     44        LEFT_CASING("left-casing-", 2.1f),
     45        RIGHT_CASING("right-casing-", 2.1f);
     46
     47        public final String prefix;
     48        public final float default_major_z_index;
     49
     50        LineType(String prefix, float default_major_z_index) {
    5051            this.prefix = prefix;
    51         }
    52     }
    53 
    54     protected LineElemStyle(Cascade c, BasicStroke line, Color color, BasicStroke dashesLine, Color dashesBackground, float offset, float realWidth) {
    55         super(c, 0f);
     52            this.default_major_z_index = default_major_z_index;
     53        }
     54    }
     55
     56    protected LineElemStyle(Cascade c, float default_major_z_index, BasicStroke line, Color color, BasicStroke dashesLine, Color dashesBackground, float offset, float realWidth) {
     57        super(c, default_major_z_index);
    5658        this.line = line;
    5759        this.color = color;
     
    6971        LineElemStyle leftCasing = createImpl(env, LineType.LEFT_CASING);
    7072        if (leftCasing != null) {
    71             leftCasing.z_index += -90;
    7273            leftCasing.isModifier = true;
    7374        }
     
    7879        LineElemStyle rightCasing = createImpl(env, LineType.RIGHT_CASING);
    7980        if (rightCasing != null) {
    80             rightCasing.z_index += -90;
    8181            rightCasing.isModifier = true;
    8282        }
     
    8787        LineElemStyle casing = createImpl(env, LineType.CASING);
    8888        if (casing != null) {
    89             casing.z_index += -100;
    9089            casing.isModifier = true;
    9190        }
     
    263262        }
    264263
    265         return new LineElemStyle(c, line, color, dashesLine, dashesBackground, offset, realWidth);
     264        return new LineElemStyle(c, type.default_major_z_index, line, color, dashesLine, dashesBackground, offset, realWidth);
    266265    }
    267266
  • trunk/src/org/openstreetmap/josm/gui/mappaint/LinePatternElemStyle.java

    r5054 r5217  
    1616
    1717    public LinePatternElemStyle(Cascade c, MapImage pattern) {
    18         super(c, -1f);
     18        super(c, 2.9f);
    1919        this.pattern = pattern;
    2020    }
  • trunk/src/org/openstreetmap/josm/gui/mappaint/LineTextElemStyle.java

    r4281 r5217  
    1010
    1111public class LineTextElemStyle extends ElemStyle {
    12    
     12
    1313    private TextElement text;
    1414
    1515    protected LineTextElemStyle(Cascade c, TextElement text) {
    16         super(c, 2f);
     16        super(c, 4.9f);
    1717        this.text = text;
    1818    }
  • trunk/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java

    r5054 r5217  
    1515import org.openstreetmap.josm.data.osm.visitor.paint.MapPaintSettings;
    1616import org.openstreetmap.josm.data.osm.visitor.paint.MapPainter;
     17import org.openstreetmap.josm.gui.mappaint.BoxTextElemStyle.BoxProvider;
     18import org.openstreetmap.josm.gui.mappaint.BoxTextElemStyle.SimpleBoxProvider;
    1719import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.IconReference;
    1820import org.openstreetmap.josm.gui.mappaint.StyleCache.StyleList;
    19 import org.openstreetmap.josm.gui.mappaint.BoxTextElemStyle.BoxProvider;
    20 import org.openstreetmap.josm.gui.mappaint.BoxTextElemStyle.SimpleBoxProvider;
    21 import org.openstreetmap.josm.tools.Pair;
    2221import org.openstreetmap.josm.tools.Utils;
    2322
     
    8584        MultiCascade mc = new MultiCascade();
    8685        Cascade c = mc.getOrCreateCascade("default");
    87         SIMPLE_NODE_ELEMSTYLE = create(new Environment(null, mc, "default", null), true);
     86        SIMPLE_NODE_ELEMSTYLE = create(new Environment(null, mc, "default", null), 4.1f, true);
    8887        if (SIMPLE_NODE_ELEMSTYLE == null) throw new AssertionError();
    8988    }
     
    9291    public static final StyleList DEFAULT_NODE_STYLELIST_TEXT = new StyleList(NodeElemStyle.SIMPLE_NODE_ELEMSTYLE, BoxTextElemStyle.SIMPLE_NODE_TEXT_ELEMSTYLE);
    9392
    94     protected NodeElemStyle(Cascade c, MapImage mapImage, Symbol symbol) {
    95         super(c, 1000f);
     93    protected NodeElemStyle(Cascade c, MapImage mapImage, Symbol symbol, float default_major_z_index) {
     94        super(c, default_major_z_index);
    9695        this.mapImage = mapImage;
    9796        this.symbol = symbol;
     
    9998
    10099    public static NodeElemStyle create(Environment env) {
    101         return create(env, false);
    102     }
    103 
    104     private static NodeElemStyle create(Environment env, boolean allowDefault) {
     100        return create(env, 4f, false);
     101    }
     102
     103    private static NodeElemStyle create(Environment env, float default_major_z_index, boolean allowDefault) {
    105104        Cascade c = env.mc.getCascade(env.layer);
    106105
     
    116115        if (!allowDefault && symbol == null && mapImage == null) return null;
    117116
    118         return new NodeElemStyle(c, mapImage, symbol);
     117        return new NodeElemStyle(c, mapImage, symbol, default_major_z_index);
    119118    }
    120119
     
    302301
    303302    public BoxProvider getBoxProvider() {
    304         if (mapImage != null) {
     303        if (mapImage != null)
    305304            return mapImage.getBoxProvider();
    306         } else if (symbol != null) {
     305        else if (symbol != null)
    307306            return new SimpleBoxProvider(new Rectangle(-symbol.size/2, -symbol.size/2, symbol.size, symbol.size));
    308         } else {
     307        else {
    309308            // This is only executed once, so no performance concerns.
    310309            // However, it would be better, if the settings could be changed at runtime.
Note: See TracChangeset for help on using the changeset viewer.