Ignore:
Timestamp:
2011-07-27T23:50:06+02:00 (13 years ago)
Author:
bastiK
Message:

mapcss: proper support for scaled icons (fixes #6560)

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

Legend:

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

    r4005 r4272  
    4545        IconReference iconRef = c.get("fill-image", null, IconReference.class);
    4646        if (iconRef != null) {
    47             ImageIcon icon = MapPaintStyles.getIcon(iconRef, false);
     47            ImageIcon icon = MapPaintStyles.getIcon(iconRef, -1, -1, false);
    4848            if (icon != null) {
    4949                if (!(icon.getImage() instanceof BufferedImage)) {
    50                     icon = MapPaintStyles.getIcon(iconRef, true);
     50                    icon = MapPaintStyles.getIcon(iconRef, -1, -1, true);
    5151                }
    5252                if (!(icon.getImage() instanceof BufferedImage))
  • trunk/src/org/openstreetmap/josm/gui/mappaint/LinePatternElemStyle.java

    r4006 r4272  
    2828        if (iconRef == null)
    2929            return null;
    30         ImageIcon icon = MapPaintStyles.getIcon(iconRef, false);
     30        ImageIcon icon = MapPaintStyles.getIcon(iconRef, -1, -1, false);
    3131        if (icon == null)
    3232            return null;
  • trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java

    r4172 r4272  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
     6import java.awt.Dimension;
    67import java.io.IOException;
    78import java.io.InputStream;
     
    6364    }
    6465
     66    /**
     67     * IconReference is used to remember the associated style source for
     68     * each icon URL.
     69     * This is necessary because image URLs can be paths relative
     70     * to the source file and we have cascading of properties from different
     71     * source files.
     72     */
    6573    public static class IconReference {
    6674
     
    7987    }
    8088
    81     public static ImageIcon getIcon(IconReference ref, boolean sanitize) {
    82         String namespace = ref.source.getPrefName();
    83         ImageIcon i = ImageProvider.getIfAvailable(getIconSourceDirs(ref.source), "mappaint."+namespace, null, ref.iconName, ref.source.zipIcons, sanitize);
     89    public static ImageIcon getIcon(IconReference ref, int width, int height, boolean sanitize) {
     90        final String namespace = ref.source.getPrefName();
     91        ImageIcon i = ImageProvider.getIfAvailable(getIconSourceDirs(ref.source), "mappaint."+namespace, null, ref.iconName, ref.source.zipIcons, width == -1 && height == -1 ? null : new Dimension(width, height), sanitize);
    8492        if(i == null)
    8593        {
  • trunk/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java

    r4191 r4272  
    66import java.awt.BasicStroke;
    77import java.awt.Color;
     8import java.awt.Dimension;
    89import java.awt.Image;
    910import java.awt.Stroke;
     
    221222            return null;
    222223
    223         ImageIcon icon = null;
    224         int iconAlpha = 0;
    225 
    226         icon = MapPaintStyles.getIcon(iconRef, false);
     224        Float widthOnDefault = c_def.get("icon-width", null, Float.class);
     225        if (widthOnDefault != null && widthOnDefault <= 0) {
     226            widthOnDefault = null;
     227        }
     228        Float widthF = getWidth(c, "icon-width", widthOnDefault);
     229
     230        Float heightOnDefault = c_def.get("icon-height", null, Float.class);
     231        if (heightOnDefault != null && heightOnDefault <= 0) {
     232            heightOnDefault = null;
     233        }
     234        Float heightF = getWidth(c, "icon-height", heightOnDefault);
     235
     236        int width = widthF == null ? -1 : Math.round(widthF);
     237        int height = heightF == null ? -1 : Math.round(heightF);
     238
     239        ImageIcon icon = MapPaintStyles.getIcon(iconRef, width, height, false);
    227240        if (icon == null)
    228241            return new Pair<ImageIcon, Integer>(MapPaintStyles.getNoIcon_Icon(iconRef.source, false), 255);
    229         else {
    230             Float sizeOnDefault = c_def.get("icon-size", null, Float.class);
    231             if (sizeOnDefault != null && sizeOnDefault <= 0) {
    232                 sizeOnDefault = null;
    233             }
    234             Float sizeF = getWidth(c, "icon-size", sizeOnDefault);
    235 
    236             if (sizeF != null) {
    237                 if (sizeF <= 0)
    238                     return null;
    239                 int size = Math.round(sizeF);
    240                 int width = icon.getIconWidth();
    241                 int height = icon.getIconHeight();
    242                 if (Math.max(width, height) != size) {
    243                     if (width >= height) {
    244                         width = size;
    245                         height = -1;
    246                     } else {
    247                         width = -1;
    248                         height = size;
    249                     }
    250                     icon.setImage(icon.getImage().getScaledInstance(width, height, Image.SCALE_SMOOTH));
    251                 }
    252             }
    253             iconAlpha = Math.min(255, Math.max(0, Integer.valueOf(Main.pref.getInteger("mappaint.icon-image-alpha", 255))));
    254             Integer pAlpha = Utils.color_float2int(c.get("icon-opacity", null, float.class));
    255             if (pAlpha != null) {
    256                 iconAlpha = pAlpha;
    257             }
    258 
    259             return new Pair<ImageIcon, Integer>(icon, iconAlpha);
    260         }
     242        int iconAlpha = Math.min(255, Math.max(0, Integer.valueOf(Main.pref.getInteger("mappaint.icon-image-alpha", 255))));
     243        Integer pAlpha = Utils.color_float2int(c.get("icon-opacity", null, float.class));
     244        if (pAlpha != null) {
     245            iconAlpha = pAlpha;
     246        }
     247
     248        return new Pair<ImageIcon, Integer>(icon, iconAlpha);
    261249    }
    262250
  • trunk/src/org/openstreetmap/josm/gui/mappaint/StyleSource.java

    r3896 r4272  
    7474        if (imageIcon == null) {
    7575            if (icon != null) {
    76                 imageIcon = MapPaintStyles.getIcon(new IconReference(icon, this), false);
     76                imageIcon = MapPaintStyles.getIcon(new IconReference(icon, this), -1, -1, false);
    7777            }
    7878            if (imageIcon == null) {
Note: See TracChangeset for help on using the changeset viewer.