Changeset 5801 in josm for trunk/src/org/openstreetmap/josm/data
- Timestamp:
- 2013-03-24T12:58:45+01:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java
r5705 r5801 57 57 import org.openstreetmap.josm.gui.mappaint.NodeElemStyle; 58 58 import org.openstreetmap.josm.gui.mappaint.NodeElemStyle.Symbol; 59 import org.openstreetmap.josm.gui.mappaint.RepeatImageElemStyle.LineImageAlignment; 59 60 import org.openstreetmap.josm.gui.mappaint.StyleCache.StyleList; 60 61 import org.openstreetmap.josm.gui.mappaint.TextElement; … … 595 596 } 596 597 598 @Deprecated 597 599 public void drawLinePattern(Way way, Image pattern) { 598 final int width = pattern.getWidth(null); 599 final int height = pattern.getHeight(null); 600 drawRepeatImage(way, pattern, 0f, 0f, LineImageAlignment.TOP); 601 } 602 603 /** 604 * Draw an image along a way repeatedly. 605 * 606 * @param way the way 607 * @param pattern the image 608 * @param offset offset from the way 609 * @param spacing spacing between two images 610 * @param align alignment of the image. The top, center or bottom edge 611 * can be aligned with the way. 612 */ 613 public void drawRepeatImage(Way way, Image pattern, float offset, float spacing, LineImageAlignment align) { 614 final int imgWidth = pattern.getWidth(null); 615 final double repeat = imgWidth + spacing; 616 final int imgHeight = pattern.getHeight(null); 600 617 601 618 Point lastP = null; 602 double wayLength = 0; 603 604 Iterator<Node> it = way.getNodes().iterator(); 619 double currentWayLength = 0; 620 621 int dy1, dy2; 622 switch (align) { 623 case TOP: 624 dy1 = 0; 625 dy2 = imgHeight; 626 break; 627 case CENTER: 628 dy1 = - imgHeight / 2; 629 dy2 = imgHeight + dy1; 630 break; 631 case BOTTOM: 632 dy1 = -imgHeight; 633 dy2 = 0; 634 break; 635 default: 636 throw new AssertionError(); 637 } 638 639 OffsetIterator it = new OffsetIterator(way.getNodes(), offset); 605 640 while (it.hasNext()) { 606 Node n = it.next(); 607 Point thisP = nc.getPoint(n); 641 Point thisP = it.next(); 608 642 609 643 if (lastP != null) { … … 613 647 final double dy = thisP.y - lastP.y; 614 648 615 double dist = wayLength == 0 ? 0 : width - (wayLength % width);649 double pos = currentWayLength == 0 ? 0 : repeat - (currentWayLength % repeat); 616 650 617 651 AffineTransform saveTransform = g.getTransform(); … … 619 653 g.rotate(Math.atan2(dy, dx)); 620 654 621 if (dist > 0) { 622 g.drawImage(pattern, 0, 0, (int) dist, height, 623 width - (int) dist, 0, width, height, null); 624 } 625 while (dist < segmentLength) { 626 if (dist + width > segmentLength) { 627 g.drawImage(pattern, (int) dist, 0, (int) segmentLength, height, 628 0, 0, (int) segmentLength - (int) dist, height, null); 655 // draw the rest of the image from the last segment in case it 656 // is cut off 657 if (pos > spacing) { 658 g.drawImage(pattern, 0, dy1, (int) (pos - spacing), dy2, 659 (int) (imgWidth + spacing - pos), 0, imgWidth, imgHeight, null); 660 } 661 // draw remaining images for this segment 662 while (pos < segmentLength) { 663 // cut off at the end? 664 if (pos + imgWidth > segmentLength) { 665 g.drawImage(pattern, (int) pos, dy1, (int) segmentLength, dy2, 666 0, 0, (int) segmentLength - (int) pos, imgHeight, null); 629 667 } else { 630 g.drawImage(pattern, (int) dist, 0, nc);668 g.drawImage(pattern, (int) pos, dy1, nc); 631 669 } 632 dist += width;670 pos += repeat; 633 671 } 634 672 g.setTransform(saveTransform); 635 673 636 wayLength += segmentLength;674 currentWayLength += segmentLength; 637 675 } 638 676 lastP = thisP; 639 677 } 640 678 } 641 679 642 680 @Override 643 681 public void drawNode(Node n, Color color, int size, boolean fill) {
Note:
See TracChangeset
for help on using the changeset viewer.