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


Ignore:
Timestamp:
2015-11-14T22:06:03+01:00 (9 years ago)
Author:
bastiK
Message:

see #12104 - mapcss: add option for partial filling of areas (inspired by iD)

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

Legend:

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

    r9002 r9005  
    451451    }
    452452
    453     protected void drawArea(OsmPrimitive osm, Path2D.Double path, Color color, MapImage fillImage, boolean disabled, TextElement text) {
     453    protected void drawArea(OsmPrimitive osm, Path2D.Double path, Color color, MapImage fillImage, Float extent, boolean disabled, TextElement text) {
    454454
    455455        Shape area = path.createTransformedShape(nc.getAffineTransform());
     
    462462                }
    463463                g.setColor(color);
    464                 g.fill(area);
     464                if (extent == null) {
     465                    g.fill(area);
     466                } else {
     467                    Shape clip = g.getClip();
     468                    g.clip(area);
     469                    g.setStroke(new BasicStroke(2 * extent));
     470                    g.draw(area);
     471                    g.setClip(clip);
     472                }
    465473            } else {
    466474                TexturePaint texture = new TexturePaint(fillImage.getImage(disabled),
     
    559567     * @param color The color to fill the area with.
    560568     * @param fillImage The image to fill the area with. Overrides color.
     569     * @param extent if not null, area will be filled partially; specifies, how
     570     * far to fill from the boundary towards the center of the area;
     571     * if null, area will be filled completely
    561572     * @param disabled If this should be drawn with a special disabled style.
    562573     * @param text The text to write on the area.
    563574     */
    564     public void drawArea(Relation r, Color color, MapImage fillImage, boolean disabled, TextElement text) {
     575    public void drawArea(Relation r, Color color, MapImage fillImage, Float extent, boolean disabled, TextElement text) {
    565576        Multipolygon multipolygon = MultipolygonCache.getInstance().get(nc, r);
    566577        if (!r.isDisabled() && !multipolygon.getOuterWays().isEmpty()) {
     
    572583                drawArea(r, p,
    573584                        pd.selected ? paintSettings.getRelationSelectedColor(color.getAlpha()) : color,
    574                                 fillImage, disabled, text);
     585                        fillImage, extent, disabled, text);
    575586            }
    576587        }
     
    582593     * @param color The color to fill the area with.
    583594     * @param fillImage The image to fill the area with. Overrides color.
     595     * @param extent if not null, area will be filled partially; specifies, how
     596     * far to fill from the boundary towards the center of the area;
     597     * if null, area will be filled completely
    584598     * @param disabled If this should be drawn with a special disabled style.
    585599     * @param text The text to write on the area.
    586600     */
    587     public void drawArea(Way w, Color color, MapImage fillImage, boolean disabled, TextElement text) {
    588         drawArea(w, getPath(w), color, fillImage, disabled, text);
     601    public void drawArea(Way w, Color color, MapImage fillImage, Float extent, boolean disabled, TextElement text) {
     602        drawArea(w, getPath(w), color, fillImage, extent, disabled, text);
    589603    }
    590604
  • trunk/src/org/openstreetmap/josm/gui/mappaint/AreaElemStyle.java

    r8289 r9005  
    2525    public MapImage fillImage;
    2626    public TextElement text;
     27    public Float extent;
    2728
    28     protected AreaElemStyle(Cascade c, Color color, MapImage fillImage, TextElement text) {
     29    protected AreaElemStyle(Cascade c, Color color, MapImage fillImage, Float extent, TextElement text) {
    2930        super(c, 1f);
    3031        CheckParameterUtil.ensureParameterNotNull(color);
    3132        this.color = color;
     33        this.extent = extent;
    3234        this.fillImage = fillImage;
    3335        this.text = text;
     
    3840        MapImage fillImage = null;
    3941        Color color = null;
     42        Float extent = null;
    4043
    4144        IconReference iconRef = c.get(FILL_IMAGE, null, IconReference.class);
     
    6972                }
    7073                color = new Color(color.getRed(), color.getGreen(), color.getBlue(), alpha);
     74                extent = c.get(FILL_EXTENT, null, float.class);
    7175            }
    7276        }
     
    7983
    8084        if (color != null)
    81             return new AreaElemStyle(c, color, fillImage, text);
     85            return new AreaElemStyle(c, color, fillImage, extent, text);
    8286        else
    8387            return null;
     
    96100                }
    97101            }
    98             painter.drawArea((Way) osm, myColor, fillImage, painter.isInactiveMode() || osm.isDisabled(), text);
     102            painter.drawArea((Way) osm, myColor, fillImage, extent, painter.isInactiveMode() || osm.isDisabled(), text);
    99103        } else if (osm instanceof Relation) {
    100104            if (color != null && (selected || outermember)) {
    101105                myColor = paintSettings.getRelationSelectedColor(color.getAlpha());
    102106            }
    103             painter.drawArea((Relation) osm, myColor, fillImage, painter.isInactiveMode() || osm.isDisabled(), text);
     107            painter.drawArea((Relation) osm, myColor, fillImage, extent, painter.isInactiveMode() || osm.isDisabled(), text);
    104108        }
    105109    }
     
    117121        if (!Objects.equals(color, other.color))
    118122            return false;
     123        if (extent != other.extent)
     124            return false;
    119125        if (!Objects.equals(text, other.text))
    120126            return false;
     
    126132        int hash = 3;
    127133        hash = 61 * hash + color.hashCode();
     134        hash = 61 * hash + (extent != null ? Float.floatToIntBits(extent) : 0);
    128135        hash = 61 * hash + (fillImage != null ? fillImage.hashCode() : 0);
    129136        hash = 61 * hash + (text != null ? text.hashCode() : 0);
  • trunk/src/org/openstreetmap/josm/gui/mappaint/StyleKeys.java

    r8260 r9005  
    1010    String DASHES_OFFSET = "dashes-offset";
    1111    String FILL_COLOR = "fill-color";
     12    String FILL_EXTENT = "fill-extent";
    1213    String FILL_IMAGE = "fill-image";
    1314    String FILL_OPACITY = "fill-opacity";
Note: See TracChangeset for help on using the changeset viewer.