Browse Source

Merge master.

Holt59 3 years ago
parent
commit
e78ea25ab3

+ 25
- 14
src/main/org/insa/graphics/drawing/components/MapViewDrawing.java View File

@@ -119,8 +119,14 @@ public class MapViewDrawing extends MapView implements Drawing {
119 119
      */
120 120
     private class MapViewMarkerOverlay extends MapViewOverlay implements MarkerOverlay {
121 121
 
122
-        public MapViewMarkerOverlay(Marker marker, Color color) {
123
-            super(new Layer[] { marker }, color);
122
+        private final AlphaMode alphaMode;
123
+        private Color innerColor;
124
+
125
+        public MapViewMarkerOverlay(Marker marker, Color outer, Color innerColor,
126
+                AlphaMode alphaMode) {
127
+            super(new Layer[] { marker }, outer);
128
+            this.innerColor = innerColor;
129
+            this.alphaMode = alphaMode;
124 130
         }
125 131
 
126 132
         @Override
@@ -131,10 +137,11 @@ public class MapViewDrawing extends MapView implements Drawing {
131 137
         }
132 138
 
133 139
         @Override
134
-        public void setColor(Color color) {
140
+        public void setColor(Color outer) {
141
+            this.innerColor = this.innerColor.equals(this.color) ? outer : this.innerColor;
135 142
             super.setColor(color);
136 143
             MarkerAutoScaling marker = (MarkerAutoScaling) super.layers[0];
137
-            marker.setImage(MarkerUtils.getMarkerForColor(color));
144
+            marker.setImage(MarkerUtils.getMarkerForColor(color, this.innerColor, this.alphaMode));
138 145
         }
139 146
 
140 147
         @Override
@@ -167,8 +174,10 @@ public class MapViewDrawing extends MapView implements Drawing {
167 174
         public void setColor(Color color) {
168 175
             super.setColor(color);
169 176
             ((PolylineAutoScaling) this.layers[0]).setColor(color);
170
-            ((MarkerAutoScaling) this.layers[1]).setImage(MarkerUtils.getMarkerForColor(color));
171
-            ((MarkerAutoScaling) this.layers[2]).setImage(MarkerUtils.getMarkerForColor(color));
177
+            ((MarkerAutoScaling) this.layers[1])
178
+                    .setImage(MarkerUtils.getMarkerForColor(color, color, AlphaMode.TRANSPARENT));
179
+            ((MarkerAutoScaling) this.layers[2])
180
+                    .setImage(MarkerUtils.getMarkerForColor(color, color, AlphaMode.TRANSPARENT));
172 181
         }
173 182
 
174 183
     }
@@ -351,14 +360,16 @@ public class MapViewDrawing extends MapView implements Drawing {
351 360
         this.drawingClickListeners.remove(listener);
352 361
     }
353 362
 
354
-    protected MarkerAutoScaling createMarker(Point point, Color color) {
355
-        Image image = MarkerUtils.getMarkerForColor(color);
363
+    protected MarkerAutoScaling createMarker(Point point, Color outer, Color inner,
364
+            AlphaMode mode) {
365
+        Image image = MarkerUtils.getMarkerForColor(outer, inner, mode);
356 366
         return new MarkerAutoScaling(convertPoint(point), image);
357 367
     }
358 368
 
359 369
     @Override
360
-    public MarkerOverlay drawMarker(Point point, Color color) {
361
-        return new MapViewMarkerOverlay(createMarker(point, color), color);
370
+    public MarkerOverlay drawMarker(Point point, Color outer, Color inner, AlphaMode mode) {
371
+        return new MapViewMarkerOverlay(createMarker(point, outer, inner, mode), outer, inner,
372
+                mode);
362 373
     }
363 374
 
364 375
     @Override
@@ -421,10 +432,10 @@ public class MapViewDrawing extends MapView implements Drawing {
421 432
         line.addAll(points);
422 433
         PathOverlay overlay = null;
423 434
         if (markers) {
424
-            MarkerAutoScaling origin = createMarker(path.getOrigin().getPoint(),
425
-                    DEFAULT_PATH_COLOR),
426
-                    destination = createMarker(path.getDestination().getPoint(),
427
-                            DEFAULT_PATH_COLOR);
435
+            MarkerAutoScaling origin = createMarker(path.getOrigin().getPoint(), DEFAULT_PATH_COLOR,
436
+                    DEFAULT_PATH_COLOR, AlphaMode.TRANSPARENT),
437
+                    destination = createMarker(path.getDestination().getPoint(), DEFAULT_PATH_COLOR,
438
+                            DEFAULT_PATH_COLOR, AlphaMode.TRANSPARENT);
428 439
             overlay = new MapViewPathOverlay(line, origin, destination);
429 440
         }
430 441
         else {

+ 27
- 7
src/main/org/insa/graphics/drawing/overlays/MarkerUtils.java View File

@@ -5,27 +5,41 @@ import java.awt.Image;
5 5
 import java.awt.image.BufferedImage;
6 6
 import java.io.DataInputStream;
7 7
 
8
+import org.insa.graphics.drawing.Drawing.AlphaMode;
9
+
8 10
 public class MarkerUtils {
9 11
 
10 12
     /**
11
-     * Create an Image representing a marker of the given color.
13
+     * Create an image to represent a marker using the given color for the outer and
14
+     * inner part, and the given mode for the inner part.
15
+     * 
16
+     * @param outer Outer color of the marker.
17
+     * @param inner Inner color of the marker.
18
+     * @param mode Mode to use to fill the inner part of the marker.
12 19
      * 
13
-     * @param color Color of the marker.
20
+     * @return An image representing a marker.
14 21
      * 
15
-     * @return A new Image representing a marker with the given color.
22
+     * @see MarkerUtils#getMarkerForColor(Color, AlphaMode)
16 23
      */
17
-    public static Image getMarkerForColor(Color color) {
24
+    public static Image getMarkerForColor(Color outer, Color inner, AlphaMode mode) {
18 25
         // create image
19 26
         int[][] mask = readMarkerMask();
20 27
         BufferedImage image = new BufferedImage(mask[0].length, mask.length,
21 28
                 BufferedImage.TYPE_4BYTE_ABGR);
22 29
 
23 30
         // Color[] map = getColorMapping(color);
24
-        int rgb = color.getRGB() & 0x00ffffff;
31
+        int outerRGB = outer.getRGB() & 0x00ffffff;
32
+        int innerRGB = inner.getRGB() & 0x00ffffff;
25 33
         for (int i = 0; i < image.getHeight(); ++i) {
26 34
             for (int j = 0; j < image.getWidth(); ++j) {
27
-                // image.setRGB(j, i, map[MARKER_MASK[i][j]].getRGB());
28
-                image.setRGB(j, i, rgb | (mask[i][j] << 24));
35
+                if (i >= MIN_Y_CENTER && i < MAX_Y_CENTER && j >= MIN_X_CENTER
36
+                        && j < MAX_X_CENTER) {
37
+                    image.setRGB(j, i, innerRGB
38
+                            | ((mode == AlphaMode.OPAQUE ? MAXIMUM_MAX_VALUE : mask[i][j]) << 24));
39
+                }
40
+                else {
41
+                    image.setRGB(j, i, outerRGB | (mask[i][j] << 24));
42
+                }
29 43
             }
30 44
         }
31 45
 
@@ -35,6 +49,12 @@ public class MarkerUtils {
35 49
     // Mask cache
36 50
     private static int[][] MASK_CACHE = null;
37 51
 
52
+    // Hand-made... These defines the "center" of the marker, that can be filled
53
+    // with a different color.
54
+    private static final int MIN_X_CENTER = 40, MAX_X_CENTER = 101, MIN_Y_CENTER = 40,
55
+            MAX_Y_CENTER = 100;
56
+    private static final int MAXIMUM_MAX_VALUE = 249;
57
+
38 58
     /**
39 59
      * @return Retrieve the mask from the mask file or from the cache.
40 60
      */

Loading…
Cancel
Save