Skip to content

Commit

Permalink
Line style transparent option (#1100)
Browse files Browse the repository at this point in the history
  • Loading branch information
devemux86 authored Feb 11, 2024
1 parent af8b583 commit b3ff48f
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 18 deletions.
1 change: 1 addition & 0 deletions docs/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions vtm-jts/src/org/oscim/layers/vector/VectorLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions vtm-jts/src/org/oscim/layers/vector/geometries/Style.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -84,6 +85,7 @@ private Style(Builder builder) {

heightOffset = builder.heightOffset;
randomOffset = builder.randomOffset;
transparent = builder.transparent;
}

/**
Expand Down Expand Up @@ -121,6 +123,7 @@ public static class Builder {

public float heightOffset = 0;
public boolean randomOffset = true;
public boolean transparent = false;

protected Builder() {
}
Expand Down Expand Up @@ -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()
Expand Down
10 changes: 5 additions & 5 deletions vtm-playground/src/org/oscim/test/LineRenderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
7 changes: 3 additions & 4 deletions vtm/src/org/oscim/renderer/bucket/LineBucket.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}
}
Expand Down
26 changes: 22 additions & 4 deletions vtm/src/org/oscim/theme/styles/LineStyle.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,26 @@ public final class LineStyle extends RenderStyle<LineStyle> {
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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -170,6 +177,8 @@ public static class LineBuilder<T extends LineBuilder<T>> extends StyleBuilder<T
public float repeatStart;
public float repeatGap;

public boolean transparent;

public LineBuilder() {
}

Expand Down Expand Up @@ -204,6 +213,8 @@ public T set(LineStyle line) {
this.repeatStart = line.repeatStart;
this.repeatGap = line.repeatGap;

this.transparent = line.transparent;

return self();
}

Expand Down Expand Up @@ -302,6 +313,11 @@ public T repeatGap(float repeatGap) {
return self();
}

public T transparent(boolean transparent) {
this.transparent = transparent;
return self();
}

public T reset() {
cat = null;
level = -1;
Expand Down Expand Up @@ -332,6 +348,8 @@ public T reset() {
repeatStart = REPEAT_START_DEFAULT * CanvasAdapter.getScale();
repeatGap = REPEAT_GAP_DEFAULT * CanvasAdapter.getScale();

transparent = false;

return self();
}

Expand Down
5 changes: 0 additions & 5 deletions vtm/src/org/oscim/utils/Parameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,6 @@ public enum SymbolScaling {ALL, POI}
*/
public static boolean TEXTURE_ATLAS = false;

/**
* Transparent line layers.
*/
public static boolean TRANSPARENT_LINES = false;

/**
* Threaded system initialization.
*/
Expand Down

0 comments on commit b3ff48f

Please sign in to comment.