CircleStyle: add style builder #122
This commit is contained in:
parent
0a5d08a908
commit
229ea0b350
@ -59,7 +59,10 @@ public class CircleTest extends GdxMap {
|
|||||||
|
|
||||||
mMap.setMapPosition(0, 0, 1 << 4);
|
mMap.setMapPosition(0, 0, 1 << 4);
|
||||||
|
|
||||||
CircleStyle cs = new CircleStyle(30, false, 0xff00ff00, 0xffffffff, 2, 0);
|
CircleStyle cs = CircleStyle.builder()
|
||||||
|
.radius(30)
|
||||||
|
.color(0xff00ff00)
|
||||||
|
.build();
|
||||||
CircleBucket cb = renderer.buckets.addCircleBucket(0, cs);
|
CircleBucket cb = renderer.buckets.addCircleBucket(0, cs);
|
||||||
addCircle(200, -200, cb);
|
addCircle(200, -200, cb);
|
||||||
addCircle(-200, -200, cb);
|
addCircle(-200, -200, cb);
|
||||||
|
@ -100,7 +100,7 @@ public class CircleBucket extends RenderBucket {
|
|||||||
for (; b != null && b.type == CIRCLE; b = b.next) {
|
for (; b != null && b.type == CIRCLE; b = b.next) {
|
||||||
CircleBucket cb = (CircleBucket) b;
|
CircleBucket cb = (CircleBucket) b;
|
||||||
|
|
||||||
GLUtils.setColor(s.uColor, cb.circle.fill, 1);
|
GLUtils.setColor(s.uColor, cb.circle.fillColor, 1);
|
||||||
gl.uniform1f(s.uScale, cb.circle.radius);
|
gl.uniform1f(s.uScale, cb.circle.radius);
|
||||||
|
|
||||||
gl.vertexAttribPointer(s.aPos, 2, GL.SHORT,
|
gl.vertexAttribPointer(s.aPos, 2, GL.SHORT,
|
||||||
|
@ -901,7 +901,7 @@ public class XmlThemeBuilder extends DefaultHandler {
|
|||||||
*/
|
*/
|
||||||
private CircleStyle createCircle(String elementName, Attributes attributes, int level) {
|
private CircleStyle createCircle(String elementName, Attributes attributes, int level) {
|
||||||
String cat = null;
|
String cat = null;
|
||||||
Float radius = null;
|
float radius = 0;
|
||||||
boolean scaleRadius = false;
|
boolean scaleRadius = false;
|
||||||
int fill = Color.TRANSPARENT;
|
int fill = Color.TRANSPARENT;
|
||||||
int stroke = Color.TRANSPARENT;
|
int stroke = Color.TRANSPARENT;
|
||||||
|
@ -18,40 +18,97 @@
|
|||||||
*/
|
*/
|
||||||
package org.oscim.theme.styles;
|
package org.oscim.theme.styles;
|
||||||
|
|
||||||
|
import org.oscim.backend.canvas.Color;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a round area on the map.
|
* Represents a round area on the map.
|
||||||
*/
|
*/
|
||||||
public final class CircleStyle extends RenderStyle<CircleStyle> {
|
public final class CircleStyle extends RenderStyle<CircleStyle> {
|
||||||
|
|
||||||
|
public final int fillColor;
|
||||||
public final int level;
|
public final int level;
|
||||||
|
|
||||||
public final int fill;
|
|
||||||
public final int outline;
|
|
||||||
public final float radius;
|
public final float radius;
|
||||||
public final boolean scaleRadius;
|
public final boolean scaleRadius;
|
||||||
|
public final int strokeColor;
|
||||||
public final float strokeWidth;
|
public final float strokeWidth;
|
||||||
|
|
||||||
public CircleStyle(float radius, boolean scaleRadius, int fill, int stroke,
|
public CircleStyle(float radius, boolean scaleRadius, int fillColor, int strokeColor,
|
||||||
float strokeWidth, int level) {
|
float strokeWidth, int level) {
|
||||||
super();
|
|
||||||
|
|
||||||
this.radius = radius;
|
this.radius = radius;
|
||||||
this.scaleRadius = scaleRadius;
|
this.scaleRadius = scaleRadius;
|
||||||
|
this.fillColor = fillColor;
|
||||||
this.fill = fill;
|
this.strokeColor = strokeColor;
|
||||||
this.outline = stroke;
|
|
||||||
|
|
||||||
this.strokeWidth = strokeWidth;
|
this.strokeWidth = strokeWidth;
|
||||||
this.level = level;
|
this.level = level;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CircleStyle(CircleStyle.CircleBuilder<?> b) {
|
||||||
|
this.radius = b.radius;
|
||||||
|
this.scaleRadius = b.scaleRadius;
|
||||||
|
this.fillColor = b.fillColor;
|
||||||
|
this.strokeColor = b.strokeColor;
|
||||||
|
this.strokeWidth = b.strokeWidth;
|
||||||
|
this.level = b.level;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CircleStyle current() {
|
||||||
|
return (CircleStyle) mCurrent;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void renderNode(Callback cb) {
|
public void renderNode(Callback cb) {
|
||||||
cb.renderCircle(this, this.level);
|
cb.renderCircle(this, this.level);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public static class CircleBuilder<T extends CircleStyle.CircleBuilder<T>> extends StyleBuilder<T> {
|
||||||
public CircleStyle current() {
|
|
||||||
return (CircleStyle) mCurrent;
|
public float radius;
|
||||||
|
public boolean scaleRadius;
|
||||||
|
|
||||||
|
public CircleBuilder() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public T set(CircleStyle circle) {
|
||||||
|
if (circle == null)
|
||||||
|
return reset();
|
||||||
|
|
||||||
|
this.radius = circle.radius;
|
||||||
|
this.scaleRadius = circle.scaleRadius;
|
||||||
|
this.fillColor = circle.fillColor;
|
||||||
|
this.strokeColor = circle.strokeColor;
|
||||||
|
this.strokeWidth = circle.strokeWidth;
|
||||||
|
this.level = circle.level;
|
||||||
|
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
public T radius(float radius) {
|
||||||
|
this.radius = radius;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
public T scaleRadius(boolean scaleRadius) {
|
||||||
|
this.scaleRadius = scaleRadius;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
public T reset() {
|
||||||
|
radius = 0;
|
||||||
|
scaleRadius = false;
|
||||||
|
fillColor = Color.TRANSPARENT;
|
||||||
|
strokeColor = Color.TRANSPARENT;
|
||||||
|
strokeWidth = 0;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
public CircleStyle build() {
|
||||||
|
return new CircleStyle(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
|
public static CircleStyle.CircleBuilder<?> builder() {
|
||||||
|
return new CircleStyle.CircleBuilder<>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user