Changeset 11670 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2017-03-04T22:29:24+01:00 (8 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java
r11553 r11670 39 39 import java.util.concurrent.ForkJoinTask; 40 40 import java.util.concurrent.RecursiveTask; 41 import java.util.function.BiConsumer; 41 42 import java.util.function.Supplier; 42 43 import java.util.stream.Collectors; … … 932 933 } 933 934 935 drawIcon(p, img, disabled, selected, member, theta, (g, r) -> { 936 Color color = getSelectionHintColor(disabled, selected); 937 g.setColor(color); 938 g.draw(r); 939 }); 940 } 941 942 943 /** 944 * Draw the icon for a given area. The icon is drawn around the lat/lon center of the area. 945 * @param primitive The node 946 * @param img The icon to draw at the node position 947 * @param disabled {@code} true to render disabled version, {@code false} for the standard version 948 * @param selected {@code} true to render it as selected, {@code false} otherwise 949 * @param member {@code} true to render it as a relation member, {@code false} otherwise 950 * @param theta the angle of rotation in radians 951 */ 952 public void drawAreaIcon(OsmPrimitive primitive, MapImage img, boolean disabled, boolean selected, boolean member, double theta) { 953 BBox bbox = null; 954 if (primitive instanceof Way) { 955 bbox = primitive.getBBox(); 956 } else if (primitive instanceof Relation) { 957 Multipolygon multipolygon = MultipolygonCache.getInstance().get(nc, (Relation) primitive); 958 if (multipolygon != null) { 959 BBox collect = new BBox(); 960 multipolygon.getOuterPolygons().forEach(p -> p.getNodes().forEach(n -> collect.add(n.getCoor()))); 961 bbox = collect; 962 } 963 } 964 965 if (bbox != null && bbox.isValid()) { 966 MapViewPoint p = mapState.getPointFor(bbox.getCenter()); 967 drawIcon(p, img, disabled, selected, member, theta, (g, r) -> { 968 // only draw a minor highlighting, so that users do not confuse this for a point. 969 Color color = getSelectionHintColor(disabled, selected); 970 g.setColor(color); 971 g.draw(r); 972 }); 973 } 974 } 975 976 private void drawIcon(MapViewPoint p, MapImage img, boolean disabled, boolean selected, boolean member, double theta, 977 BiConsumer<Graphics2D, Rectangle2D> selectionDrawer) { 934 978 float alpha = img.getAlphaFloat(); 935 979 … … 943 987 temporaryGraphics.translate(x, y); 944 988 temporaryGraphics.rotate(theta); 945 int drawX = - w/2 + img.offsetX;946 int drawY = - h/2 + img.offsetY;989 int drawX = -img.getWidth() / 2 + img.offsetX; 990 int drawY = -img.getHeight() / 2 + img.offsetY; 947 991 temporaryGraphics.drawImage(img.getImage(disabled), drawX, drawY, nc); 948 992 if (selected || member) { 949 Color color; 950 if (disabled) { 951 color = inactiveColor; 952 } else if (selected) { 953 color = selectedColor; 954 } else { 955 color = relationSelectedColor; 956 } 957 temporaryGraphics.setColor(color); 958 temporaryGraphics.draw(new Rectangle2D.Double(drawX - 2, drawY - 2, w + 4, h + 4)); 959 } 993 selectionDrawer.accept(temporaryGraphics, new Rectangle2D.Double(drawX - 2, drawY - 2, img.getWidth() + 4, img.getHeight() + 4)); 994 } 995 } 996 997 private Color getSelectionHintColor(boolean disabled, boolean selected) { 998 Color color; 999 if (disabled) { 1000 color = inactiveColor; 1001 } else if (selected) { 1002 color = selectedColor; 1003 } else { 1004 color = relationSelectedColor; 1005 } 1006 return color; 960 1007 } 961 1008 -
trunk/src/org/openstreetmap/josm/gui/mappaint/styleelement/AreaElement.java
r11285 r11670 16 16 import org.openstreetmap.josm.gui.mappaint.Keyword; 17 17 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.IconReference; 18 import org.openstreetmap.josm.gui.util.RotationAngle; 18 19 import org.openstreetmap.josm.tools.CheckParameterUtil; 19 20 import org.openstreetmap.josm.tools.Utils; … … 56 57 public Float extentThreshold; 57 58 58 protected AreaElement(Cascade c, Color color, MapImage fillImage, Float extent, Float extentThreshold, TextLabel text) { 59 /** 60 * The icon that is displayed on the center of the area. 61 */ 62 private final MapImage iconImage; 63 64 private final RotationAngle iconImageAngle; 65 66 protected AreaElement(Cascade c, Color color, MapImage fillImage, Float extent, Float extentThreshold, TextLabel text, MapImage iconImage, RotationAngle iconImageAngle) { 59 67 super(c, 1f); 60 68 CheckParameterUtil.ensureParameterNotNull(color); … … 64 72 this.extentThreshold = extentThreshold; 65 73 this.text = text; 74 this.iconImage = iconImage; 75 this.iconImageAngle = iconImageAngle; 66 76 } 67 77 … … 109 119 } 110 120 111 TextLabel text = null; 112 Keyword textPos = c.get(TEXT_POSITION, null, Keyword.class); 113 if (textPos == null || "center".equals(textPos.val)) { 114 text = TextLabel.create(env, PaintColors.AREA_TEXT.get(), true); 121 if (color != null) { 122 123 TextLabel text = null; 124 Keyword textPos = c.get(TEXT_POSITION, null, Keyword.class); 125 if (textPos == null || "center".equals(textPos.val)) { 126 text = TextLabel.create(env, PaintColors.AREA_TEXT.get(), true); 127 } 128 129 Float extent = c.get(FILL_EXTENT, null, float.class); 130 Float extentThreshold = c.get(FILL_EXTENT_THRESHOLD, null, float.class); 131 132 MapImage iconImage = NodeElement.createIcon(env); 133 RotationAngle rotationAngle = NodeElement.createRotationAngle(env); 134 135 return new AreaElement(c, color, fillImage, extent, extentThreshold, text, iconImage, rotationAngle); 136 } else { 137 return null; 115 138 } 116 117 Float extent = c.get(FILL_EXTENT, null, float.class);118 Float extentThreshold = c.get(FILL_EXTENT_THRESHOLD, null, float.class);119 120 if (color != null)121 return new AreaElement(c, color, fillImage, extent, extentThreshold, text);122 else123 return null;124 139 } 125 140 … … 142 157 } 143 158 painter.drawArea((Relation) osm, myColor, fillImage, extent, extentThreshold, painter.isInactiveMode() || osm.isDisabled(), text); 159 } 160 161 if (iconImage != null && painter.isShowIcons()) { 162 painter.drawAreaIcon(osm, iconImage, painter.isInactiveMode() || osm.isDisabled(), selected, member, 163 iconImageAngle == null ? 0.0 : iconImageAngle.getRotationAngle(osm)); 144 164 } 145 165 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/styleelement/NodeElement.java
r11553 r11670 70 70 Cascade c = env.mc.getCascade(env.layer); 71 71 72 MapImage mapImage = createIcon(env , ICON_KEYS);72 MapImage mapImage = createIcon(env); 73 73 Symbol symbol = null; 74 74 if (mapImage == null) { 75 75 symbol = createSymbol(env); 76 76 } 77 78 RotationAngle rotationAngle = createRotationAngle(env); 79 80 // optimization: if we neither have a symbol, nor a mapImage 81 // we don't have to check for the remaining style properties and we don't 82 // have to allocate a node element style. 83 if (!allowDefault && symbol == null && mapImage == null) return null; 84 85 return new NodeElement(c, mapImage, symbol, defaultMajorZindex, rotationAngle); 86 } 87 88 /** 89 * Reads the icon-rotation property and creates a rotation angle from it. 90 * @param env The environment 91 * @return The angle 92 */ 93 public static RotationAngle createRotationAngle(Environment env) { 94 Cascade c = env.mc.getCascade(env.layer); 95 77 96 RotationAngle rotationAngle = null; 78 97 final Float angle = c.get(ICON_ROTATION, null, Float.class, true); … … 93 112 } 94 113 } 95 96 // optimization: if we neither have a symbol, nor a mapImage 97 // we don't have to check for the remaining style properties and we don't 98 // have to allocate a node element style. 99 if (!allowDefault && symbol == null && mapImage == null) return null; 100 101 return new NodeElement(c, mapImage, symbol, defaultMajorZindex, rotationAngle); 114 return rotationAngle; 115 } 116 117 public static MapImage createIcon(final Environment env) { 118 return createIcon(env, ICON_KEYS); 102 119 } 103 120
Note:
See TracChangeset
for help on using the changeset viewer.