Changeset 3879 in josm
- Timestamp:
- 2011-02-09T19:13:04+01:00 (14 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPainter.java
r3871 r3879 211 211 } 212 212 213 public void drawNodeSymbol(Node n, Symbol s, boolean selected, boolean member, TextElement text) {213 public void drawNodeSymbol(Node n, Symbol s, Color fillColor, Color strokeColor, TextElement text) { 214 214 Point p = nc.getPoint(n); 215 215 if ((p.x < 0) || (p.y < 0) || (p.x > nc.getWidth()) || (p.y > nc.getHeight())) return; 216 216 int radius = s.size / 2; 217 217 218 if (s.fillColor != null) { 219 if (inactive || n.isDisabled()) { 220 g.setColor(inactiveColor); 221 } else { 222 g.setColor(s.fillColor); 223 } 218 if (fillColor != null) { 219 g.setColor(fillColor); 224 220 switch (s.symbol) { 225 221 case SQUARE: … … 235 231 if (s.stroke != null) { 236 232 g.setStroke(s.stroke); 237 if (inactive || n.isDisabled()) { 238 g.setColor(inactiveColor); 239 } else { 240 g.setColor(s.strokeColor); 241 } 233 g.setColor(strokeColor); 242 234 switch (s.symbol) { 243 235 case SQUARE: … … 353 345 } 354 346 355 public void drawArea(Way w, Color color, BufferedImage fillImage, String name) { 347 public void drawArea(Way w, Color color, BufferedImage fillImage, float fillImageAlpha, String name) { 356 348 Polygon polygon = getPolygon(w); 357 drawArea(polygon, color, fillImage, name); 358 } 359 360 protected void drawArea(Polygon polygon, Color color, BufferedImage fillImage, String name) { 349 drawArea(polygon, color, fillImage, fillImageAlpha, name); 350 } 351 352 protected void drawArea(Polygon polygon, Color color, BufferedImage fillImage, float fillImageAlpha, String name) { 361 353 362 354 if (fillImage == null) { … … 367 359 new Rectangle(polygon.xpoints[0], polygon.ypoints[0], fillImage.getWidth(), fillImage.getHeight())); 368 360 g.setPaint(texture); 369 if ( color.getAlpha() != 255) {370 g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, Utils.color_int2float(color.getAlpha())));361 if (fillImageAlpha != 1f) { 362 g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, fillImageAlpha)); 371 363 } 372 364 g.fill(polygon); … … 411 403 } 412 404 413 public void drawArea(Relation r, Color color, BufferedImage fillImage, String name) { 405 public void drawArea(Relation r, Color color, BufferedImage fillImage, float fillImageAlpha, String name) { 414 406 Multipolygon multipolygon = new Multipolygon(nc); 415 407 multipolygon.load(r); … … 420 412 continue; 421 413 } 422 drawArea(p, color, fillImage, getAreaName(r)); 414 drawArea(p, color, fillImage, fillImageAlpha, getAreaName(r)); 423 415 } 424 416 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/AreaElemStyle.java
r3865 r3879 14 14 import org.openstreetmap.josm.data.osm.visitor.paint.MapPainter; 15 15 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.IconReference; 16 import org.openstreetmap.josm.tools.CheckParameterUtil; 16 17 import org.openstreetmap.josm.tools.Utils; 17 18 18 19 public class AreaElemStyle extends ElemStyle 19 20 { 21 /** 22 * If fillImage == null, color is the fill-color, otherwise 23 * an arbitrary color value sampled from the fillImage 24 */ 20 25 public Color color; 21 26 public BufferedImage fillImage; 27 public float fillImageAlpha; 22 28 23 protected AreaElemStyle(Cascade c, Color color, BufferedImage fillImage) { 29 protected AreaElemStyle(Cascade c, Color color, BufferedImage fillImage, float fillImageAlpha) { 24 30 super(c); 31 CheckParameterUtil.ensureParameterNotNull(color); 25 32 this.color = color; 26 33 this.fillImage = fillImage; 34 this.fillImageAlpha = fillImageAlpha; 27 35 } 28 36 29 37 public static AreaElemStyle create(Cascade c) { 30 38 BufferedImage fillImage = null; 39 Color color = null; 40 float fillImageAlpha = 1f; 41 31 42 IconReference iconRef = c.get("fill-image", null, IconReference.class); 32 Integer fillImageAlpha = null;33 34 43 if (iconRef != null) { 35 44 ImageIcon icon = MapPaintStyles.getIcon(iconRef, false); … … 42 51 fillImage = (BufferedImage) icon.getImage(); 43 52 44 fillImageAlpha = Math.min(255, Math.max(0, Integer.valueOf(Main.pref.getInteger("mappaint.fill-image-alpha", 255)))); 45 Integer pAlpha = Utils.color_float2int(c.get("fill-opacity", null, float.class)); 53 color = new Color(fillImage.getRGB(fillImage.getWidth() / 2, fillImage.getHeight() / 2)); 54 55 fillImageAlpha = Utils.color_int2float(Math.min(255, Math.max(0, Integer.valueOf(Main.pref.getInteger("mappaint.fill-image-alpha", 255))))); 56 Float pAlpha = c.get("fill-opacity", null, Float.class); 46 57 if (pAlpha != null) { 58 if (pAlpha < 0f || pAlpha > 1f) { 59 pAlpha= 1f; 60 } 47 61 fillImageAlpha = pAlpha; 48 62 } 49 63 } 50 } 51 52 Color color = c.get("fill-color", null, Color.class); 53 if (color != null) { 54 55 int alpha; 56 if (fillImageAlpha != null) { 57 alpha = fillImageAlpha; 58 } else { 59 alpha = Math.min(255, Math.max(0, Integer.valueOf(Main.pref.getInteger("mappaint.fillalpha", 50)))); 64 } else { 65 color = c.get("fill-color", null, Color.class); 66 if (color != null) { 67 int alpha = Math.min(255, Math.max(0, Integer.valueOf(Main.pref.getInteger("mappaint.fillalpha", 50)))); 60 68 Integer pAlpha = Utils.color_float2int(c.get("fill-opacity", null, float.class)); 61 69 if (pAlpha != null) { 62 70 alpha = pAlpha; 63 71 } 72 color = new Color(color.getRed(), color.getGreen(), color.getBlue(), alpha); 64 73 } 65 color = new Color(color.getRed(), color.getGreen(), color.getBlue(), alpha);66 74 } 67 75 68 if (fillImage != null || color != null) { 69 if (color == null) { 70 color = new Color(0, 0, 0, fillImageAlpha); 71 } 72 return new AreaElemStyle(c, color, fillImage); 73 } 76 if (color != null) 77 return new AreaElemStyle(c, color, fillImage, fillImageAlpha); 74 78 else 75 79 return null; … … 86 90 } 87 91 } 88 painter.drawArea((Way) osm, myColor, fillImage, 92 painter.drawArea((Way) osm, myColor, fillImage, fillImageAlpha, 89 93 painter.isShowNames() ? painter.getAreaName(osm) : null); 90 94 } else if (osm instanceof Relation) … … 96 100 } 97 101 } 98 painter.drawArea((Relation) osm, myColor, fillImage, 102 painter.drawArea((Relation) osm, myColor, fillImage, fillImageAlpha, 99 103 painter.getAreaName(osm)); 100 104 } … … 109 113 AreaElemStyle other = (AreaElemStyle) obj; 110 114 // we should get the same image object due to caching 111 if (fillImage != other.fillImage && (fillImage == null || other.fillImage == null || fillImage != other.fillImage))115 if (fillImage != other.fillImage) 112 116 return false; 113 117 if (!Utils.equal(color, other.color)) 118 return false; 119 if (fillImageAlpha != other.fillImageAlpha) 114 120 return false; 115 121 return true; … … 119 125 public int hashCode() { 120 126 int hash = 3; 121 hash = 61 * hash + (this.color != null ? this.color.hashCode() : 0); 122 hash = 61 * hash + (this.fillImage != null ? this.fillImage.hashCode() : 0); 127 hash = 61 * hash + color.hashCode(); 128 hash = 61 * hash + (fillImage != null ? fillImage.hashCode() : 0); 129 hash = 61 * hash + Float.floatToIntBits(fillImageAlpha); 123 130 return hash; 124 131 } … … 126 133 @Override 127 134 public String toString() { 128 return "AreaElemStyle{" + super.toString() + "color=" + Utils.toString(color) + '}'; 135 return "AreaElemStyle{" + super.toString() + "color=" + Utils.toString(color) + 136 " fillImageAlpha=" + fillImageAlpha + " fillImage=[" + fillImage + "]}"; 129 137 } 130 138 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java
r3871 r3879 240 240 return null; 241 241 242 Float size = c.get("symbol-size",null, Float.class);243 if (size == null || size<= 0)242 float size = c.get("symbol-size", 10f, Float.class); 243 if (size <= 0) 244 244 return null; 245 245 246 246 Float strokeWidth = c.get("symbol-stroke-width", null, Float.class); 247 if (strokeWidth != null && strokeWidth <= 0) { 248 strokeWidth = null; 249 } 247 250 Color strokeColor = c.get("symbol-stroke-color", null, Color.class); 251 252 if (strokeWidth == null && strokeColor != null) { 253 strokeWidth = 1f; 254 } else if (strokeWidth != null && strokeColor == null) { 255 strokeColor = Color.ORANGE; 256 } 257 258 Stroke stroke = null; 248 259 if (strokeColor != null) { 249 260 float strokeAlpha = c.get("symbol-stroke-opacity", 1f, Float.class); 250 261 strokeColor = new Color(strokeColor.getRed(), strokeColor.getGreen(), 251 262 strokeColor.getBlue(), Utils.color_float2int(strokeAlpha)); 252 }253 Stroke stroke = null;254 if (strokeWidth != null && strokeWidth > 0 && strokeColor != null) {255 263 stroke = new BasicStroke(strokeWidth); 256 264 } 257 265 258 266 Color fillColor = c.get("symbol-fill-color", null, Color.class); 267 if (stroke == null && fillColor == null) 268 fillColor = Color.BLUE; 269 259 270 if (fillColor != null) { 260 271 float fillAlpha = c.get("symbol-fill-opacity", 1f, Float.class); … … 263 274 } 264 275 265 if ((stroke == null || strokeColor == null) && fillColor == null) 266 return null; 267 268 return new Symbol(shape, size.intValue(), stroke, strokeColor, fillColor); 276 return new Symbol(shape, Math.round(size), stroke, strokeColor, fillColor); 269 277 } 270 278 … … 277 285 Utils.color_int2float(iconAlpha), selected, member, text); 278 286 } else if (symbol != null) { 279 painter.drawNodeSymbol(n, symbol, selected, member, text); 287 Color fillColor = symbol.fillColor; 288 if (fillColor != null) { 289 if (n.isHighlighted()) { 290 fillColor = settings.getHighlightColor(); 291 } else { 292 if (painter.isInactive() || n.isDisabled()) { 293 fillColor = settings.getInactiveColor(); 294 } else if (selected) { 295 fillColor = settings.getSelectedColor(fillColor.getAlpha()); 296 } else if (member) { 297 fillColor = settings.getRelationSelectedColor(fillColor.getAlpha()); 298 } 299 } 300 } 301 Color strokeColor = symbol.strokeColor; 302 if (strokeColor != null) { 303 if (n.isHighlighted()) { 304 strokeColor = settings.getHighlightColor(); 305 } else { 306 if (painter.isInactive() || n.isDisabled()) { 307 strokeColor = settings.getInactiveColor(); 308 } else if (selected) { 309 strokeColor = settings.getSelectedColor(strokeColor.getAlpha()); 310 } else if (member) { 311 strokeColor = settings.getRelationSelectedColor(strokeColor.getAlpha()); 312 } 313 } 314 } 315 painter.drawNodeSymbol(n, symbol, fillColor, strokeColor, text); 280 316 } else { 281 317 if (n.isHighlighted()) { -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r3869 r3879 138 138 * convert float range 0 <= x <= 1 to integer range 0..255 139 139 * when dealing with colors and color alpha value 140 * @return null if val is null, the corresponding int if val is in the 141 * range 0...1. If val is outside that range, return 255 140 142 */ 141 143 public static Integer color_float2int(Float val) {
Note:
See TracChangeset
for help on using the changeset viewer.