Changeset 5812 in josm
- Timestamp:
- 2013-03-29T14:44:47+01:00 (12 years ago)
- 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 598 598 @Deprecated 599 599 public void drawLinePattern(Way way, Image pattern) { 600 drawRepeatImage(way, pattern, 0f, 0f, LineImageAlignment.TOP);600 drawRepeatImage(way, pattern, 0f, 0f, 0f, LineImageAlignment.TOP); 601 601 } 602 602 … … 608 608 * @param offset offset from the way 609 609 * @param spacing spacing between two images 610 * @param phase initial spacing 610 611 * @param align alignment of the image. The top, center or bottom edge 611 612 * can be aligned with the way. 612 613 */ 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) { 614 615 final int imgWidth = pattern.getWidth(null); 615 616 final double repeat = imgWidth + spacing; … … 617 618 618 619 Point lastP = null; 619 double currentWayLength = 0; 620 double currentWayLength = phase % repeat; 621 if (currentWayLength < 0) { 622 currentWayLength += repeat; 623 } 620 624 621 625 int dy1, dy2; … … 647 651 final double dy = thisP.y - lastP.y; 648 652 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); 650 656 651 657 AffineTransform saveTransform = g.getTransform(); … … 656 662 // is cut off 657 663 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 } 660 674 } 661 675 // draw remaining images for this segment -
trunk/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java
r5811 r5812 118 118 } 119 119 120 public static MapImage createIcon( Environment env,String[] keys) {120 public static MapImage createIcon(final Environment env, final String[] keys) { 121 121 Cascade c = env.mc.getCascade(env.layer); 122 122 -
trunk/src/org/openstreetmap/josm/gui/mappaint/RepeatImageElemStyle.java
r5811 r5812 17 17 public float offset; 18 18 public float spacing; 19 public float phase; 19 20 public LineImageAlignment align; 20 21 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) { 22 23 super(c, 2.9f); 23 24 CheckParameterUtil.ensureParameterNotNull(pattern); … … 26 27 this.offset = offset; 27 28 this.spacing = spacing; 29 this.phase = phase; 28 30 this.align = align; 29 31 } … … 34 36 return null; 35 37 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); 38 41 39 42 LineImageAlignment align = LineImageAlignment.CENTER; … … 45 48 } 46 49 47 return new RepeatImageElemStyle(c, pattern, offset, spacing, align);50 return new RepeatImageElemStyle(c, pattern, offset, spacing, phase, align); 48 51 } 49 52 50 53 @Override 51 54 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); 54 57 } 55 58 … … 69 72 if (this.offset != other.offset) return false; 70 73 if (this.spacing != other.spacing) return false; 74 if (this.phase != other.phase) return false; 71 75 if (this.align != other.align) return false; 72 76 return true; … … 79 83 hash = 83 * hash + Float.floatToIntBits(this.offset); 80 84 hash = 83 * hash + Float.floatToIntBits(this.spacing); 85 hash = 83 * hash + Float.floatToIntBits(this.phase); 81 86 hash = 83 * hash + this.align.hashCode(); 82 87 return hash; … … 86 91 public String toString() { 87 92 return "RepeatImageStyle{" + super.toString() + "pattern=[" + pattern + 88 "], offset=" + offset + ", spacing=" + spacing + ", align=" + align + "}"; 93 "], offset=" + offset + ", spacing=" + spacing + 94 ", phase=" + (-phase) + ", align=" + align + "}"; 89 95 } 90 96 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/StyleKeys.java
r5811 r5812 25 25 String REPEAT_IMAGE_OFFSET = "repeat-image-offset"; 26 26 String REPEAT_IMAGE_SPACING = "repeat-image-spacing"; 27 String REPEAT_IMAGE_PHASE = "repeat-image-phase"; 27 28 String REPEAT_IMAGE_ALIGN = "repeat-image-align"; 28 29
Note:
See TracChangeset
for help on using the changeset viewer.