Browse Source

Merge master.

Holt59 3 years ago
parent
commit
ccd6d7d7af

+ 3
- 3
src/main/org/insa/graphics/NodesInputPanel.java View File

@@ -248,8 +248,8 @@ public class NodesInputPanel extends JPanel
248 248
                 MarkerOverlay tracker = markerTrackers.getOrDefault(textField, null);
249 249
                 if (curnode != null) {
250 250
                     if (tracker == null) {
251
-                        tracker = drawing.drawMarker(curnode.getPoint(), markerColor, markerColor,
252
-                                AlphaMode.OPAQUE);
251
+                        tracker = drawing.drawMarker(curnode.getPoint(), markerColor, Color.BLACK,
252
+                                AlphaMode.TRANSPARENT);
253 253
                         markerTrackers.put(textField, tracker);
254 254
                     }
255 255
                     else {
@@ -414,7 +414,7 @@ public class NodesInputPanel extends JPanel
414 414
             MarkerOverlay tracker = markerTrackers.getOrDefault(input, null);
415 415
             if (tracker != null) {
416 416
                 MarkerOverlay newMarker = this.drawing.drawMarker(tracker.getPoint(),
417
-                        tracker.getColor(), tracker.getColor(), AlphaMode.OPAQUE);
417
+                        tracker.getColor(), Color.BLACK, AlphaMode.TRANSPARENT);
418 418
                 markerTrackers.put(input, newMarker);
419 419
                 newMarker.setVisible(tracker.isVisible());
420 420
                 tracker.delete();

+ 19
- 6
src/main/org/insa/graphics/drawing/overlays/MarkerUtils.java View File

@@ -29,14 +29,27 @@ public class MarkerUtils {
29 29
 
30 30
         // Color[] map = getColorMapping(color);
31 31
         int outerRGB = outer.getRGB() & 0x00ffffff;
32
-        int innerRGB = inner.getRGB() & 0x00ffffff;
33 32
         for (int i = 0; i < image.getHeight(); ++i) {
34 33
             for (int j = 0; j < image.getWidth(); ++j) {
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));
34
+
35
+                // If we are in the "inner" part of the marker...
36
+                if (i >= MIN_Y_CENTER && i < MAX_Y_CENTER && j >= MIN_X_CENTER && j < MAX_X_CENTER
37
+                        && mask[i][j] != MAXIMUM_INNER_MASK_VALUE) {
38
+                    // Don't ask... https://stackoverflow.com/a/29321264/2666289
39
+                    // Basically, this compute a "middle" color between outer and inner depending on
40
+                    // the current mask value.
41
+                    double t = 1 - (mask[i][j] - MINIMUM_INNER_MASK_VALUE)
42
+                            / (double) (MAXIMUM_INNER_MASK_VALUE - MINIMUM_INNER_MASK_VALUE);
43
+                    int r = (int) Math.sqrt((1 - t) * outer.getRed() * outer.getRed()
44
+                            + t * inner.getRed() * inner.getRed());
45
+                    int g = (int) Math.sqrt((1 - t) * outer.getGreen() * outer.getGreen()
46
+                            + t * inner.getGreen() * inner.getGreen());
47
+                    int b = (int) Math.sqrt((1 - t) * outer.getBlue() * outer.getBlue()
48
+                            + t * inner.getBlue() * inner.getBlue());
49
+                    int a = mode == AlphaMode.OPAQUE ? MAXIMUM_INNER_MASK_VALUE : mask[i][j];
50
+                    image.setRGB(j, i, (a << 24) | (r << 16) | (g << 8) | b);
39 51
                 }
52
+                // Otherwize, just fill with the outer color and set the alpha value properly.
40 53
                 else {
41 54
                     image.setRGB(j, i, outerRGB | (mask[i][j] << 24));
42 55
                 }
@@ -53,7 +66,7 @@ public class MarkerUtils {
53 66
     // with a different color.
54 67
     private static final int MIN_X_CENTER = 40, MAX_X_CENTER = 101, MIN_Y_CENTER = 40,
55 68
             MAX_Y_CENTER = 100;
56
-    private static final int MAXIMUM_MAX_VALUE = 249;
69
+    private static final int MINIMUM_INNER_MASK_VALUE = 116, MAXIMUM_INNER_MASK_VALUE = 249;
57 70
 
58 71
     /**
59 72
      * @return Retrieve the mask from the mask file or from the cache.

Loading…
Cancel
Save