From 14108fcfe7fee6dc8a501cc89dd74ecec8d3222d Mon Sep 17 00:00:00 2001 From: Emux Date: Fri, 5 Aug 2016 13:26:43 +0300 Subject: [PATCH] Line texture: randomize offset rendering, #105 --- .../oscim/android/test/LineTexActivity.java | 1 + .../org/oscim/layers/vector/VectorLayer.java | 1 + .../oscim/layers/vector/geometries/Style.java | 11 +++++++++ .../src/org/oscim/test/LineRenderTest.java | 11 +++++---- .../src/org/oscim/test/LineTexTest.java | 1 + .../oscim/renderer/bucket/LineTexBucket.java | 4 +--- vtm/src/org/oscim/theme/styles/LineStyle.java | 24 +++++++++++++++---- 7 files changed, 41 insertions(+), 12 deletions(-) diff --git a/vtm-android-example/src/org/oscim/android/test/LineTexActivity.java b/vtm-android-example/src/org/oscim/android/test/LineTexActivity.java index 962ae6b1..672940f4 100644 --- a/vtm-android-example/src/org/oscim/android/test/LineTexActivity.java +++ b/vtm-android-example/src/org/oscim/android/test/LineTexActivity.java @@ -65,6 +65,7 @@ public class LineTexActivity extends BitmapTileMapActivity { .strokeColor(c) .fixed(true) .texture(tex) + .randomOffset(false) .build(); PathLayer pathLayer = new PathLayer(mMap, style); mMap.layers().add(pathLayer); diff --git a/vtm-jts/src/org/oscim/layers/vector/VectorLayer.java b/vtm-jts/src/org/oscim/layers/vector/VectorLayer.java index b3d7eb65..b4fa66d1 100644 --- a/vtm-jts/src/org/oscim/layers/vector/VectorLayer.java +++ b/vtm-jts/src/org/oscim/layers/vector/VectorLayer.java @@ -264,6 +264,7 @@ public class VectorLayer extends AbstractVectorLayer { .color(style.strokeColor) .fixed(style.fixed) .level(0) + .randomOffset(style.randomOffset) .stipple(style.stipple) .stippleColor(style.stippleColor) .stippleWidth(style.stippleWidth) 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 b0a41b4e..6760f282 100644 --- a/vtm-jts/src/org/oscim/layers/vector/geometries/Style.java +++ b/vtm-jts/src/org/oscim/layers/vector/geometries/Style.java @@ -50,6 +50,8 @@ public class Style { public final float stippleWidth; public final TextureItem texture; + public final boolean randomOffset; + private Style(Builder builder) { strokeWidth = builder.strokeWidth; strokeColor = builder.strokeColor; @@ -68,6 +70,8 @@ public class Style { stippleColor = builder.stippleColor; stippleWidth = builder.stippleWidth; texture = builder.texture; + + randomOffset = builder.randomOffset; } /** @@ -99,6 +103,8 @@ public class Style { public float stippleWidth = 1; public TextureItem texture = null; + public boolean randomOffset = true; + protected Builder() { } @@ -221,6 +227,11 @@ public class Style { this.texture = texture; return this; } + + public Builder randomOffset(boolean randomOffset) { + this.randomOffset = randomOffset; + 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 d2e4d248..317fa03e 100644 --- a/vtm-playground/src/org/oscim/test/LineRenderTest.java +++ b/vtm-playground/src/org/oscim/test/LineRenderTest.java @@ -72,9 +72,9 @@ public class LineRenderTest extends GdxMap { 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, 0, 0, 0, 0, 1f, false, null); - line2 = new LineStyle(0, null, Color.GREEN, 6.0f, Cap.BUTT, false, 0, 0, 0, 0, 1f, false, null); - line4 = new LineStyle(0, null, Color.LTGRAY, 2.0f, Cap.ROUND, false, 0, 0, 0, 0, 1f, false, null); + line1 = new LineStyle(0, null, Color.fade(Color.RED, 0.5f), 4.0f, Cap.BUTT, false, 0, 0, 0, 0, 1f, false, null, true); + line2 = new LineStyle(0, null, Color.GREEN, 6.0f, Cap.BUTT, false, 0, 0, 0, 0, 1f, false, null, true); + line4 = new LineStyle(0, null, Color.LTGRAY, 2.0f, Cap.ROUND, false, 0, 0, 0, 0, 1f, false, null, true); } TextureItem tex = new TextureItem(CanvasAdapter.getBitmapAsset("", "patterns/dot.png")); @@ -87,10 +87,11 @@ public class LineRenderTest extends GdxMap { .strokeColor(Color.BLUE) .fixed(fixed) .texture(tex) + .randomOffset(true) .build(); - LineStyle outline = new LineStyle(0, null, Color.BLUE, 2.0f, Cap.ROUND, false, 0, 0, 0, 0, 1f, true, null); - LineStyle outline2 = new LineStyle(0, null, Color.RED, 2.0f, Cap.ROUND, false, 0, 0, 0, 0, 0, true, null); + LineStyle outline = new LineStyle(0, null, Color.BLUE, 2.0f, Cap.ROUND, false, 0, 0, 0, 0, 1f, true, null, true); + LineStyle outline2 = new LineStyle(0, null, Color.RED, 2.0f, Cap.ROUND, false, 0, 0, 0, 0, 0, true, null, true); LineBucket ol = l.buckets.addLineBucket(0, outline); LineBucket ol2 = l.buckets.addLineBucket(5, outline2); diff --git a/vtm-playground/src/org/oscim/test/LineTexTest.java b/vtm-playground/src/org/oscim/test/LineTexTest.java index be1e341a..79de2123 100644 --- a/vtm-playground/src/org/oscim/test/LineTexTest.java +++ b/vtm-playground/src/org/oscim/test/LineTexTest.java @@ -104,6 +104,7 @@ public class LineTexTest extends GdxMapApp { .strokeColor(c) .fixed(true) .texture(tex) + .randomOffset(false) .build(); pathLayer = new PathLayer(mMap, style); mMap.layers().add(pathLayer); diff --git a/vtm/src/org/oscim/renderer/bucket/LineTexBucket.java b/vtm/src/org/oscim/renderer/bucket/LineTexBucket.java index 998ee985..f6fc7705 100644 --- a/vtm/src/org/oscim/renderer/bucket/LineTexBucket.java +++ b/vtm/src/org/oscim/renderer/bucket/LineTexBucket.java @@ -92,8 +92,6 @@ public final class LineTexBucket extends LineBucket { private boolean evenSegment = true; - protected boolean mRandomizeOffset = true; - LineTexBucket(int level) { super(TEXLINE, false, true); @@ -148,7 +146,7 @@ public final class LineTexBucket extends LineBucket { float y = points[pos++] * COORD_SCALE; /* randomize a bit */ - float lineLength = mRandomizeOffset ? (x * x + y * y) % 80 : 0; + float lineLength = line.randomOffset ? (x * x + y * y) % 80 : 0; while (pos < end) { float nx = points[pos++] * COORD_SCALE; diff --git a/vtm/src/org/oscim/theme/styles/LineStyle.java b/vtm/src/org/oscim/theme/styles/LineStyle.java index 8c664d17..cbb1d62e 100644 --- a/vtm/src/org/oscim/theme/styles/LineStyle.java +++ b/vtm/src/org/oscim/theme/styles/LineStyle.java @@ -41,6 +41,8 @@ public final class LineStyle extends RenderStyle { public final float stippleWidth; public final TextureItem texture; + public final boolean randomOffset; + private LineStyle(LineBuilder builder) { this.level = builder.level; this.style = builder.style; @@ -55,12 +57,14 @@ public final class LineStyle extends RenderStyle { this.stippleColor = builder.stippleColor; this.stippleWidth = builder.stippleWidth; this.texture = builder.texture; + this.randomOffset = builder.randomOffset; } public LineStyle(int level, String style, int color, float width, Cap cap, boolean fixed, int stipple, int stippleColor, float stippleWidth, - int fadeScale, float blur, boolean isOutline, TextureItem texture) { + int fadeScale, float blur, boolean isOutline, TextureItem texture, + boolean randomOffset) { this.level = level; this.style = style; @@ -78,18 +82,20 @@ public final class LineStyle extends RenderStyle { this.blur = blur; this.fadeScale = fadeScale; + + this.randomOffset = randomOffset; } public LineStyle(int stroke, float width) { - this(0, "", stroke, width, Cap.BUTT, true, 0, 0, 0, -1, 0, false, null); + this(0, "", stroke, width, Cap.BUTT, true, 0, 0, 0, -1, 0, false, null, true); } public LineStyle(int level, int stroke, float width) { - this(level, "", stroke, width, Cap.BUTT, true, 0, 0, 0, -1, 0, false, null); + this(level, "", stroke, width, Cap.BUTT, true, 0, 0, 0, -1, 0, false, null, true); } public LineStyle(int stroke, float width, Cap cap) { - this(0, "", stroke, width, cap, true, 0, 0, 0, -1, 0, false, null); + this(0, "", stroke, width, cap, true, 0, 0, 0, -1, 0, false, null, true); } @Override @@ -116,6 +122,8 @@ public final class LineStyle extends RenderStyle { public float stippleWidth; public TextureItem texture; + public boolean randomOffset; + public T set(LineStyle line) { if (line == null) return reset(); @@ -132,6 +140,7 @@ public final class LineStyle extends RenderStyle { this.stippleColor = line.stippleColor; this.stippleWidth = line.stippleWidth; this.texture = line.texture; + this.randomOffset = line.randomOffset; return self(); } @@ -151,6 +160,8 @@ public final class LineStyle extends RenderStyle { stippleColor = Color.BLACK; texture = null; + randomOffset = true; + return self(); } @@ -212,6 +223,11 @@ public final class LineStyle extends RenderStyle { this.texture = texture; return self(); } + + public T randomOffset(boolean randomOffset) { + this.randomOffset = randomOffset; + return self(); + } } @SuppressWarnings("rawtypes")