Merge master.

This commit is contained in:
Holt59 2018-03-13 23:07:30 +01:00
parent c7d4dc8077
commit e78ea25ab3
2 changed files with 52 additions and 21 deletions

View File

@ -119,8 +119,14 @@ public class MapViewDrawing extends MapView implements Drawing {
*/ */
private class MapViewMarkerOverlay extends MapViewOverlay implements MarkerOverlay { private class MapViewMarkerOverlay extends MapViewOverlay implements MarkerOverlay {
public MapViewMarkerOverlay(Marker marker, Color color) { private final AlphaMode alphaMode;
super(new Layer[] { marker }, color); 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 @Override
@ -131,10 +137,11 @@ public class MapViewDrawing extends MapView implements Drawing {
} }
@Override @Override
public void setColor(Color color) { public void setColor(Color outer) {
this.innerColor = this.innerColor.equals(this.color) ? outer : this.innerColor;
super.setColor(color); super.setColor(color);
MarkerAutoScaling marker = (MarkerAutoScaling) super.layers[0]; MarkerAutoScaling marker = (MarkerAutoScaling) super.layers[0];
marker.setImage(MarkerUtils.getMarkerForColor(color)); marker.setImage(MarkerUtils.getMarkerForColor(color, this.innerColor, this.alphaMode));
} }
@Override @Override
@ -167,8 +174,10 @@ public class MapViewDrawing extends MapView implements Drawing {
public void setColor(Color color) { public void setColor(Color color) {
super.setColor(color); super.setColor(color);
((PolylineAutoScaling) this.layers[0]).setColor(color); ((PolylineAutoScaling) this.layers[0]).setColor(color);
((MarkerAutoScaling) this.layers[1]).setImage(MarkerUtils.getMarkerForColor(color)); ((MarkerAutoScaling) this.layers[1])
((MarkerAutoScaling) this.layers[2]).setImage(MarkerUtils.getMarkerForColor(color)); .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); this.drawingClickListeners.remove(listener);
} }
protected MarkerAutoScaling createMarker(Point point, Color color) { protected MarkerAutoScaling createMarker(Point point, Color outer, Color inner,
Image image = MarkerUtils.getMarkerForColor(color); AlphaMode mode) {
Image image = MarkerUtils.getMarkerForColor(outer, inner, mode);
return new MarkerAutoScaling(convertPoint(point), image); return new MarkerAutoScaling(convertPoint(point), image);
} }
@Override @Override
public MarkerOverlay drawMarker(Point point, Color color) { public MarkerOverlay drawMarker(Point point, Color outer, Color inner, AlphaMode mode) {
return new MapViewMarkerOverlay(createMarker(point, color), color); return new MapViewMarkerOverlay(createMarker(point, outer, inner, mode), outer, inner,
mode);
} }
@Override @Override
@ -421,10 +432,10 @@ public class MapViewDrawing extends MapView implements Drawing {
line.addAll(points); line.addAll(points);
PathOverlay overlay = null; PathOverlay overlay = null;
if (markers) { if (markers) {
MarkerAutoScaling origin = createMarker(path.getOrigin().getPoint(), MarkerAutoScaling origin = createMarker(path.getOrigin().getPoint(), DEFAULT_PATH_COLOR,
DEFAULT_PATH_COLOR), DEFAULT_PATH_COLOR, AlphaMode.TRANSPARENT),
destination = createMarker(path.getDestination().getPoint(), destination = createMarker(path.getDestination().getPoint(), DEFAULT_PATH_COLOR,
DEFAULT_PATH_COLOR); DEFAULT_PATH_COLOR, AlphaMode.TRANSPARENT);
overlay = new MapViewPathOverlay(line, origin, destination); overlay = new MapViewPathOverlay(line, origin, destination);
} }
else { else {

View File

@ -5,27 +5,41 @@ import java.awt.Image;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.DataInputStream; import java.io.DataInputStream;
import org.insa.graphics.drawing.Drawing.AlphaMode;
public class MarkerUtils { 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 // create image
int[][] mask = readMarkerMask(); int[][] mask = readMarkerMask();
BufferedImage image = new BufferedImage(mask[0].length, mask.length, BufferedImage image = new BufferedImage(mask[0].length, mask.length,
BufferedImage.TYPE_4BYTE_ABGR); BufferedImage.TYPE_4BYTE_ABGR);
// Color[] map = getColorMapping(color); // 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 i = 0; i < image.getHeight(); ++i) {
for (int j = 0; j < image.getWidth(); ++j) { for (int j = 0; j < image.getWidth(); ++j) {
// image.setRGB(j, i, map[MARKER_MASK[i][j]].getRGB()); if (i >= MIN_Y_CENTER && i < MAX_Y_CENTER && j >= MIN_X_CENTER
image.setRGB(j, i, rgb | (mask[i][j] << 24)); && 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 // Mask cache
private static int[][] MASK_CACHE = null; 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. * @return Retrieve the mask from the mask file or from the cache.
*/ */