diff --git a/src/main/org/insa/graphics/drawing/components/MapViewDrawing.java b/src/main/org/insa/graphics/drawing/components/MapViewDrawing.java index 82b2382..253db6d 100644 --- a/src/main/org/insa/graphics/drawing/components/MapViewDrawing.java +++ b/src/main/org/insa/graphics/drawing/components/MapViewDrawing.java @@ -119,8 +119,14 @@ public class MapViewDrawing extends MapView implements Drawing { */ private class MapViewMarkerOverlay extends MapViewOverlay implements MarkerOverlay { - public MapViewMarkerOverlay(Marker marker, Color color) { - super(new Layer[] { marker }, color); + private final AlphaMode alphaMode; + private Color innerColor; + + public MapViewMarkerOverlay(Marker marker, Color outer, Color innerColor, + AlphaMode alphaMode) { + super(new Layer[] { marker }, outer); + this.innerColor = innerColor; + this.alphaMode = alphaMode; } @Override @@ -131,10 +137,11 @@ public class MapViewDrawing extends MapView implements Drawing { } @Override - public void setColor(Color color) { + public void setColor(Color outer) { + this.innerColor = this.innerColor.equals(this.color) ? outer : this.innerColor; super.setColor(color); MarkerAutoScaling marker = (MarkerAutoScaling) super.layers[0]; - marker.setImage(MarkerUtils.getMarkerForColor(color)); + marker.setImage(MarkerUtils.getMarkerForColor(color, this.innerColor, this.alphaMode)); } @Override @@ -167,8 +174,10 @@ public class MapViewDrawing extends MapView implements Drawing { public void setColor(Color color) { super.setColor(color); ((PolylineAutoScaling) this.layers[0]).setColor(color); - ((MarkerAutoScaling) this.layers[1]).setImage(MarkerUtils.getMarkerForColor(color)); - ((MarkerAutoScaling) this.layers[2]).setImage(MarkerUtils.getMarkerForColor(color)); + ((MarkerAutoScaling) this.layers[1]) + .setImage(MarkerUtils.getMarkerForColor(color, color, AlphaMode.TRANSPARENT)); + ((MarkerAutoScaling) this.layers[2]) + .setImage(MarkerUtils.getMarkerForColor(color, color, AlphaMode.TRANSPARENT)); } } @@ -351,14 +360,16 @@ public class MapViewDrawing extends MapView implements Drawing { this.drawingClickListeners.remove(listener); } - protected MarkerAutoScaling createMarker(Point point, Color color) { - Image image = MarkerUtils.getMarkerForColor(color); + protected MarkerAutoScaling createMarker(Point point, Color outer, Color inner, + AlphaMode mode) { + Image image = MarkerUtils.getMarkerForColor(outer, inner, mode); return new MarkerAutoScaling(convertPoint(point), image); } @Override - public MarkerOverlay drawMarker(Point point, Color color) { - return new MapViewMarkerOverlay(createMarker(point, color), color); + public MarkerOverlay drawMarker(Point point, Color outer, Color inner, AlphaMode mode) { + return new MapViewMarkerOverlay(createMarker(point, outer, inner, mode), outer, inner, + mode); } @Override @@ -421,10 +432,10 @@ public class MapViewDrawing extends MapView implements Drawing { line.addAll(points); PathOverlay overlay = null; if (markers) { - MarkerAutoScaling origin = createMarker(path.getOrigin().getPoint(), - DEFAULT_PATH_COLOR), - destination = createMarker(path.getDestination().getPoint(), - DEFAULT_PATH_COLOR); + MarkerAutoScaling origin = createMarker(path.getOrigin().getPoint(), DEFAULT_PATH_COLOR, + DEFAULT_PATH_COLOR, AlphaMode.TRANSPARENT), + destination = createMarker(path.getDestination().getPoint(), DEFAULT_PATH_COLOR, + DEFAULT_PATH_COLOR, AlphaMode.TRANSPARENT); overlay = new MapViewPathOverlay(line, origin, destination); } else { diff --git a/src/main/org/insa/graphics/drawing/overlays/MarkerUtils.java b/src/main/org/insa/graphics/drawing/overlays/MarkerUtils.java index 1a9dcd0..79846ff 100644 --- a/src/main/org/insa/graphics/drawing/overlays/MarkerUtils.java +++ b/src/main/org/insa/graphics/drawing/overlays/MarkerUtils.java @@ -5,27 +5,41 @@ import java.awt.Image; import java.awt.image.BufferedImage; import java.io.DataInputStream; +import org.insa.graphics.drawing.Drawing.AlphaMode; + public class MarkerUtils { /** - * Create an Image representing a marker of the given color. + * Create an image to represent a marker using the given color for the outer and + * inner part, and the given mode for the inner part. * - * @param color Color of the marker. + * @param outer Outer color of the marker. + * @param inner Inner color of the marker. + * @param mode Mode to use to fill the inner part of the marker. * - * @return A new Image representing a marker with the given color. + * @return An image representing a marker. + * + * @see MarkerUtils#getMarkerForColor(Color, AlphaMode) */ - public static Image getMarkerForColor(Color color) { + public static Image getMarkerForColor(Color outer, Color inner, AlphaMode mode) { // create image int[][] mask = readMarkerMask(); BufferedImage image = new BufferedImage(mask[0].length, mask.length, BufferedImage.TYPE_4BYTE_ABGR); // Color[] map = getColorMapping(color); - int rgb = color.getRGB() & 0x00ffffff; + int outerRGB = outer.getRGB() & 0x00ffffff; + int innerRGB = inner.getRGB() & 0x00ffffff; for (int i = 0; i < image.getHeight(); ++i) { for (int j = 0; j < image.getWidth(); ++j) { - // image.setRGB(j, i, map[MARKER_MASK[i][j]].getRGB()); - image.setRGB(j, i, rgb | (mask[i][j] << 24)); + if (i >= MIN_Y_CENTER && i < MAX_Y_CENTER && j >= MIN_X_CENTER + && j < MAX_X_CENTER) { + image.setRGB(j, i, innerRGB + | ((mode == AlphaMode.OPAQUE ? MAXIMUM_MAX_VALUE : mask[i][j]) << 24)); + } + else { + image.setRGB(j, i, outerRGB | (mask[i][j] << 24)); + } } } @@ -35,6 +49,12 @@ public class MarkerUtils { // Mask cache private static int[][] MASK_CACHE = null; + // Hand-made... These defines the "center" of the marker, that can be filled + // with a different color. + private static final int MIN_X_CENTER = 40, MAX_X_CENTER = 101, MIN_Y_CENTER = 40, + MAX_Y_CENTER = 100; + private static final int MAXIMUM_MAX_VALUE = 249; + /** * @return Retrieve the mask from the mask file or from the cache. */