Line texture: randomize offset rendering, #105
This commit is contained in:
@@ -65,6 +65,7 @@ public class LineTexActivity extends BitmapTileMapActivity {
|
|||||||
.strokeColor(c)
|
.strokeColor(c)
|
||||||
.fixed(true)
|
.fixed(true)
|
||||||
.texture(tex)
|
.texture(tex)
|
||||||
|
.randomOffset(false)
|
||||||
.build();
|
.build();
|
||||||
PathLayer pathLayer = new PathLayer(mMap, style);
|
PathLayer pathLayer = new PathLayer(mMap, style);
|
||||||
mMap.layers().add(pathLayer);
|
mMap.layers().add(pathLayer);
|
||||||
|
|||||||
@@ -264,6 +264,7 @@ public class VectorLayer extends AbstractVectorLayer<Drawable> {
|
|||||||
.color(style.strokeColor)
|
.color(style.strokeColor)
|
||||||
.fixed(style.fixed)
|
.fixed(style.fixed)
|
||||||
.level(0)
|
.level(0)
|
||||||
|
.randomOffset(style.randomOffset)
|
||||||
.stipple(style.stipple)
|
.stipple(style.stipple)
|
||||||
.stippleColor(style.stippleColor)
|
.stippleColor(style.stippleColor)
|
||||||
.stippleWidth(style.stippleWidth)
|
.stippleWidth(style.stippleWidth)
|
||||||
|
|||||||
@@ -50,6 +50,8 @@ public class Style {
|
|||||||
public final float stippleWidth;
|
public final float stippleWidth;
|
||||||
public final TextureItem texture;
|
public final TextureItem texture;
|
||||||
|
|
||||||
|
public final boolean randomOffset;
|
||||||
|
|
||||||
private Style(Builder builder) {
|
private Style(Builder builder) {
|
||||||
strokeWidth = builder.strokeWidth;
|
strokeWidth = builder.strokeWidth;
|
||||||
strokeColor = builder.strokeColor;
|
strokeColor = builder.strokeColor;
|
||||||
@@ -68,6 +70,8 @@ public class Style {
|
|||||||
stippleColor = builder.stippleColor;
|
stippleColor = builder.stippleColor;
|
||||||
stippleWidth = builder.stippleWidth;
|
stippleWidth = builder.stippleWidth;
|
||||||
texture = builder.texture;
|
texture = builder.texture;
|
||||||
|
|
||||||
|
randomOffset = builder.randomOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -99,6 +103,8 @@ public class Style {
|
|||||||
public float stippleWidth = 1;
|
public float stippleWidth = 1;
|
||||||
public TextureItem texture = null;
|
public TextureItem texture = null;
|
||||||
|
|
||||||
|
public boolean randomOffset = true;
|
||||||
|
|
||||||
protected Builder() {
|
protected Builder() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -221,6 +227,11 @@ public class Style {
|
|||||||
this.texture = texture;
|
this.texture = texture;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Builder randomOffset(boolean randomOffset) {
|
||||||
|
this.randomOffset = randomOffset;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static final Style DEFAULT_STYLE = new Builder()
|
static final Style DEFAULT_STYLE = new Builder()
|
||||||
|
|||||||
@@ -72,9 +72,9 @@ public class LineRenderTest extends GdxMap {
|
|||||||
line2 = new LineStyle(Color.GREEN, 1);
|
line2 = new LineStyle(Color.GREEN, 1);
|
||||||
line4 = new LineStyle(Color.LTGRAY, 3);
|
line4 = new LineStyle(Color.LTGRAY, 3);
|
||||||
} else {
|
} else {
|
||||||
line1 = new LineStyle(0, null, Color.fade(Color.RED, 0.5f), 4.0f, Cap.BUTT, 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);
|
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);
|
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"));
|
TextureItem tex = new TextureItem(CanvasAdapter.getBitmapAsset("", "patterns/dot.png"));
|
||||||
@@ -87,10 +87,11 @@ public class LineRenderTest extends GdxMap {
|
|||||||
.strokeColor(Color.BLUE)
|
.strokeColor(Color.BLUE)
|
||||||
.fixed(fixed)
|
.fixed(fixed)
|
||||||
.texture(tex)
|
.texture(tex)
|
||||||
|
.randomOffset(true)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
LineStyle outline = new LineStyle(0, null, Color.BLUE, 2.0f, Cap.ROUND, false, 0, 0, 0, 0, 1f, 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);
|
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 ol = l.buckets.addLineBucket(0, outline);
|
||||||
LineBucket ol2 = l.buckets.addLineBucket(5, outline2);
|
LineBucket ol2 = l.buckets.addLineBucket(5, outline2);
|
||||||
|
|||||||
@@ -104,6 +104,7 @@ public class LineTexTest extends GdxMapApp {
|
|||||||
.strokeColor(c)
|
.strokeColor(c)
|
||||||
.fixed(true)
|
.fixed(true)
|
||||||
.texture(tex)
|
.texture(tex)
|
||||||
|
.randomOffset(false)
|
||||||
.build();
|
.build();
|
||||||
pathLayer = new PathLayer(mMap, style);
|
pathLayer = new PathLayer(mMap, style);
|
||||||
mMap.layers().add(pathLayer);
|
mMap.layers().add(pathLayer);
|
||||||
|
|||||||
@@ -92,8 +92,6 @@ public final class LineTexBucket extends LineBucket {
|
|||||||
|
|
||||||
private boolean evenSegment = true;
|
private boolean evenSegment = true;
|
||||||
|
|
||||||
protected boolean mRandomizeOffset = true;
|
|
||||||
|
|
||||||
LineTexBucket(int level) {
|
LineTexBucket(int level) {
|
||||||
super(TEXLINE, false, true);
|
super(TEXLINE, false, true);
|
||||||
|
|
||||||
@@ -148,7 +146,7 @@ public final class LineTexBucket extends LineBucket {
|
|||||||
float y = points[pos++] * COORD_SCALE;
|
float y = points[pos++] * COORD_SCALE;
|
||||||
|
|
||||||
/* randomize a bit */
|
/* 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) {
|
while (pos < end) {
|
||||||
float nx = points[pos++] * COORD_SCALE;
|
float nx = points[pos++] * COORD_SCALE;
|
||||||
|
|||||||
@@ -41,6 +41,8 @@ public final class LineStyle extends RenderStyle {
|
|||||||
public final float stippleWidth;
|
public final float stippleWidth;
|
||||||
public final TextureItem texture;
|
public final TextureItem texture;
|
||||||
|
|
||||||
|
public final boolean randomOffset;
|
||||||
|
|
||||||
private LineStyle(LineBuilder<?> builder) {
|
private LineStyle(LineBuilder<?> builder) {
|
||||||
this.level = builder.level;
|
this.level = builder.level;
|
||||||
this.style = builder.style;
|
this.style = builder.style;
|
||||||
@@ -55,12 +57,14 @@ public final class LineStyle extends RenderStyle {
|
|||||||
this.stippleColor = builder.stippleColor;
|
this.stippleColor = builder.stippleColor;
|
||||||
this.stippleWidth = builder.stippleWidth;
|
this.stippleWidth = builder.stippleWidth;
|
||||||
this.texture = builder.texture;
|
this.texture = builder.texture;
|
||||||
|
this.randomOffset = builder.randomOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LineStyle(int level, String style, int color, float width,
|
public LineStyle(int level, String style, int color, float width,
|
||||||
Cap cap, boolean fixed,
|
Cap cap, boolean fixed,
|
||||||
int stipple, int stippleColor, float stippleWidth,
|
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.level = level;
|
||||||
this.style = style;
|
this.style = style;
|
||||||
@@ -78,18 +82,20 @@ public final class LineStyle extends RenderStyle {
|
|||||||
|
|
||||||
this.blur = blur;
|
this.blur = blur;
|
||||||
this.fadeScale = fadeScale;
|
this.fadeScale = fadeScale;
|
||||||
|
|
||||||
|
this.randomOffset = randomOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LineStyle(int stroke, float width) {
|
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) {
|
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) {
|
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
|
@Override
|
||||||
@@ -116,6 +122,8 @@ public final class LineStyle extends RenderStyle {
|
|||||||
public float stippleWidth;
|
public float stippleWidth;
|
||||||
public TextureItem texture;
|
public TextureItem texture;
|
||||||
|
|
||||||
|
public boolean randomOffset;
|
||||||
|
|
||||||
public T set(LineStyle line) {
|
public T set(LineStyle line) {
|
||||||
if (line == null)
|
if (line == null)
|
||||||
return reset();
|
return reset();
|
||||||
@@ -132,6 +140,7 @@ public final class LineStyle extends RenderStyle {
|
|||||||
this.stippleColor = line.stippleColor;
|
this.stippleColor = line.stippleColor;
|
||||||
this.stippleWidth = line.stippleWidth;
|
this.stippleWidth = line.stippleWidth;
|
||||||
this.texture = line.texture;
|
this.texture = line.texture;
|
||||||
|
this.randomOffset = line.randomOffset;
|
||||||
return self();
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,6 +160,8 @@ public final class LineStyle extends RenderStyle {
|
|||||||
stippleColor = Color.BLACK;
|
stippleColor = Color.BLACK;
|
||||||
texture = null;
|
texture = null;
|
||||||
|
|
||||||
|
randomOffset = true;
|
||||||
|
|
||||||
return self();
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,6 +223,11 @@ public final class LineStyle extends RenderStyle {
|
|||||||
this.texture = texture;
|
this.texture = texture;
|
||||||
return self();
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public T randomOffset(boolean randomOffset) {
|
||||||
|
this.randomOffset = randomOffset;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
|
|||||||
Reference in New Issue
Block a user