From b3ff48fcc62c328e6c3ea60337ebe9fdd8a906d3 Mon Sep 17 00:00:00 2001 From: Emux Date: Sun, 11 Feb 2024 11:12:52 +0200 Subject: [PATCH] Line style transparent option (#1100) --- docs/Changelog.md | 1 + .../org/oscim/layers/vector/VectorLayer.java | 1 + .../oscim/layers/vector/geometries/Style.java | 8 ++++++ .../src/org/oscim/test/LineRenderTest.java | 10 +++---- .../org/oscim/renderer/bucket/LineBucket.java | 7 +++-- vtm/src/org/oscim/theme/styles/LineStyle.java | 26 ++++++++++++++++--- vtm/src/org/oscim/utils/Parameters.java | 5 ---- 7 files changed, 40 insertions(+), 18 deletions(-) diff --git a/docs/Changelog.md b/docs/Changelog.md index bf1420839..99cf962a9 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -4,6 +4,7 @@ - Drawable style `dropDistance` option [#1085](https://github.com/mapsforge/vtm/pull/1085) - Removed `pointReduction` option +- Line style `transparent` option [#1100](https://github.com/mapsforge/vtm/pull/1100) - Canvas adapter: line scale option [#1075](https://github.com/mapsforge/vtm/pull/1075) - Minor improvements and bug fixes - [Solved issues](https://github.com/mapsforge/vtm/issues?q=is%3Aclosed+milestone%3A0.21.0) diff --git a/vtm-jts/src/org/oscim/layers/vector/VectorLayer.java b/vtm-jts/src/org/oscim/layers/vector/VectorLayer.java index 1f6841286..e21bd69a6 100644 --- a/vtm-jts/src/org/oscim/layers/vector/VectorLayer.java +++ b/vtm-jts/src/org/oscim/layers/vector/VectorLayer.java @@ -295,6 +295,7 @@ protected void drawLine(Task t, int level, Geometry line, Style style) { .strokeIncrease(style.strokeIncrease) .strokeWidth(style.strokeWidth) .texture(style.texture) + .transparent(style.transparent) .build(); ll.setDropDistance(style.dropDistance); if (ll instanceof LineTexBucket) diff --git a/vtm-jts/src/org/oscim/layers/vector/geometries/Style.java b/vtm-jts/src/org/oscim/layers/vector/geometries/Style.java index 5e7e8bcce..0b23d3471 100644 --- a/vtm-jts/src/org/oscim/layers/vector/geometries/Style.java +++ b/vtm-jts/src/org/oscim/layers/vector/geometries/Style.java @@ -58,6 +58,7 @@ public class Style { public final float heightOffset; public final boolean randomOffset; + public final boolean transparent; private Style(Builder builder) { strokeWidth = builder.strokeWidth; @@ -84,6 +85,7 @@ private Style(Builder builder) { heightOffset = builder.heightOffset; randomOffset = builder.randomOffset; + transparent = builder.transparent; } /** @@ -121,6 +123,7 @@ public static class Builder { public float heightOffset = 0; public boolean randomOffset = true; + public boolean transparent = false; protected Builder() { } @@ -274,6 +277,11 @@ public Builder randomOffset(boolean randomOffset) { this.randomOffset = randomOffset; return this; } + + public Builder transparent(boolean transparent) { + this.transparent = transparent; + return this; + } } static final Style DEFAULT_STYLE = new Builder() diff --git a/vtm-playground/src/org/oscim/test/LineRenderTest.java b/vtm-playground/src/org/oscim/test/LineRenderTest.java index d91a58c71..96c70b2c5 100644 --- a/vtm-playground/src/org/oscim/test/LineRenderTest.java +++ b/vtm-playground/src/org/oscim/test/LineRenderTest.java @@ -69,9 +69,9 @@ void addLines(LineTest l, int layer, boolean addOutline, boolean fixed) { line2 = new LineStyle(Color.GREEN, 1); line4 = new LineStyle(Color.LTGRAY, 3); } else { - line1 = new LineStyle(0, null, Color.fade(Color.RED, 0.5f), 4.0f, Cap.BUTT, false, 1, 0, 0, 0, 0, 1f, false, null, true, null, LineStyle.REPEAT_START_DEFAULT, LineStyle.REPEAT_GAP_DEFAULT); - line2 = new LineStyle(0, null, Color.GREEN, 6.0f, Cap.BUTT, false, 1, 0, 0, 0, 0, 1f, false, null, true, null, LineStyle.REPEAT_START_DEFAULT, LineStyle.REPEAT_GAP_DEFAULT); - line4 = new LineStyle(0, null, Color.LTGRAY, 2.0f, Cap.ROUND, false, 1, 0, 0, 0, 0, 1f, false, null, true, null, LineStyle.REPEAT_START_DEFAULT, LineStyle.REPEAT_GAP_DEFAULT); + line1 = new LineStyle(0, null, Color.fade(Color.RED, 0.5f), 4.0f, Cap.BUTT, false, 1, 0, 0, 0, 0, 1f, false, null, true, null, LineStyle.REPEAT_START_DEFAULT, LineStyle.REPEAT_GAP_DEFAULT, false); + line2 = new LineStyle(0, null, Color.GREEN, 6.0f, Cap.BUTT, false, 1, 0, 0, 0, 0, 1f, false, null, true, null, LineStyle.REPEAT_START_DEFAULT, LineStyle.REPEAT_GAP_DEFAULT, false); + line4 = new LineStyle(0, null, Color.LTGRAY, 2.0f, Cap.ROUND, false, 1, 0, 0, 0, 0, 1f, false, null, true, null, LineStyle.REPEAT_START_DEFAULT, LineStyle.REPEAT_GAP_DEFAULT, false); } TextureItem tex = null; @@ -92,8 +92,8 @@ void addLines(LineTest l, int layer, boolean addOutline, boolean fixed) { .randomOffset(true) .build(); - LineStyle outline = new LineStyle(0, null, Color.BLUE, 2.0f, Cap.ROUND, false, 1, 0, 0, 0, 0, 1f, true, null, true, null, LineStyle.REPEAT_START_DEFAULT, LineStyle.REPEAT_GAP_DEFAULT); - LineStyle outline2 = new LineStyle(0, null, Color.RED, 2.0f, Cap.ROUND, false, 1, 0, 0, 0, 0, 0, true, null, true, null, LineStyle.REPEAT_START_DEFAULT, LineStyle.REPEAT_GAP_DEFAULT); + LineStyle outline = new LineStyle(0, null, Color.BLUE, 2.0f, Cap.ROUND, false, 1, 0, 0, 0, 0, 1f, true, null, true, null, LineStyle.REPEAT_START_DEFAULT, LineStyle.REPEAT_GAP_DEFAULT, false); + LineStyle outline2 = new LineStyle(0, null, Color.RED, 2.0f, Cap.ROUND, false, 1, 0, 0, 0, 0, 0, true, null, true, null, LineStyle.REPEAT_START_DEFAULT, LineStyle.REPEAT_GAP_DEFAULT, false); LineBucket ol = l.buckets.addLineBucket(0, outline); LineBucket ol2 = l.buckets.addLineBucket(5, outline2); diff --git a/vtm/src/org/oscim/renderer/bucket/LineBucket.java b/vtm/src/org/oscim/renderer/bucket/LineBucket.java index 3f017eca8..ad458578f 100644 --- a/vtm/src/org/oscim/renderer/bucket/LineBucket.java +++ b/vtm/src/org/oscim/renderer/bucket/LineBucket.java @@ -28,7 +28,6 @@ import org.oscim.renderer.GLUtils; import org.oscim.renderer.GLViewport; import org.oscim.theme.styles.LineStyle; -import org.oscim.utils.Parameters; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -665,7 +664,7 @@ public static RenderBucket draw(RenderBucket b, GLViewport v, blur = false; } - if (Parameters.TRANSPARENT_LINES && !Color.isOpaque(line.color)) { + if (line.transparent && !Color.isOpaque(line.color)) { gl.depthMask(true); gl.clear(GL.DEPTH_BUFFER_BIT); GLState.test(true, false); @@ -712,7 +711,7 @@ public static RenderBucket draw(RenderBucket b, GLViewport v, gl.drawArrays(GL.TRIANGLE_STRIP, b.vertexOffset, b.numVertices); - if (Parameters.TRANSPARENT_LINES && !Color.isOpaque(line.color)) { + if (line.transparent && !Color.isOpaque(line.color)) { gl.depthMask(false); } @@ -763,7 +762,7 @@ public static RenderBucket draw(RenderBucket b, GLViewport v, ref.vertexOffset, ref.numVertices); } - if (Parameters.TRANSPARENT_LINES && !Color.isOpaque(line.color)) { + if (line.transparent && !Color.isOpaque(line.color)) { gl.depthMask(false); } } diff --git a/vtm/src/org/oscim/theme/styles/LineStyle.java b/vtm/src/org/oscim/theme/styles/LineStyle.java index fb0fc3eb6..40de259af 100644 --- a/vtm/src/org/oscim/theme/styles/LineStyle.java +++ b/vtm/src/org/oscim/theme/styles/LineStyle.java @@ -58,23 +58,26 @@ public final class LineStyle extends RenderStyle { public final float repeatStart; public final float repeatGap; + public final boolean transparent; + public LineStyle(int color, float width) { - this(0, "", color, width, Cap.BUTT, true, 1, 0, 0, 0, -1, 0, false, null, true, null, REPEAT_START_DEFAULT * CanvasAdapter.getScale(), REPEAT_GAP_DEFAULT * CanvasAdapter.getScale()); + this(0, "", color, width, Cap.BUTT, true, 1, 0, 0, 0, -1, 0, false, null, true, null, REPEAT_START_DEFAULT * CanvasAdapter.getScale(), REPEAT_GAP_DEFAULT * CanvasAdapter.getScale(), false); } public LineStyle(int level, int color, float width) { - this(level, "", color, width, Cap.BUTT, true, 1, 0, 0, 0, -1, 0, false, null, true, null, REPEAT_START_DEFAULT * CanvasAdapter.getScale(), REPEAT_GAP_DEFAULT * CanvasAdapter.getScale()); + this(level, "", color, width, Cap.BUTT, true, 1, 0, 0, 0, -1, 0, false, null, true, null, REPEAT_START_DEFAULT * CanvasAdapter.getScale(), REPEAT_GAP_DEFAULT * CanvasAdapter.getScale(), false); } public LineStyle(int color, float width, Cap cap) { - this(0, "", color, width, cap, true, 1, 0, 0, 0, -1, 0, false, null, true, null, REPEAT_START_DEFAULT * CanvasAdapter.getScale(), REPEAT_GAP_DEFAULT * CanvasAdapter.getScale()); + this(0, "", color, width, cap, true, 1, 0, 0, 0, -1, 0, false, null, true, null, REPEAT_START_DEFAULT * CanvasAdapter.getScale(), REPEAT_GAP_DEFAULT * CanvasAdapter.getScale(), false); } public LineStyle(int level, String style, int color, float width, Cap cap, boolean fixed, double strokeIncrease, int stipple, int stippleColor, float stippleWidth, int fadeScale, float blur, boolean isOutline, TextureItem texture, - boolean randomOffset, float[] dashArray, float repeatStart, float repeatGap) { + boolean randomOffset, float[] dashArray, float repeatStart, float repeatGap, + boolean transparent) { this.level = level; this.style = style; @@ -104,6 +107,8 @@ public LineStyle(int level, String style, int color, float width, this.dashArray = dashArray; this.repeatStart = repeatStart; this.repeatGap = repeatGap; + + this.transparent = transparent; } private LineStyle(LineBuilder b) { @@ -133,6 +138,8 @@ private LineStyle(LineBuilder b) { this.dashArray = b.dashArray; this.repeatStart = b.repeatStart; this.repeatGap = b.repeatGap; + + this.transparent = b.transparent; } @Override @@ -170,6 +177,8 @@ public static class LineBuilder> extends StyleBuilder