Changeset 8085 in josm
- Timestamp:
- 2015-02-18T23:43:28+01:00 (10 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java
r7801 r8085 428 428 } 429 429 430 protected void drawArea(OsmPrimitive osm, Path2D.Double path, Color color, MapImage fillImage, TextElement text) {430 protected void drawArea(OsmPrimitive osm, Path2D.Double path, Color color, MapImage fillImage, boolean disabled, TextElement text) { 431 431 432 432 Shape area = path.createTransformedShape(nc.getAffineTransform()); … … 440 440 g.fill(area); 441 441 } else { 442 TexturePaint texture = new TexturePaint(fillImage.getImage( ),442 TexturePaint texture = new TexturePaint(fillImage.getImage(disabled), 443 443 new Rectangle(0, 0, fillImage.getWidth(), fillImage.getHeight())); 444 444 g.setPaint(texture); 445 Float alpha = Utils.color_int2float(fillImage.alpha);445 Float alpha = fillImage.getAlphaFloat(); 446 446 if (alpha != 1f) { 447 447 g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha)); … … 529 529 } 530 530 531 public void drawArea(Relation r, Color color, MapImage fillImage, TextElement text) {531 public void drawArea(Relation r, Color color, MapImage fillImage, boolean disabled, TextElement text) { 532 532 Multipolygon multipolygon = MultipolygonCache.getInstance().get(nc, r); 533 533 if (!r.isDisabled() && !multipolygon.getOuterWays().isEmpty()) { … … 539 539 drawArea(r, p, 540 540 pd.selected ? paintSettings.getRelationSelectedColor(color.getAlpha()) : color, 541 fillImage, text);542 } 543 } 544 } 545 546 public void drawArea(Way w, Color color, MapImage fillImage, TextElement text) {547 drawArea(w, getPath(w), color, fillImage, text);541 fillImage, disabled, text); 542 } 543 } 544 } 545 546 public void drawArea(Way w, Color color, MapImage fillImage, boolean disabled, TextElement text) { 547 drawArea(w, getPath(w), color, fillImage, disabled, text); 548 548 } 549 549 … … 617 617 * can be aligned with the way. 618 618 */ 619 public void drawRepeatImage(Way way, Image pattern, float offset, float spacing, float phase, LineImageAlignment align) {620 final int imgWidth = pattern.getWidth( null);619 public void drawRepeatImage(Way way, MapImage pattern, boolean disabled, float offset, float spacing, float phase, LineImageAlignment align) { 620 final int imgWidth = pattern.getWidth(); 621 621 final double repeat = imgWidth + spacing; 622 final int imgHeight = pattern.getHeight( null);622 final int imgHeight = pattern.getHeight(); 623 623 624 624 Point lastP = null; … … 669 669 // segment is too short for a complete image 670 670 if (pos > segmentLength + spacing) { 671 g.drawImage(pattern , 0, dy1, (int) segmentLength, dy2,671 g.drawImage(pattern.getImage(disabled), 0, dy1, (int) segmentLength, dy2, 672 672 (int) (repeat - pos), 0, 673 673 (int) (repeat - pos + segmentLength), imgHeight, null); 674 674 // rest of the image fits fully on the current segment 675 675 } else { 676 g.drawImage(pattern , 0, dy1, (int) (pos - spacing), dy2,676 g.drawImage(pattern.getImage(disabled), 0, dy1, (int) (pos - spacing), dy2, 677 677 (int) (repeat - pos), 0, imgWidth, imgHeight, null); 678 678 } … … 682 682 // cut off at the end? 683 683 if (pos + imgWidth > segmentLength) { 684 g.drawImage(pattern , (int) pos, dy1, (int) segmentLength, dy2,684 g.drawImage(pattern.getImage(disabled), (int) pos, dy1, (int) segmentLength, dy2, 685 685 0, 0, (int) segmentLength - (int) pos, imgHeight, null); 686 686 } else { 687 g.drawImage(pattern , (int) pos, dy1, nc);687 g.drawImage(pattern.getImage(disabled), (int) pos, dy1, nc); 688 688 } 689 689 pos += repeat; … … 725 725 } 726 726 727 public void drawNodeIcon(Node n, Image img, float alpha, boolean selected, boolean member) {727 public void drawNodeIcon(Node n, MapImage img, boolean disabled, boolean selected, boolean member) { 728 728 Point p = nc.getPoint(n); 729 729 730 final int w = img.getWidth( null), h=img.getHeight(null);730 final int w = img.getWidth(), h = img.getHeight(); 731 731 if(n.isHighlighted()) { 732 732 drawPointHighlight(p, Math.max(w, h)); 733 733 } 734 734 735 float alpha = img.getAlphaFloat(); 736 735 737 if (alpha != 1f) { 736 738 g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha)); 737 739 } 738 g.drawImage(img , p.x-w/2, p.y-h/2, nc);740 g.drawImage(img.getImage(disabled), p.x - w/2 + img.offsetX, p.y - h/2 + img.offsetY, nc); 739 741 g.setPaintMode(); 740 742 if (selected || member) 741 743 { 742 744 Color color; 743 if ( isInactiveMode || n.isDisabled()) {745 if (disabled) { 744 746 color = inactiveColor; 745 747 } else if (selected) { … … 749 751 } 750 752 g.setColor(color); 751 g.drawRect(p.x -w/2-2, p.y-h/2-2, w+4, h+4);753 g.drawRect(p.x - w/2 + img.offsetX - 2, p.y - h/2 + img.offsetY - 2, w + 4, h + 4); 752 754 } 753 755 } … … 888 890 } 889 891 890 public void drawRestriction(Relation r, MapImage icon ) {892 public void drawRestriction(Relation r, MapImage icon, boolean disabled) { 891 893 Way fromWay = null; 892 894 Way toWay = null; … … 1057 1059 } 1058 1060 1059 drawRestriction(i sInactiveMode || r.isDisabled() ? icon.getDisabled() : icon.getImage(),1061 drawRestriction(icon.getImage(disabled), 1060 1062 pVia, vx, vx2, vy, vy2, iconAngle, r.isSelected()); 1061 1063 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/AreaElemStyle.java
r7621 r8085 42 42 if (iconRef != null) { 43 43 fillImage = new MapImage(iconRef.iconName, iconRef.source); 44 fillImage.getImage();45 44 46 color = new Color(fillImage.getImage( ).getRGB(45 color = new Color(fillImage.getImage(false).getRGB( 47 46 fillImage.getWidth() / 2, fillImage.getHeight() / 2) 48 47 ); … … 97 96 } 98 97 } 99 painter.drawArea((Way) osm, myColor, fillImage, text);98 painter.drawArea((Way) osm, myColor, fillImage, painter.isInactiveMode() || osm.isDisabled(), text); 100 99 } else if (osm instanceof Relation) { 101 100 if (color != null && (selected || outermember)) { 102 101 myColor = paintSettings.getRelationSelectedColor(color.getAlpha()); 103 102 } 104 painter.drawArea((Relation) osm, myColor, fillImage, text);103 painter.drawArea((Relation) osm, myColor, fillImage, painter.isInactiveMode() || osm.isDisabled(), text); 105 104 } 106 105 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyle.java
r7621 r8085 14 14 public abstract class ElemStyle implements StyleKeys { 15 15 16 protected static final String[] ICON_KEYS = {"icon-image", "icon-width", "icon-height", "icon-opacity" };17 protected static final String[] REPEAT_IMAGE_KEYS = {"repeat-image", "repeat-image-width", "repeat-image-height", "repeat-image-opacity" };16 protected static final String[] ICON_KEYS = {"icon-image", "icon-width", "icon-height", "icon-opacity", "icon-offset-x", "icon-offset-y"}; 17 protected static final String[] REPEAT_IMAGE_KEYS = {"repeat-image", "repeat-image-width", "repeat-image-height", "repeat-image-opacity", null, null}; 18 18 19 19 public float major_z_index; -
trunk/src/org/openstreetmap/josm/gui/mappaint/MapImage.java
r7083 r8085 2 2 package org.openstreetmap.josm.gui.mappaint; 3 3 4 import java.awt.Graphics; 4 5 import java.awt.Image; 5 6 import java.awt.Rectangle; … … 17 18 import org.openstreetmap.josm.tools.Utils; 18 19 20 /** 21 * An image that will be displayed on the map. 22 */ 19 23 public class MapImage { 20 24 … … 26 30 private BufferedImage img; 27 31 28 /**29 * The 5 following fields are only used to check for equality.30 */31 32 public int alpha = 255; 32 33 public String name; … … 34 35 public int width = -1; 35 36 public int height = -1; 37 public int offsetX = 0; 38 public int offsetY = 0; 36 39 37 40 private boolean temporary; 38 private Image disabledImgCache;41 private BufferedImage disabledImgCache; 39 42 40 43 public MapImage(String name, StyleSource source) { … … 43 46 } 44 47 45 public Image getDisabled() { 48 /** 49 * Get the image associated with this MapImage object. 50 * 51 * @param disabled {@code} true to request disabled version, {@code false} for the standard version 52 * @return the image 53 */ 54 public BufferedImage getImage(boolean disabled) { 55 if (disabled) { 56 return getDisabled(); 57 } else { 58 return getImage(); 59 } 60 } 61 62 private BufferedImage getDisabled() { 46 63 if (disabledImgCache != null) 47 64 return disabledImgCache; 48 65 if (img == null) 49 66 getImage(); // fix #7498 ? 50 disabledImgCache = GuiHelper.getDisabledImage(img); 67 Image disImg = GuiHelper.getDisabledImage(img); 68 if (disImg instanceof BufferedImage) { 69 disabledImgCache = (BufferedImage) disImg; 70 } else { 71 disabledImgCache = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_BYTE_GRAY); 72 Graphics g = disabledImgCache.getGraphics(); 73 g.drawImage(disImg, 0, 0, null); 74 g.dispose(); 75 } 51 76 return disabledImgCache; 52 77 } 53 78 54 p ublicBufferedImage getImage() {79 private BufferedImage getImage() { 55 80 if (img != null) 56 81 return img; … … 72 97 img = noIcon == null ? null : (BufferedImage) noIcon.getImage(); 73 98 } else { 74 img = (BufferedImage) res ult.getImage();99 img = (BufferedImage) rescale(result.getImage()); 75 100 } 76 101 if (temporary) { … … 159 184 160 185 /** 161 * Re turns the really displayed node icon for this {@code MapImage}.162 * @param disabled {@code} true to request disabled version, {@code false} for the standard version186 * Rescale excessively large images. 187 * @param image the unscaled image 163 188 * @return The scaled down version to 16x16 pixels if the image height and width exceeds 48 pixels and no size has been explicitely specified 164 * @since 6174 165 */ 166 public Image getDisplayedNodeIcon(boolean disabled) { 167 final Image image = disabled ? getDisabled() : getImage(); 189 */ 190 private Image rescale(Image image) { 191 if (image == null) return null; 168 192 // Scale down large (.svg) images to 16x16 pixels if no size is explicitely specified 169 193 if (mustRescale(image)) { -
trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java
r8061 r8085 167 167 if (mapImage != null) { 168 168 if (includeDeprecatedIcon || mapImage.name == null || !"misc/deprecated.png".equals(mapImage.name)) { 169 return new ImageIcon(mapImage.get DisplayedNodeIcon(false));169 return new ImageIcon(mapImage.getImage(false)); 170 170 } else { 171 171 return null; // Deprecated icon found but not wanted -
trunk/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java
r7864 r8085 148 148 int height = heightF == null ? -1 : Math.round(heightF); 149 149 150 float offsetXF = 0f; 151 float offsetYF = 0f; 152 if (keys[ICON_OFFSET_X_IDX] != null) { 153 offsetXF = c.get(keys[ICON_OFFSET_X_IDX], 0f, Float.class); 154 offsetYF = c.get(keys[ICON_OFFSET_Y_IDX], 0f, Float.class); 155 } 156 150 157 final MapImage mapImage = new MapImage(iconRef.iconName, iconRef.source); 151 158 152 159 mapImage.width = width; 153 160 mapImage.height = height; 161 mapImage.offsetX = Math.round(offsetXF); 162 mapImage.offsetY = Math.round(offsetYF); 154 163 155 164 mapImage.alpha = Math.min(255, Math.max(0, Integer.valueOf(Main.pref.getInteger("mappaint.icon-image-alpha", 255)))); … … 246 255 Node n = (Node) primitive; 247 256 if (mapImage != null && painter.isShowIcons()) { 248 final Image nodeIcon; 249 if (painter.isInactiveMode() || n.isDisabled()) { 250 if (disabledNodeIcon == null || disabledNodeIconIsTemporary) { 251 disabledNodeIcon = mapImage.getDisplayedNodeIcon(true); 252 disabledNodeIconIsTemporary = mapImage.isTemporary(); 253 } 254 nodeIcon = disabledNodeIcon; 255 } else { 256 if (enabledNodeIcon == null || enabledNodeIconIsTemporary) { 257 enabledNodeIcon = mapImage.getDisplayedNodeIcon(false); 258 enabledNodeIconIsTemporary = mapImage.isTemporary(); 259 } 260 nodeIcon = enabledNodeIcon; 261 } 262 painter.drawNodeIcon(n, nodeIcon, Utils.color_int2float(mapImage.alpha), selected, member); 257 painter.drawNodeIcon(n, mapImage, painter.isInactiveMode() || n.isDisabled(), selected, member); 263 258 } else if (symbol != null) { 264 259 Color fillColor = symbol.fillColor; … … 321 316 } 322 317 } else if (primitive instanceof Relation && mapImage != null) { 323 painter.drawRestriction((Relation) primitive, mapImage );318 painter.drawRestriction((Relation) primitive, mapImage, painter.isInactiveMode() || primitive.isDisabled()); 324 319 } 325 320 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/RepeatImageElemStyle.java
r7937 r8085 53 53 boolean selected, boolean outermember, boolean member) { 54 54 Way w = (Way) primitive; 55 painter.drawRepeatImage(w, pattern .getImage(), offset, spacing, phase, align);55 painter.drawRepeatImage(w, pattern, painter.isInactiveMode() || w.isDisabled(), offset, spacing, phase, align); 56 56 } 57 57 -
trunk/src/org/openstreetmap/josm/gui/mappaint/StyleKeys.java
r7937 r8085 32 32 int ICON_HEIGHT_IDX = 2; 33 33 int ICON_OPACITY_IDX = 3; 34 int ICON_OFFSET_X_IDX = 4; 35 int ICON_OFFSET_Y_IDX = 5; 34 36 }
Note:
See TracChangeset
for help on using the changeset viewer.