Ignore:
Timestamp:
2011-02-05T18:28:47+01:00 (13 years ago)
Author:
bastiK
Message:

mapcss: support for opacity & icon-image

Location:
trunk/src/org/openstreetmap/josm/gui/mappaint
Files:
9 edited

Legend:

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

    r3856 r3858  
    44import java.awt.Color;
    55
     6import org.openstreetmap.josm.Main;
    67import org.openstreetmap.josm.data.osm.OsmPrimitive;
    78import org.openstreetmap.josm.data.osm.Relation;
     
    2425        if (color == null)
    2526            return null;
     27        int alpha = Math.min(255, Math.max(0, Integer.valueOf(Main.pref.getInteger("mappaint.fillalpha", 50))));
     28        Integer pAlpha = color_float2int(c.get("fill-opacity", null, float.class));
     29        if (pAlpha != null) {
     30            alpha = pAlpha;
     31        }
     32        color = new Color(color.getRed(), color.getGreen(), color.getBlue(), alpha);
    2633        return new AreaElemStyle(c, color);
    2734    }
    2835
    2936    @Override
    30     public void paintPrimitive(OsmPrimitive primitive, MapPaintSettings paintSettings, MapPainter painter, boolean selected, boolean member) {
    31         if (primitive instanceof Way) {
    32             Way w = (Way) primitive;
    33             String name = painter.isShowNames() ? painter.getAreaName(w) : null;
    34             painter.drawArea(w, w.isSelected() ? paintSettings.getSelectedColor() : color, name);
    35         } else if (primitive instanceof Relation) {
    36             painter.drawArea((Relation) primitive, selected ? paintSettings.getRelationSelectedColor() : color, painter.getAreaName(primitive));
     37    public void paintPrimitive(OsmPrimitive osm, MapPaintSettings paintSettings, MapPainter painter, boolean selected, boolean member) {
     38        if (osm instanceof Way)
     39        {
     40            painter.drawArea((Way) osm,
     41                    osm.isSelected() ? paintSettings.getSelectedColor(color.getAlpha()) : color,
     42                    painter.isShowNames() ? painter.getAreaName(osm) : null);
     43        } else if (osm instanceof Relation)
     44        {
     45            painter.drawArea((Relation) osm,
     46                    selected ? paintSettings.getRelationSelectedColor(color.getAlpha()) : color,
     47                    painter.getAreaName(osm));
    3748        }
    3849    }
  • trunk/src/org/openstreetmap/josm/gui/mappaint/Cascade.java

    r3856 r3858  
    160160            if (val instanceof float[]) {
    161161                res.append(Arrays.toString((float[]) val));
     162            } else if (val instanceof Color) {
     163                res.append(String.format("#%x", ((Color) val).getRGB()));
    162164            } else {
    163165                res.append(val+"");
  • trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyle.java

    r3856 r3858  
    4545        return "";
    4646    }
     47
     48    public static Integer color_float2int(Float val) {
     49        if (val == null || val < 0 || val > 1)
     50            return null;
     51        return (int) (255f * val + 0.5f);
     52    }
     53   
     54    public static Float color_int2float(Integer val) {
     55        if (val == null || val < 0 || val > 255)
     56            return null;
     57        return ((float) val) / 255f;
     58    }
    4759}
  • trunk/src/org/openstreetmap/josm/gui/mappaint/LineElemStyle.java

    r3856 r3858  
    6060            color = PaintColors.UNTAGGED.get();
    6161        }
     62
     63        int alpha = 255;
     64        Integer pAlpha = color_float2int(c.get("opacity", null, float.class));
     65        if (pAlpha != null) {
     66            alpha = pAlpha;
     67        }
     68        color = new Color(color.getRed(), color.getGreen(), color.getBlue(), alpha);
     69
    6270        float[] dashes = c.get(prefix + "dashes", null, float[].class);
    6371        if (dashes != null) {
     
    124132            markColor = paintSettings.getHighlightColor();
    125133        } else if (selected) {
    126             markColor = paintSettings.getSelectedColor();
     134            markColor = paintSettings.getSelectedColor(color.getAlpha());
    127135        } else if (member) {
    128             markColor = paintSettings.getRelationSelectedColor();
     136            markColor = paintSettings.getRelationSelectedColor(color.getAlpha());
    129137        } else if(w.isDisabled()) {
    130138            markColor = paintSettings.getInactiveColor();
  • trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java

    r3855 r3858  
    4747
    4848        public String iconName;
    49         public XmlStyleSource source;
    50 
    51         public IconReference(String iconName, XmlStyleSource source) {
     49        public StyleSource source;
     50
     51        public IconReference(String iconName, StyleSource source) {
    5252            this.iconName = iconName;
    5353            this.source = source;
     54        }
     55
     56        @Override
     57        public String toString() {
     58            return "IconReference{" + "iconName=" + iconName + " source=" + source.getDisplayString() + '}';
    5459        }
    5560    }
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Environment.java

    r3848 r3858  
    55import org.openstreetmap.josm.gui.mappaint.Cascade;
    66import org.openstreetmap.josm.gui.mappaint.MultiCascade;
     7import org.openstreetmap.josm.gui.mappaint.StyleSource;
    78
    89public class Environment {
     
    1112    MultiCascade mc;
    1213    String layer;
     14    StyleSource source;
    1315
    14     public Environment(OsmPrimitive osm, MultiCascade mc, String layer) {
     16    public Environment(OsmPrimitive osm, MultiCascade mc, String layer, StyleSource source) {
    1517        this.osm = osm;
    1618        this.mc = mc;
    1719        this.layer = layer;
     20        this.source = source;
    1821    }
    1922
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Instruction.java

    r3848 r3858  
    33
    44import java.util.Arrays;
     5
     6import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.IconReference;
    57
    68abstract public class Instruction {
     
    3234        @Override
    3335        public void execute(Environment env) {
    34             if (val instanceof Expression) {
    35                 env.getCascade().putOrClear(key, ((Expression) val).evaluate(env));
    36             } else {
    37                 env.getCascade().putOrClear(key, val);
     36            Object value = (val instanceof Expression) ? ((Expression) val).evaluate(env) : val;
     37            if (key.equals("icon-image")) {
     38                if (value instanceof String) {
     39                    value = new IconReference((String) value, env.source);
     40                }
    3841            }
     42            env.getCascade().putOrClear(key, value);
    3943        }
    4044
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java

    r3856 r3858  
    8080        n.put("lang", code);
    8181        // create a fake environment to read the meta data block
    82         Environment env = new Environment(n, mc, "default");
     82        Environment env = new Environment(n, mc, "default", this);
    8383
    8484        NEXT_RULE:
     
    105105    @Override
    106106    public void apply(MultiCascade mc, OsmPrimitive osm, double scale, OsmPrimitive multipolyOuterWay, boolean pretendWayIsClosed) {
    107         Environment env = new Environment(osm, mc, null);
     107        Environment env = new Environment(osm, mc, null, this);
    108108        for (MapCSSRule r : rules) {
    109109            for (Selector s : r.selectors) {
  • trunk/src/org/openstreetmap/josm/gui/mappaint/xml/XmlStyleSource.java

    r3856 r3858  
    2020import org.openstreetmap.josm.data.osm.Way;
    2121import org.openstreetmap.josm.gui.mappaint.Cascade;
     22import org.openstreetmap.josm.gui.mappaint.ElemStyle;
    2223import org.openstreetmap.josm.gui.mappaint.MultiCascade;
    2324import org.openstreetmap.josm.gui.mappaint.Range;
     
    300301                def.putOrClear("real-width", p.line.realWidth != null ? new Float(p.line.realWidth) : null);
    301302                def.putOrClear("color", p.line.color);
     303                if (p.line.color != null) {
     304                    int alpha = p.line.color.getAlpha();
     305                    if (alpha != 255) {
     306                        def.put("opacity", ElemStyle.color_int2float(alpha));
     307                    }
     308                }
    302309                def.putOrClear("dashes", p.line.getDashed());
    303310                def.putOrClear("dashes-background-color", p.line.dashedColor);
     
    323330                    c.put("width", new Float(mod.getWidth(refWidth)));
    324331                    c.putOrClear("color", mod.color);
     332                    if (mod.color != null) {
     333                        int alpha = mod.color.getAlpha();
     334                        if (alpha != 255) {
     335                            c.put("opacity", ElemStyle.color_int2float(alpha));
     336                        }
     337                    }
    325338                    c.putOrClear("dashes", mod.getDashed());
    326339                    c.putOrClear("dashes-background-color", mod.dashedColor);
Note: See TracChangeset for help on using the changeset viewer.