Line texture: randomize offset rendering, #105

This commit is contained in:
Emux 2016-08-05 13:26:43 +03:00
parent b32b5ceb0b
commit 14108fcfe7
7 changed files with 41 additions and 12 deletions

View File

@ -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);

View File

@ -264,6 +264,7 @@ public class VectorLayer extends AbstractVectorLayer<Drawable> {
.color(style.strokeColor)
.fixed(style.fixed)
.level(0)
.randomOffset(style.randomOffset)
.stipple(style.stipple)
.stippleColor(style.stippleColor)
.stippleWidth(style.stippleWidth)

View File

@ -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()

View File

@ -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);

View File

@ -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);

View File

@ -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;

View File

@ -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")