Changeset 8085 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2015-02-18T23:43:28+01:00 (5 years ago)
Author:
bastiK
Message:

fixed #10216 Offsetting node icon in MapCSS

also: rework of rendering of disabled layers and objects

Location:
trunk/src/org/openstreetmap/josm
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java

    r7801 r8085  
    428428    }
    429429
    430     protected void drawArea(OsmPrimitive osm, Path2D.Double path, Color color, MapImage fillImage, TextElement text) {
     430    protected void drawArea(OsmPrimitive osm, Path2D.Double path, Color color, MapImage fillImage, boolean disabled, TextElement text) {
    431431
    432432        Shape area = path.createTransformedShape(nc.getAffineTransform());
     
    440440                g.fill(area);
    441441            } else {
    442                 TexturePaint texture = new TexturePaint(fillImage.getImage(),
     442                TexturePaint texture = new TexturePaint(fillImage.getImage(disabled),
    443443                        new Rectangle(0, 0, fillImage.getWidth(), fillImage.getHeight()));
    444444                g.setPaint(texture);
    445                 Float alpha = Utils.color_int2float(fillImage.alpha);
     445                Float alpha = fillImage.getAlphaFloat();
    446446                if (alpha != 1f) {
    447447                    g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
     
    529529    }
    530530
    531     public void drawArea(Relation r, Color color, MapImage fillImage, TextElement text) {
     531    public void drawArea(Relation r, Color color, MapImage fillImage, boolean disabled, TextElement text) {
    532532        Multipolygon multipolygon = MultipolygonCache.getInstance().get(nc, r);
    533533        if (!r.isDisabled() && !multipolygon.getOuterWays().isEmpty()) {
     
    539539                drawArea(r, p,
    540540                        pd.selected ? paintSettings.getRelationSelectedColor(color.getAlpha()) : color,
    541                                 fillImage, text);
    542             }
    543         }
    544     }
    545 
    546     public void drawArea(Way w, Color color, MapImage fillImage, TextElement text) {
    547         drawArea(w, getPath(w), color, fillImage, text);
     541                                fillImage, disabled, text);
     542            }
     543        }
     544    }
     545
     546    public void drawArea(Way w, Color color, MapImage fillImage, boolean disabled, TextElement text) {
     547        drawArea(w, getPath(w), color, fillImage, disabled, text);
    548548    }
    549549
     
    617617     * can be aligned with the way.
    618618     */
    619     public void drawRepeatImage(Way way, Image pattern, float offset, float spacing, float phase, LineImageAlignment align) {
    620         final int imgWidth = pattern.getWidth(null);
     619    public void drawRepeatImage(Way way, MapImage pattern, boolean disabled, float offset, float spacing, float phase, LineImageAlignment align) {
     620        final int imgWidth = pattern.getWidth();
    621621        final double repeat = imgWidth + spacing;
    622         final int imgHeight = pattern.getHeight(null);
     622        final int imgHeight = pattern.getHeight();
    623623
    624624        Point lastP = null;
     
    669669                    // segment is too short for a complete image
    670670                    if (pos > segmentLength + spacing) {
    671                         g.drawImage(pattern, 0, dy1, (int) segmentLength, dy2,
     671                        g.drawImage(pattern.getImage(disabled), 0, dy1, (int) segmentLength, dy2,
    672672                                (int) (repeat - pos), 0,
    673673                                (int) (repeat - pos + segmentLength), imgHeight, null);
    674674                    // rest of the image fits fully on the current segment
    675675                    } else {
    676                         g.drawImage(pattern, 0, dy1, (int) (pos - spacing), dy2,
     676                        g.drawImage(pattern.getImage(disabled), 0, dy1, (int) (pos - spacing), dy2,
    677677                                (int) (repeat - pos), 0, imgWidth, imgHeight, null);
    678678                    }
     
    682682                    // cut off at the end?
    683683                    if (pos + imgWidth > segmentLength) {
    684                         g.drawImage(pattern, (int) pos, dy1, (int) segmentLength, dy2,
     684                        g.drawImage(pattern.getImage(disabled), (int) pos, dy1, (int) segmentLength, dy2,
    685685                                0, 0, (int) segmentLength - (int) pos, imgHeight, null);
    686686                    } else {
    687                         g.drawImage(pattern, (int) pos, dy1, nc);
     687                        g.drawImage(pattern.getImage(disabled), (int) pos, dy1, nc);
    688688                    }
    689689                    pos += repeat;
     
    725725    }
    726726
    727     public void drawNodeIcon(Node n, Image img, float alpha, boolean selected, boolean member) {
     727    public void drawNodeIcon(Node n, MapImage img, boolean disabled, boolean selected, boolean member) {
    728728        Point p = nc.getPoint(n);
    729729
    730         final int w = img.getWidth(null), h=img.getHeight(null);
     730        final int w = img.getWidth(), h = img.getHeight();
    731731        if(n.isHighlighted()) {
    732732            drawPointHighlight(p, Math.max(w, h));
    733733        }
    734734
     735        float alpha = img.getAlphaFloat();
     736
    735737        if (alpha != 1f) {
    736738            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
    737739        }
    738         g.drawImage(img, p.x-w/2, p.y-h/2, nc);
     740        g.drawImage(img.getImage(disabled), p.x - w/2 + img.offsetX, p.y - h/2 + img.offsetY, nc);
    739741        g.setPaintMode();
    740742        if (selected || member)
    741743        {
    742744            Color color;
    743             if (isInactiveMode || n.isDisabled()) {
     745            if (disabled) {
    744746                color = inactiveColor;
    745747            } else if (selected) {
     
    749751            }
    750752            g.setColor(color);
    751             g.drawRect(p.x-w/2-2, p.y-h/2-2, w+4, h+4);
     753            g.drawRect(p.x - w/2 + img.offsetX - 2, p.y - h/2 + img.offsetY - 2, w + 4, h + 4);
    752754        }
    753755    }
     
    888890    }
    889891
    890     public void drawRestriction(Relation r, MapImage icon) {
     892    public void drawRestriction(Relation r, MapImage icon, boolean disabled) {
    891893        Way fromWay = null;
    892894        Way toWay = null;
     
    10571059        }
    10581060
    1059         drawRestriction(isInactiveMode || r.isDisabled() ? icon.getDisabled() : icon.getImage(),
     1061        drawRestriction(icon.getImage(disabled),
    10601062                pVia, vx, vx2, vy, vy2, iconAngle, r.isSelected());
    10611063    }
  • trunk/src/org/openstreetmap/josm/gui/mappaint/AreaElemStyle.java

    r7621 r8085  
    4242        if (iconRef != null) {
    4343            fillImage = new MapImage(iconRef.iconName, iconRef.source);
    44             fillImage.getImage();
    4544
    46             color = new Color(fillImage.getImage().getRGB(
     45            color = new Color(fillImage.getImage(false).getRGB(
    4746                    fillImage.getWidth() / 2, fillImage.getHeight() / 2)
    4847            );
     
    9796                }
    9897            }
    99             painter.drawArea((Way) osm, myColor, fillImage, text);
     98            painter.drawArea((Way) osm, myColor, fillImage, painter.isInactiveMode() || osm.isDisabled(), text);
    10099        } else if (osm instanceof Relation) {
    101100            if (color != null && (selected || outermember)) {
    102101                myColor = paintSettings.getRelationSelectedColor(color.getAlpha());
    103102            }
    104             painter.drawArea((Relation) osm, myColor, fillImage, text);
     103            painter.drawArea((Relation) osm, myColor, fillImage, painter.isInactiveMode() || osm.isDisabled(), text);
    105104        }
    106105    }
  • trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyle.java

    r7621 r8085  
    1414public abstract class ElemStyle implements StyleKeys {
    1515
    16     protected static final String[] ICON_KEYS = {"icon-image", "icon-width", "icon-height", "icon-opacity"};
    17     protected static final String[] REPEAT_IMAGE_KEYS = {"repeat-image", "repeat-image-width", "repeat-image-height", "repeat-image-opacity"};
     16    protected static final String[] ICON_KEYS = {"icon-image", "icon-width", "icon-height", "icon-opacity", "icon-offset-x", "icon-offset-y"};
     17    protected static final String[] REPEAT_IMAGE_KEYS = {"repeat-image", "repeat-image-width", "repeat-image-height", "repeat-image-opacity", null, null};
    1818
    1919    public float major_z_index;
  • trunk/src/org/openstreetmap/josm/gui/mappaint/MapImage.java

    r7083 r8085  
    22package org.openstreetmap.josm.gui.mappaint;
    33
     4import java.awt.Graphics;
    45import java.awt.Image;
    56import java.awt.Rectangle;
     
    1718import org.openstreetmap.josm.tools.Utils;
    1819
     20/**
     21 * An image that will be displayed on the map.
     22 */
    1923public class MapImage {
    2024
     
    2630    private BufferedImage img;
    2731
    28     /**
    29      * The 5 following fields are only used to check for equality.
    30      */
    3132    public int alpha = 255;
    3233    public String name;
     
    3435    public int width = -1;
    3536    public int height = -1;
     37    public int offsetX = 0;
     38    public int offsetY = 0;
    3639
    3740    private boolean temporary;
    38     private Image disabledImgCache;
     41    private BufferedImage disabledImgCache;
    3942
    4043    public MapImage(String name, StyleSource source) {
     
    4346    }
    4447
    45     public Image getDisabled() {
     48    /**
     49     * Get the image associated with this MapImage object.
     50     *
     51     * @param disabled {@code} true to request disabled version, {@code false} for the standard version
     52     * @return the image
     53     */
     54    public BufferedImage getImage(boolean disabled) {
     55        if (disabled) {
     56            return getDisabled();
     57        } else {
     58            return getImage();
     59        }
     60    }
     61
     62    private BufferedImage getDisabled() {
    4663        if (disabledImgCache != null)
    4764                return disabledImgCache;
    4865        if (img == null)
    4966            getImage(); // fix #7498 ?
    50         disabledImgCache = GuiHelper.getDisabledImage(img);
     67        Image disImg = GuiHelper.getDisabledImage(img);
     68        if (disImg instanceof BufferedImage) {
     69            disabledImgCache = (BufferedImage) disImg;
     70        } else {
     71            disabledImgCache = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_BYTE_GRAY);
     72            Graphics g = disabledImgCache.getGraphics();
     73            g.drawImage(disImg, 0, 0, null);
     74            g.dispose();
     75        }
    5176        return disabledImgCache;
    5277    }
    5378
    54     public BufferedImage getImage() {
     79    private BufferedImage getImage() {
    5580        if (img != null)
    5681            return img;
     
    7297                                img = noIcon == null ? null : (BufferedImage) noIcon.getImage();
    7398                            } else {
    74                                 img = (BufferedImage) result.getImage();
     99                                img = (BufferedImage) rescale(result.getImage());
    75100                            }
    76101                            if (temporary) {
     
    159184
    160185    /**
    161      * Returns the really displayed node icon for this {@code MapImage}.
    162      * @param disabled {@code} true to request disabled version, {@code false} for the standard version
     186     * Rescale excessively large images.
     187     * @param image the unscaled image
    163188     * @return The scaled down version to 16x16 pixels if the image height and width exceeds 48 pixels and no size has been explicitely specified
    164      * @since 6174
    165      */
    166     public Image getDisplayedNodeIcon(boolean disabled) {
    167         final Image image = disabled ? getDisabled() : getImage();
     189     */
     190    private Image rescale(Image image) {
     191        if (image == null) return null;
    168192        // Scale down large (.svg) images to 16x16 pixels if no size is explicitely specified
    169193        if (mustRescale(image)) {
  • trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java

    r8061 r8085  
    167167                        if (mapImage != null) {
    168168                            if (includeDeprecatedIcon || mapImage.name == null || !"misc/deprecated.png".equals(mapImage.name)) {
    169                                 return new ImageIcon(mapImage.getDisplayedNodeIcon(false));
     169                                return new ImageIcon(mapImage.getImage(false));
    170170                            } else {
    171171                                return null; // Deprecated icon found but not wanted
  • trunk/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java

    r7864 r8085  
    148148        int height = heightF == null ? -1 : Math.round(heightF);
    149149
     150        float offsetXF = 0f;
     151        float offsetYF = 0f;
     152        if (keys[ICON_OFFSET_X_IDX] != null) {
     153            offsetXF = c.get(keys[ICON_OFFSET_X_IDX], 0f, Float.class);
     154            offsetYF = c.get(keys[ICON_OFFSET_Y_IDX], 0f, Float.class);
     155        }
     156
    150157        final MapImage mapImage = new MapImage(iconRef.iconName, iconRef.source);
    151158
    152159        mapImage.width = width;
    153160        mapImage.height = height;
     161        mapImage.offsetX = Math.round(offsetXF);
     162        mapImage.offsetY = Math.round(offsetYF);
    154163
    155164        mapImage.alpha = Math.min(255, Math.max(0, Integer.valueOf(Main.pref.getInteger("mappaint.icon-image-alpha", 255))));
     
    246255            Node n = (Node) primitive;
    247256            if (mapImage != null && painter.isShowIcons()) {
    248                 final Image nodeIcon;
    249                 if (painter.isInactiveMode() || n.isDisabled()) {
    250                     if (disabledNodeIcon == null || disabledNodeIconIsTemporary) {
    251                         disabledNodeIcon = mapImage.getDisplayedNodeIcon(true);
    252                         disabledNodeIconIsTemporary = mapImage.isTemporary();
    253                     }
    254                     nodeIcon = disabledNodeIcon;
    255                 } else {
    256                     if (enabledNodeIcon == null || enabledNodeIconIsTemporary) {
    257                         enabledNodeIcon = mapImage.getDisplayedNodeIcon(false);
    258                         enabledNodeIconIsTemporary = mapImage.isTemporary();
    259                     }
    260                     nodeIcon = enabledNodeIcon;
    261                 }
    262                 painter.drawNodeIcon(n, nodeIcon, Utils.color_int2float(mapImage.alpha), selected, member);
     257                painter.drawNodeIcon(n, mapImage, painter.isInactiveMode() || n.isDisabled(), selected, member);
    263258            } else if (symbol != null) {
    264259                Color fillColor = symbol.fillColor;
     
    321316            }
    322317        } else if (primitive instanceof Relation && mapImage != null) {
    323             painter.drawRestriction((Relation) primitive, mapImage);
     318            painter.drawRestriction((Relation) primitive, mapImage, painter.isInactiveMode() || primitive.isDisabled());
    324319        }
    325320    }
  • trunk/src/org/openstreetmap/josm/gui/mappaint/RepeatImageElemStyle.java

    r7937 r8085  
    5353            boolean selected, boolean outermember, boolean member) {
    5454        Way w = (Way) primitive;
    55         painter.drawRepeatImage(w, pattern.getImage(), offset, spacing, phase, align);
     55        painter.drawRepeatImage(w, pattern, painter.isInactiveMode() || w.isDisabled(), offset, spacing, phase, align);
    5656    }
    5757
  • trunk/src/org/openstreetmap/josm/gui/mappaint/StyleKeys.java

    r7937 r8085  
    3232    int ICON_HEIGHT_IDX = 2;
    3333    int ICON_OPACITY_IDX = 3;
     34    int ICON_OFFSET_X_IDX = 4;
     35    int ICON_OFFSET_Y_IDX = 5;
    3436}
Note: See TracChangeset for help on using the changeset viewer.