Changeset 11700 in josm for trunk


Ignore:
Timestamp:
2017-03-08T16:47:38+01:00 (8 years ago)
Author:
michael2402
Message:

Do not hack default opacity into color setting. Use a opacity default of ~.2 instead, so that style authors can overwrite it more easily and the behaviour is more predictable.

File:
1 edited

Legend:

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

    r11689 r11700  
    1212import org.openstreetmap.josm.data.osm.visitor.paint.PaintColors;
    1313import org.openstreetmap.josm.data.osm.visitor.paint.StyledMapRenderer;
     14import org.openstreetmap.josm.data.preferences.IntegerProperty;
    1415import org.openstreetmap.josm.gui.mappaint.Cascade;
    1516import org.openstreetmap.josm.gui.mappaint.Environment;
     
    2425 */
    2526public class AreaElement extends StyleElement {
     27
     28    /**
     29     * The default opacity for the fill. For historical reasons in range 0.255.
     30     */
     31    private static final IntegerProperty DEFAULT_FILL_ALPHA = new IntegerProperty("mappaint.fillalpha", 50);
    2632
    2733    /**
     
    98104            );
    99105
    100             fillImage.alpha = Math.min(255, Math.max(0, Main.pref.getInteger("mappaint.fill-image-alpha", 255)));
     106            fillImage.alpha = Utils.clamp(Main.pref.getInteger("mappaint.fill-image-alpha", 255), 0, 255);
    101107            Integer pAlpha = Utils.colorFloat2int(c.get(FILL_OPACITY, null, float.class));
    102108            if (pAlpha != null) {
     
    106112            color = c.get(FILL_COLOR, null, Color.class);
    107113            if (color != null) {
    108                 int alpha = color.getAlpha();
    109                 if (alpha == 255) {
    110                     // Assume alpha value has not been specified by the user if
    111                     // is set to fully opaque. Use default value in this case.
    112                     // It is not an ideal solution, but a little tricky to get this
    113                     // right, especially as named map colors can be changed in
    114                     // the preference GUI and written to the preferences file.
    115                     alpha = Math.min(255, Math.max(0, Main.pref.getInteger("mappaint.fillalpha", 50)));
    116                 }
    117                 Integer pAlpha = Utils.colorFloat2int(c.get(FILL_OPACITY, null, float.class));
    118                 if (pAlpha != null) {
    119                     alpha = pAlpha;
    120                 }
    121                 color = new Color(color.getRed(), color.getGreen(), color.getBlue(), alpha);
     114                float defaultOpacity = Utils.colorInt2float(DEFAULT_FILL_ALPHA.get());
     115                float opacity = c.get(FILL_OPACITY, defaultOpacity, Float.class);
     116                color = Utils.alphaMultiply(color, opacity);
    122117            }
    123118        }
Note: See TracChangeset for help on using the changeset viewer.