Ignore:
Timestamp:
2013-08-21T18:15:12+02:00 (11 years ago)
Author:
Don-vip
Message:

fix #8849:

  • Used scaled down (16x16 pixels) of large (.svg) images if no size is explicitely defined
  • rendering of emergency=aed with recently added svg
  • optimizations/refactoring in icons rotating/rescaling code
  • fix of various warnings, javadoc
File:
1 edited

Legend:

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

    r5812 r6172  
    66import java.awt.BasicStroke;
    77import java.awt.Color;
     8import java.awt.Image;
    89import java.awt.Rectangle;
    910import java.awt.Stroke;
     
    1920import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.IconReference;
    2021import org.openstreetmap.josm.gui.mappaint.StyleCache.StyleList;
     22import org.openstreetmap.josm.tools.ImageProvider;
    2123import org.openstreetmap.josm.tools.Utils;
    2224
     
    2527 */
    2628public class NodeElemStyle extends ElemStyle implements StyleKeys {
    27     public MapImage mapImage;
    28     public Symbol symbol;
     29    public final MapImage mapImage;
     30    public final Symbol symbol;
     31   
     32    private Image enabledNodeIcon;
     33    private Image disabledNodeIcon;
    2934
    3035    public enum SymbolShape { SQUARE, CIRCLE, TRIANGLE, PENTAGON, HEXAGON, HEPTAGON, OCTAGON, NONAGON, DECAGON }
     
    230235    }
    231236
     237    private Image getRealNodeIcon(final Image image) {
     238        final int maxSize = 16;
     239        // Scale down large (.svg) images to 16x16 pixels if no size is explicitely specified
     240        if ((mapImage.width  == -1 && image.getWidth(null) > maxSize)
     241         || (mapImage.height == -1 && image.getHeight(null) > maxSize)) {
     242            return ImageProvider.createBoundedImage(image, maxSize);
     243        } else {
     244            return image;
     245        }
     246    }
     247   
    232248    @Override
    233249    public void paintPrimitive(OsmPrimitive primitive, MapPaintSettings settings, StyledMapRenderer painter, boolean selected, boolean member) {
     
    235251            Node n = (Node) primitive;
    236252            if (mapImage != null && painter.isShowIcons()) {
    237                 painter.drawNodeIcon(n, (painter.isInactiveMode() || n.isDisabled()) ? mapImage.getDisabled() : mapImage.getImage(),
    238                         Utils.color_int2float(mapImage.alpha), selected, member);
     253                final Image nodeIcon;
     254                if (painter.isInactiveMode() || n.isDisabled()) {
     255                    if (disabledNodeIcon == null) {
     256                        disabledNodeIcon = getRealNodeIcon(mapImage.getDisabled());
     257                    }
     258                    nodeIcon = disabledNodeIcon;
     259                } else {
     260                    if (enabledNodeIcon == null) {
     261                        enabledNodeIcon = getRealNodeIcon(mapImage.getImage());
     262                    }
     263                    nodeIcon = enabledNodeIcon;
     264                }
     265                painter.drawNodeIcon(n, nodeIcon, Utils.color_int2float(mapImage.alpha), selected, member);
    239266            } else if (symbol != null) {
    240267                Color fillColor = symbol.fillColor;
Note: See TracChangeset for help on using the changeset viewer.