Ignore:
Timestamp:
2013-03-29T14:44:47+01:00 (11 years ago)
Author:
bastiK
Message:

mapcss: add phase for repeat-image

File:
1 edited

Legend:

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

    r5801 r5812  
    598598    @Deprecated
    599599    public void drawLinePattern(Way way, Image pattern) {
    600         drawRepeatImage(way, pattern, 0f, 0f, LineImageAlignment.TOP);
     600        drawRepeatImage(way, pattern, 0f, 0f, 0f, LineImageAlignment.TOP);
    601601    }
    602602
     
    608608     * @param offset offset from the way
    609609     * @param spacing spacing between two images
     610     * @param phase initial spacing
    610611     * @param align alignment of the image. The top, center or bottom edge
    611612     * can be aligned with the way.
    612613     */
    613     public void drawRepeatImage(Way way, Image pattern, float offset, float spacing, LineImageAlignment align) {
     614    public void drawRepeatImage(Way way, Image pattern, float offset, float spacing, float phase, LineImageAlignment align) {
    614615        final int imgWidth = pattern.getWidth(null);
    615616        final double repeat = imgWidth + spacing;
     
    617618
    618619        Point lastP = null;
    619         double currentWayLength = 0;
     620        double currentWayLength = phase % repeat;
     621        if (currentWayLength < 0) {
     622            currentWayLength += repeat;
     623        }
    620624
    621625        int dy1, dy2;
     
    647651                final double dy = thisP.y - lastP.y;
    648652
    649                 double pos = currentWayLength == 0 ? 0 : repeat - (currentWayLength % repeat);
     653                // pos is the position from the beginning of the current segment
     654                // where an image should be painted
     655                double pos = repeat - (currentWayLength % repeat);
    650656
    651657                AffineTransform saveTransform = g.getTransform();
     
    656662                // is cut off
    657663                if (pos > spacing) {
    658                     g.drawImage(pattern, 0, dy1, (int) (pos - spacing), dy2,
    659                             (int) (imgWidth + spacing - pos), 0, imgWidth, imgHeight, null);
     664                    // segment is too short for a complete image
     665                    if (pos > segmentLength + spacing) {
     666                        g.drawImage(pattern, 0, dy1, (int) segmentLength, dy2,
     667                                (int) (repeat - pos), 0,
     668                                (int) (repeat - pos + segmentLength), imgHeight, null);
     669                    // rest of the image fits fully on the current segment
     670                    } else {
     671                        g.drawImage(pattern, 0, dy1, (int) (pos - spacing), dy2,
     672                                (int) (repeat - pos), 0, imgWidth, imgHeight, null);
     673                    }
    660674                }
    661675                // draw remaining images for this segment
Note: See TracChangeset for help on using the changeset viewer.