Changeset 7136 in josm for trunk/src


Ignore:
Timestamp:
2014-05-17T23:52:55+02:00 (10 years ago)
Author:
bastiK
Message:

mapcss: add support for alpha info in color property, e.g.
color: #aa0022ee; or color: rgba(1.0, 0.2, 0.8, 0.8);
*opacity properties still have higher priority, if specified
explicitly

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

Legend:

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

    r7083 r7136  
    5555            color = c.get(FILL_COLOR, null, Color.class);
    5656            if (color != null) {
    57                 int alpha = Math.min(255, Math.max(0, Integer.valueOf(Main.pref.getInteger("mappaint.fillalpha", 50))));
     57                int alpha = color.getAlpha();
     58                if (alpha == 255) {
     59                    // Assume alpha value has not been specified by the user if
     60                    // is set to fully opaque. Use default value in this case.
     61                    // It is not an ideal solution, but a little tricky to get this
     62                    // right, especially as named map colors can be changed in
     63                    // the preference GUI and written to the preferences file.
     64                    alpha = Math.min(255, Math.max(0, Integer.valueOf(Main.pref.getInteger("mappaint.fillalpha", 50))));
     65                }
    5866                Integer pAlpha = Utils.color_float2int(c.get(FILL_OPACITY, null, float.class));
    5967                if (pAlpha != null) {
  • trunk/src/org/openstreetmap/josm/gui/mappaint/LineElemStyle.java

    r7083 r7136  
    2424        c.put(WIDTH, Keyword.DEFAULT);
    2525        c.put(COLOR, color != null ? color : PaintColors.UNTAGGED.get());
     26        c.put(OPACITY, 1f);
    2627        if (isAreaEdge) {
    2728            c.put(Z_INDEX, -3f);
     
    169170        }
    170171
     172        int alpha = 255;
    171173        Color color = c.get(type.prefix + COLOR, null, Color.class);
     174        if (color != null) {
     175            alpha = color.getAlpha();
     176        }
    172177        if (type == LineType.NORMAL && color == null) {
    173178            color = c.get(FILL_COLOR, null, Color.class);
     
    177182        }
    178183
    179         int alpha = 255;
    180184        Integer pAlpha = Utils.color_float2int(c.get(type.prefix + OPACITY, null, Float.class));
    181185        if (pAlpha != null) {
  • trunk/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java

    r7099 r7136  
    216216        Stroke stroke = null;
    217217        if (strokeColor != null) {
    218             float strokeAlpha = c.get("symbol-stroke-opacity", 1f, Float.class);
    219             strokeColor = new Color(strokeColor.getRed(), strokeColor.getGreen(),
    220                     strokeColor.getBlue(), Utils.color_float2int(strokeAlpha));
     218            Integer strokeAlpha = Utils.color_float2int(c.get("symbol-stroke-opacity", null, Float.class));
     219            if (strokeAlpha != null) {
     220                strokeColor = new Color(strokeColor.getRed(), strokeColor.getGreen(),
     221                        strokeColor.getBlue(), strokeAlpha);
     222            }
    221223            stroke = new BasicStroke(strokeWidth);
    222224        }
     
    228230
    229231        if (fillColor != null) {
    230             float fillAlpha = c.get("symbol-fill-opacity", 1f, Float.class);
    231             fillColor = new Color(fillColor.getRed(), fillColor.getGreen(),
    232                     fillColor.getBlue(), Utils.color_float2int(fillAlpha));
     232            Integer fillAlpha = Utils.color_float2int(c.get("symbol-fill-opacity", null, Float.class));
     233            if (fillAlpha != null) {
     234                fillColor = new Color(fillColor.getRed(), fillColor.getGreen(),
     235                        fillColor.getBlue(), fillAlpha);
     236            }
    233237        }
    234238
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactory.java

    r7103 r7136  
    202202         */
    203203        public static Color rgb(float r, float g, float b) {
    204             Color c;
    205204            try {
    206                 c = new Color(r, g, b);
     205                return new Color(r, g, b);
    207206            } catch (IllegalArgumentException e) {
    208207                return null;
    209208            }
    210             return c;
     209        }
     210       
     211        public static Color rgba(float r, float g, float b, float alpha) {
     212            try {
     213                return new Color(r, g, b, alpha);
     214            } catch (IllegalArgumentException e) {
     215                return null;
     216            }
    211217        }
    212218
Note: See TracChangeset for help on using the changeset viewer.