Changeset 9061 in josm


Ignore:
Timestamp:
2015-11-24T20:49:07+01:00 (9 years ago)
Author:
bastiK
Message:

mappaint partial fill: render unclosed areas differently (margin on both sites) (see #12104)

Location:
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint
Files:
3 edited

Legend:

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

    r8968 r9061  
    4949    /** Preference: should only the data area outline be drawn */
    5050    private boolean outlineOnly;
     51    /** Preference: if unclosed areas should be drawn differently for partial fill */
     52    private boolean unclosedAreaHighlight;
     53    /** Preference: width of unclosed area highlight */
     54    private double unclosedAreaHighlightWidth;
    5155    /** Color Preference for selected objects */
    5256    private Color selectedColor;
     
    106110
    107111        outlineOnly = Main.pref.getBoolean("draw.data.area_outline_only", false);
     112        unclosedAreaHighlight = Main.pref.getBoolean("draw.unclosed_area_partial_fill_highlight", true);
     113        unclosedAreaHighlightWidth = Main.pref.getDouble("draw.unclosed_area_partial_fill_highlight.width", 80);
    108114    }
    109115
     
    346352        return outlineOnly;
    347353    }
     354
     355    /**
     356     * Determines if unclosed areas should be drawn differently for partial fill.
     357     *
     358     * @return {@code true} if unclosed areas should be drawn differently for partial fill
     359     */
     360    public boolean isUnclosedAreaHighlight() {
     361        return unclosedAreaHighlight;
     362    }
     363
     364    /**
     365     * Returns the width of unclosed area highlight
     366     * @return the width of unclosed area highlight
     367     */
     368    public double getUnclosedAreaHighlightWidth() {
     369        return unclosedAreaHighlightWidth;
     370    }
    348371}
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java

    r9059 r9061  
    333333    private boolean showIcons;
    334334    private boolean isOutlineOnly;
     335    private boolean isUnclosedAreaHighlight;
     336    private double unclosedAreaHighlightWidth;
    335337
    336338    private Font orderFont;
     
    451453    }
    452454
    453     protected void drawArea(OsmPrimitive osm, Path2D.Double path, Color color, MapImage fillImage, Float extent,
     455    /**
     456     * Worker function for drawing areas.
     457     *
     458     * @param osm the primitive
     459     * @param path the path object for the area that should be drawn; in case
     460     * of multipolygons, this can path can be a complex shape with one outer
     461     * polygon and one or more inner polygons
     462     * @param color The color to fill the area with.
     463     * @param fillImage The image to fill the area with. Overrides color.
     464     * @param extent if not null, area will be filled partially; specifies, how
     465     * far to fill from the boundary towards the center of the area;
     466     * if null, area will be filled completely
     467     * @param unClosedHighlight true, if the fact that the way / multipolygon is not
     468     * properly closed should be highlighted; this parameter is only used
     469     * for partial fill ({@code extent != null}), otherwise it is ignored
     470     * @param disabled If this should be drawn with a special disabled style.
     471     * @param text The text to write on the area.
     472     */
     473    protected void drawArea(OsmPrimitive osm, Path2D.Double path, Color color, MapImage fillImage, Float extent, boolean unClosedHighlight,
    454474            boolean disabled, TextElement text) {
    455475
     
    466486                    g.fill(area);
    467487                } else {
    468                     Shape clip = g.getClip();
    469                     g.clip(area);
    470                     g.setStroke(new BasicStroke(2 * extent, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER));
    471                     g.draw(area);
    472                     g.setClip(clip);
     488                    if (unClosedHighlight) {
     489                        g.setStroke(new BasicStroke((int)(unclosedAreaHighlightWidth / 100 * extent),
     490                                BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER));
     491                        g.draw(area);
     492                    } else {
     493                        Shape clip = g.getClip();
     494                        g.clip(area);
     495                        g.setStroke(new BasicStroke(2 * extent, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER));
     496                        g.draw(area);
     497                        g.setClip(clip);
     498                    }
    473499                }
    474500            } else {
     
    483509                    g.fill(area);
    484510                } else {
    485                     Shape clip = g.getClip();
    486                     BasicStroke stroke = new BasicStroke(2 * extent, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER);
    487                     g.clip(stroke.createStrokedShape(area));
    488                     g.fill(area);
    489                     g.setClip(clip);
     511                    if (unClosedHighlight) {
     512                        g.setStroke(new BasicStroke((int)(unclosedAreaHighlightWidth / 100 * extent),
     513                                BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER));
     514                        g.draw(area);
     515                    } else {
     516                        Shape clip = g.getClip();
     517                        BasicStroke stroke = new BasicStroke(2 * extent, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER);
     518                        g.clip(stroke.createStrokedShape(area));
     519                        g.fill(area);
     520                        g.setClip(clip);
     521                    }
    490522                }
    491523                g.setPaintMode();
     
    592624                drawArea(r, p,
    593625                        pd.selected ? paintSettings.getRelationSelectedColor(color.getAlpha()) : color,
    594                         fillImage, extent, disabled, text);
     626                        fillImage, extent,
     627                        isUnclosedAreaHighlight && extent != null && !pd.isClosed(),
     628                        disabled, text);
    595629            }
    596630        }
     
    609643     */
    610644    public void drawArea(Way w, Color color, MapImage fillImage, Float extent, boolean disabled, TextElement text) {
    611         drawArea(w, getPath(w), color, fillImage, extent, disabled, text);
     645        drawArea(w, getPath(w), color, fillImage, extent, isUnclosedAreaHighlight && !w.isClosed(), disabled, text);
    612646    }
    613647
     
    14641498        showIcons = paintSettings.getShowIconsDistance() > circum;
    14651499        isOutlineOnly = paintSettings.isOutlineOnly();
     1500        isUnclosedAreaHighlight = paintSettings.isUnclosedAreaHighlight();
     1501        unclosedAreaHighlightWidth = paintSettings.getUnclosedAreaHighlightWidth();
    14661502        orderFont = new Font(Main.pref.get("mappaint.font", "Droid Sans"), Font.PLAIN, Main.pref.getInteger("mappaint.fontsize", 8));
    14671503
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/relations/Multipolygon.java

    r9059 r9061  
    360360                resetNodes(event.getDataset());
    361361            }
     362        }
     363
     364        public boolean isClosed() {
     365            if (nodes.size() < 3 || nodes.get(0) != nodes.get(nodes.size() - 1)) return false;
     366            for (PolyData inner : inners) {
     367                if (!inner.isClosed()) return false;
     368            }
     369            return true;
    362370        }
    363371    }
Note: See TracChangeset for help on using the changeset viewer.