From 25f0310334e06e48d4f30adc7135e711c52ea2bd Mon Sep 17 00:00:00 2001 From: Emux Date: Sat, 24 Jun 2017 20:05:34 +0300 Subject: [PATCH] Height offset in render styles, close #368 --- .../org/oscim/layers/vector/PathLayer.java | 3 +- .../org/oscim/layers/vector/VectorLayer.java | 32 +++++++++---------- .../oscim/layers/vector/geometries/Style.java | 11 ++++++- .../org/oscim/renderer/bucket/LineBucket.java | 4 ++- .../org/oscim/renderer/bucket/MeshBucket.java | 6 +++- vtm/src/org/oscim/theme/styles/AreaStyle.java | 19 ++++++++++- vtm/src/org/oscim/theme/styles/LineStyle.java | 16 +++++++++- 7 files changed, 69 insertions(+), 22 deletions(-) diff --git a/vtm-jts/src/org/oscim/layers/vector/PathLayer.java b/vtm-jts/src/org/oscim/layers/vector/PathLayer.java index 9653732a..0b00e049 100644 --- a/vtm-jts/src/org/oscim/layers/vector/PathLayer.java +++ b/vtm-jts/src/org/oscim/layers/vector/PathLayer.java @@ -1,7 +1,7 @@ /* * Copyright 2012 osmdroid authors: Viesturs Zarins, Martin Pearman * Copyright 2012 Hannes Janetzek - * Copyright 2016 devemux86 + * Copyright 2016-2017 devemux86 * Copyright 2016 Pedinel * * This file is part of the OpenScienceMap project (http://www.opensciencemap.org). @@ -50,6 +50,7 @@ public class PathLayer extends VectorLayer { public PathLayer(Map map, int lineColor, float lineWidth) { this(map, Style.builder() + .fixed(true) .strokeColor(lineColor) .strokeWidth(lineWidth) .build()); diff --git a/vtm-jts/src/org/oscim/layers/vector/VectorLayer.java b/vtm-jts/src/org/oscim/layers/vector/VectorLayer.java index b4fa66d1..8f99a963 100644 --- a/vtm-jts/src/org/oscim/layers/vector/VectorLayer.java +++ b/vtm-jts/src/org/oscim/layers/vector/VectorLayer.java @@ -1,5 +1,6 @@ /* - * Copyright 2016 devemux86 + * Copyright 2014 Hannes Janetzek + * Copyright 2016-2017 devemux86 * * This file is part of the OpenScienceMap project (http://www.opensciencemap.org). * @@ -256,21 +257,20 @@ public class VectorLayer extends AbstractVectorLayer { else ll = t.buckets.getLineTexBucket(level); if (ll.line == null) { - if (style.stipple == 0 && style.texture == null) - ll.line = new LineStyle(style.strokeColor, style.strokeWidth, style.cap); - else - ll.line = LineStyle.builder() - .cap(style.cap) - .color(style.strokeColor) - .fixed(style.fixed) - .level(0) - .randomOffset(style.randomOffset) - .stipple(style.stipple) - .stippleColor(style.stippleColor) - .stippleWidth(style.stippleWidth) - .strokeWidth(style.strokeWidth) - .texture(style.texture) - .build(); + ll.line = LineStyle.builder() + .reset() + .cap(style.cap) + .color(style.strokeColor) + .fixed(style.fixed) + .heightOffset(style.heightOffset) + .level(0) + .randomOffset(style.randomOffset) + .stipple(style.stipple) + .stippleColor(style.stippleColor) + .stippleWidth(style.stippleWidth) + .strokeWidth(style.strokeWidth) + .texture(style.texture) + .build(); } if (style.generalization != Style.GENERALIZATION_NONE) { 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 6760f282..7f07fc7c 100644 --- a/vtm-jts/src/org/oscim/layers/vector/geometries/Style.java +++ b/vtm-jts/src/org/oscim/layers/vector/geometries/Style.java @@ -1,5 +1,6 @@ /* - * Copyright 2016 devemux86 + * Copyright 2014 Hannes Janetzek + * Copyright 2016-2017 devemux86 * * This file is part of the OpenScienceMap project (http://www.opensciencemap.org). * @@ -50,6 +51,7 @@ public class Style { public final float stippleWidth; public final TextureItem texture; + public final float heightOffset; public final boolean randomOffset; private Style(Builder builder) { @@ -71,6 +73,7 @@ public class Style { stippleWidth = builder.stippleWidth; texture = builder.texture; + heightOffset = builder.heightOffset; randomOffset = builder.randomOffset; } @@ -103,6 +106,7 @@ public class Style { public float stippleWidth = 1; public TextureItem texture = null; + public float heightOffset = 0; public boolean randomOffset = true; protected Builder() { @@ -228,6 +232,11 @@ public class Style { return this; } + public Builder heightOffset(float heightOffset) { + this.heightOffset = heightOffset; + return this; + } + public Builder randomOffset(boolean randomOffset) { this.randomOffset = randomOffset; return this; diff --git a/vtm/src/org/oscim/renderer/bucket/LineBucket.java b/vtm/src/org/oscim/renderer/bucket/LineBucket.java index 6e0c0b2f..70f4f3a3 100644 --- a/vtm/src/org/oscim/renderer/bucket/LineBucket.java +++ b/vtm/src/org/oscim/renderer/bucket/LineBucket.java @@ -1,6 +1,6 @@ /* * Copyright 2013 Hannes Janetzek - * Copyright 2016 devemux86 + * Copyright 2016-2017 devemux86 * * This file is part of the OpenScienceMap project (http://www.opensciencemap.org). * @@ -633,6 +633,8 @@ public class LineBucket extends RenderBucket { LineBucket lb = (LineBucket) b; LineStyle line = lb.line.current(); + if (line.heightOffset != lb.heightOffset) + lb.heightOffset = line.heightOffset; if (lb.heightOffset != heightOffset) { heightOffset = lb.heightOffset; diff --git a/vtm/src/org/oscim/renderer/bucket/MeshBucket.java b/vtm/src/org/oscim/renderer/bucket/MeshBucket.java index 4e657492..b15e9951 100644 --- a/vtm/src/org/oscim/renderer/bucket/MeshBucket.java +++ b/vtm/src/org/oscim/renderer/bucket/MeshBucket.java @@ -1,5 +1,6 @@ /* * Copyright 2013 Hannes Janetzek + * Copyright 2017 devemux86 * * This file is part of the OpenScienceMap project (http://www.opensciencemap.org). * @@ -182,7 +183,10 @@ public class MeshBucket extends RenderBucket { for (; l != null && l.type == MESH; l = l.next) { MeshBucket ml = (MeshBucket) l; + AreaStyle area = ml.area.current(); + if (area.heightOffset != ml.heightOffset) + ml.heightOffset = area.heightOffset; if (ml.heightOffset != heightOffset) { heightOffset = ml.heightOffset; @@ -193,7 +197,7 @@ public class MeshBucket extends RenderBucket { if (ml.area == null) GLUtils.setColor(s.uColor, Color.BLUE, 0.4f); else { - setColor(ml.area.current(), s, v.pos); + setColor(area, s, v.pos); } gl.vertexAttribPointer(s.aPos, 2, GL.SHORT, false, 0, ml.vertexOffset); diff --git a/vtm/src/org/oscim/theme/styles/AreaStyle.java b/vtm/src/org/oscim/theme/styles/AreaStyle.java index efb37032..ae57209c 100644 --- a/vtm/src/org/oscim/theme/styles/AreaStyle.java +++ b/vtm/src/org/oscim/theme/styles/AreaStyle.java @@ -1,7 +1,7 @@ /* * Copyright 2010, 2011, 2012 mapsforge.org * Copyright 2014 Hannes Janetzek - * Copyright 2016 devemux86 + * Copyright 2016-2017 devemux86 * * This file is part of the OpenScienceMap project (http://www.opensciencemap.org). * @@ -78,6 +78,8 @@ public class AreaStyle extends RenderStyle { */ public final boolean mesh; + public final float heightOffset; + public final int symbolWidth; public final int symbolHeight; public final int symbolPercent; @@ -98,6 +100,8 @@ public class AreaStyle extends RenderStyle { this.strokeWidth = 1; this.mesh = false; + this.heightOffset = 0; + this.symbolWidth = 0; this.symbolHeight = 0; this.symbolPercent = 100; @@ -115,6 +119,8 @@ public class AreaStyle extends RenderStyle { this.strokeWidth = b.strokeWidth; this.mesh = b.mesh; + this.heightOffset = b.heightOffset; + this.symbolWidth = b.symbolWidth; this.symbolHeight = b.symbolHeight; this.symbolPercent = b.symbolPercent; @@ -176,6 +182,8 @@ public class AreaStyle extends RenderStyle { public TextureItem texture; + public float heightOffset; + public int symbolWidth; public int symbolHeight; public int symbolPercent; @@ -198,6 +206,8 @@ public class AreaStyle extends RenderStyle { this.strokeWidth = area.strokeWidth; this.mesh = area.mesh; + this.heightOffset = area.heightOffset; + this.symbolWidth = area.symbolWidth; this.symbolHeight = area.symbolHeight; this.symbolPercent = area.symbolPercent; @@ -235,6 +245,11 @@ public class AreaStyle extends RenderStyle { return self(); } + public T heightOffset(float heightOffset) { + this.heightOffset = heightOffset; + return self(); + } + public T symbolWidth(int symbolWidth) { this.symbolWidth = symbolWidth; return self(); @@ -262,6 +277,8 @@ public class AreaStyle extends RenderStyle { texture = null; mesh = false; + heightOffset = 0; + symbolWidth = 0; symbolHeight = 0; symbolPercent = 100; diff --git a/vtm/src/org/oscim/theme/styles/LineStyle.java b/vtm/src/org/oscim/theme/styles/LineStyle.java index 7edbff4a..da65cfc5 100644 --- a/vtm/src/org/oscim/theme/styles/LineStyle.java +++ b/vtm/src/org/oscim/theme/styles/LineStyle.java @@ -1,7 +1,7 @@ /* * Copyright 2010, 2011, 2012 mapsforge.org * Copyright 2013 Hannes Janetzek - * Copyright 2016 devemux86 + * Copyright 2016-2017 devemux86 * * This file is part of the OpenScienceMap project (http://www.opensciencemap.org). * @@ -41,6 +41,7 @@ public final class LineStyle extends RenderStyle { public final float stippleWidth; public final TextureItem texture; + public final float heightOffset; public final boolean randomOffset; public final int symbolWidth; @@ -82,6 +83,7 @@ public final class LineStyle extends RenderStyle { this.blur = blur; this.fadeScale = fadeScale; + this.heightOffset = 0; this.randomOffset = randomOffset; this.symbolWidth = 0; @@ -103,6 +105,8 @@ public final class LineStyle extends RenderStyle { this.stippleColor = b.themeCallback != null ? b.themeCallback.getColor(b.stippleColor) : b.stippleColor; this.stippleWidth = b.stippleWidth; this.texture = b.texture; + + this.heightOffset = b.heightOffset; this.randomOffset = b.randomOffset; this.symbolWidth = b.symbolWidth; @@ -133,6 +137,7 @@ public final class LineStyle extends RenderStyle { public float stippleWidth; public TextureItem texture; + public float heightOffset; public boolean randomOffset; public int symbolWidth; @@ -159,6 +164,8 @@ public final class LineStyle extends RenderStyle { this.stippleColor = themeCallback != null ? themeCallback.getColor(line.stippleColor) : line.stippleColor; this.stippleWidth = line.stippleWidth; this.texture = line.texture; + + this.heightOffset = line.heightOffset; this.randomOffset = line.randomOffset; this.symbolWidth = line.symbolWidth; @@ -218,6 +225,11 @@ public final class LineStyle extends RenderStyle { return self(); } + public T heightOffset(float heightOffset) { + this.heightOffset = heightOffset; + return self(); + } + public T randomOffset(boolean randomOffset) { this.randomOffset = randomOffset; return self(); @@ -243,6 +255,7 @@ public final class LineStyle extends RenderStyle { style = null; fillColor = Color.BLACK; cap = Cap.ROUND; + outline = false; strokeWidth = 1; fixed = false; @@ -254,6 +267,7 @@ public final class LineStyle extends RenderStyle { stippleColor = Color.BLACK; texture = null; + heightOffset = 0; randomOffset = true; symbolWidth = 0;