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


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

mapcss: add phase for repeat-image

Location:
trunk/src/org/openstreetmap/josm
Files:
4 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
  • trunk/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java

    r5811 r5812  
    118118    }
    119119
    120     public static MapImage createIcon(Environment env, String[] keys) {
     120    public static MapImage createIcon(final Environment env, final String[] keys) {
    121121        Cascade c = env.mc.getCascade(env.layer);
    122122
  • trunk/src/org/openstreetmap/josm/gui/mappaint/RepeatImageElemStyle.java

    r5811 r5812  
    1717    public float offset;
    1818    public float spacing;
     19    public float phase;
    1920    public LineImageAlignment align;
    2021
    21     public RepeatImageElemStyle(Cascade c, MapImage pattern, float offset, float spacing, LineImageAlignment align) {
     22    public RepeatImageElemStyle(Cascade c, MapImage pattern, float offset, float spacing, float phase, LineImageAlignment align) {
    2223        super(c, 2.9f);
    2324        CheckParameterUtil.ensureParameterNotNull(pattern);
     
    2627        this.offset = offset;
    2728        this.spacing = spacing;
     29        this.phase = phase;
    2830        this.align = align;
    2931    }
     
    3436            return null;
    3537        Cascade c = env.mc.getCascade(env.layer);
    36         Float offset = c.get(REPEAT_IMAGE_OFFSET, 0f, Float.class);
    37         Float spacing = c.get(REPEAT_IMAGE_SPACING, 0f, Float.class);
     38        float offset = c.get(REPEAT_IMAGE_OFFSET, 0f, Float.class);
     39        float spacing = c.get(REPEAT_IMAGE_SPACING, 0f, Float.class);
     40        float phase = - c.get(REPEAT_IMAGE_PHASE, 0f, Float.class);
    3841
    3942        LineImageAlignment align = LineImageAlignment.CENTER;
     
    4548        }
    4649
    47         return new RepeatImageElemStyle(c, pattern, offset, spacing, align);
     50        return new RepeatImageElemStyle(c, pattern, offset, spacing, phase, align);
    4851    }
    4952
    5053    @Override
    5154    public void paintPrimitive(OsmPrimitive primitive, MapPaintSettings paintSettings, StyledMapRenderer painter, boolean selected, boolean member) {
    52         Way w = (Way)primitive;
    53         painter.drawRepeatImage(w, pattern.getImage(), offset, spacing, align);
     55        Way w = (Way) primitive;
     56        painter.drawRepeatImage(w, pattern.getImage(), offset, spacing, phase, align);
    5457    }
    5558
     
    6972        if (this.offset != other.offset) return false;
    7073        if (this.spacing != other.spacing) return false;
     74        if (this.phase != other.phase) return false;
    7175        if (this.align != other.align) return false;
    7276        return true;
     
    7983        hash = 83 * hash + Float.floatToIntBits(this.offset);
    8084        hash = 83 * hash + Float.floatToIntBits(this.spacing);
     85        hash = 83 * hash + Float.floatToIntBits(this.phase);
    8186        hash = 83 * hash + this.align.hashCode();
    8287        return hash;
     
    8691    public String toString() {
    8792        return "RepeatImageStyle{" + super.toString() + "pattern=[" + pattern +
    88                 "], offset=" + offset + ", spacing=" + spacing + ", align=" + align + "}";
     93                "], offset=" + offset + ", spacing=" + spacing +
     94                ", phase=" + (-phase) + ", align=" + align + "}";
    8995    }
    9096}
  • trunk/src/org/openstreetmap/josm/gui/mappaint/StyleKeys.java

    r5811 r5812  
    2525    String REPEAT_IMAGE_OFFSET = "repeat-image-offset";
    2626    String REPEAT_IMAGE_SPACING = "repeat-image-spacing";
     27    String REPEAT_IMAGE_PHASE = "repeat-image-phase";
    2728    String REPEAT_IMAGE_ALIGN = "repeat-image-align";
    2829
Note: See TracChangeset for help on using the changeset viewer.