wip: StyleBuilder
This commit is contained in:
parent
1ded32d303
commit
29f19b36ce
@ -49,8 +49,8 @@ public class ThemeStylerActivity extends BaseMapActivity implements OnSeekBarCha
|
||||
}
|
||||
|
||||
class ModStyleVisitor extends RuleVisitor {
|
||||
private final LineBuilder lineBuilder = new LineBuilder();
|
||||
private final AreaBuilder areaBuilder = new AreaBuilder();
|
||||
private final LineBuilder<?> lineBuilder = LineStyle.builder();
|
||||
private final AreaBuilder<?> areaBuilder = AreaStyle.builder();
|
||||
|
||||
@Override
|
||||
public void apply(Rule r) {
|
||||
|
@ -14,3 +14,4 @@ target=android-19
|
||||
|
||||
#proguard.config=proguard.cfg
|
||||
android.library=true
|
||||
android.library.reference.1=../android-v7-appcompat
|
||||
|
@ -18,7 +18,6 @@ import org.oscim.renderer.bucket.TextItem;
|
||||
import org.oscim.theme.styles.AreaStyle;
|
||||
import org.oscim.theme.styles.LineStyle;
|
||||
import org.oscim.theme.styles.TextStyle;
|
||||
import org.oscim.theme.styles.TextStyle.TextBuilder;
|
||||
|
||||
import com.vividsolutions.jts.geom.Envelope;
|
||||
import com.vividsolutions.jts.geom.Geometry;
|
||||
@ -27,9 +26,9 @@ import com.vividsolutions.jts.geom.LineString;
|
||||
public class OSMIndoorLayer extends JeoVectorLayer {
|
||||
|
||||
protected TextBucket mTextLayer;
|
||||
protected TextStyle mText = new TextBuilder()
|
||||
.setFontSize(16).setColor(Color.BLACK)
|
||||
.setStrokeWidth(2.2f).setStroke(Color.WHITE)
|
||||
protected TextStyle mText = TextStyle.builder()
|
||||
.fontSize(16).color(Color.BLACK)
|
||||
.strokeWidth(2.2f).strokeColor(Color.WHITE)
|
||||
.build();
|
||||
|
||||
public OSMIndoorLayer(Map map, VectorDataset data, Style style) {
|
||||
|
@ -229,7 +229,7 @@ public class RenderTheme implements IRenderTheme {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
public void dispose() {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -33,9 +33,9 @@ public class HairLineTest extends GdxMap {
|
||||
|
||||
static class Renderer extends BucketRenderer {
|
||||
boolean init;
|
||||
LineBuilder l = new LineStyle.LineBuilder()
|
||||
LineBuilder<?> l = LineStyle.builder()
|
||||
.color(Color.WHITE)
|
||||
.width(1.5f)
|
||||
.strokeWidth(1.5f)
|
||||
.cap(Cap.ROUND);
|
||||
|
||||
HairLineBucket ll = buckets.addHairLineBucket(1, l.build());
|
||||
@ -48,7 +48,7 @@ public class HairLineTest extends GdxMap {
|
||||
//style = new LineStyle(Color.fade(Color.LTGRAY, 0.8f), 1.5f);
|
||||
LineBucket l2 = buckets.addLineBucket(3, style);
|
||||
|
||||
PolygonBucket pl = buckets.addPolygonBucket(4, new AreaStyle.AreaBuilder()
|
||||
PolygonBucket pl = buckets.addPolygonBucket(4, AreaStyle.builder()
|
||||
.color(Color.BLUE)
|
||||
//.outline(Color.CYAN, 1)
|
||||
.build());
|
||||
|
@ -77,8 +77,8 @@ public class RuleVisitorTest extends GdxMap {
|
||||
}
|
||||
|
||||
static class SaturateLineStyles extends RuleVisitor {
|
||||
private final LineBuilder lineBuilder = new LineBuilder();
|
||||
private final AreaBuilder areaBuilder = new AreaBuilder();
|
||||
private final LineBuilder<?> lineBuilder = LineStyle.builder();
|
||||
private final AreaBuilder<?> areaBuilder = AreaStyle.builder();
|
||||
|
||||
private final double saturation;
|
||||
private final boolean modifyArea;
|
||||
|
@ -8,9 +8,12 @@ import org.oscim.theme.rule.Rule;
|
||||
import org.oscim.theme.rule.Rule.Element;
|
||||
import org.oscim.theme.rule.RuleBuilder;
|
||||
import org.oscim.theme.rule.RuleBuilder.RuleType;
|
||||
import org.oscim.theme.styles.AreaStyle;
|
||||
import org.oscim.theme.styles.AreaStyle.AreaBuilder;
|
||||
import org.oscim.theme.styles.LineStyle;
|
||||
import org.oscim.theme.styles.LineStyle.LineBuilder;
|
||||
import org.oscim.theme.styles.RenderStyle;
|
||||
import org.oscim.theme.styles.TextStyle;
|
||||
import org.oscim.theme.styles.TextStyle.TextBuilder;
|
||||
|
||||
public class ThemeBuilder {
|
||||
@ -82,28 +85,28 @@ public class ThemeBuilder {
|
||||
|
||||
};
|
||||
|
||||
public static LineBuilder line(int color, float width) {
|
||||
return new LineBuilder()
|
||||
public static LineBuilder<?> line(int color, float width) {
|
||||
return LineStyle.builder()
|
||||
.color(color)
|
||||
.width(width);
|
||||
.strokeWidth(width);
|
||||
}
|
||||
|
||||
public static AreaBuilder area(int color) {
|
||||
return new AreaBuilder()
|
||||
public static AreaBuilder<?> area(int color) {
|
||||
return AreaStyle.builder()
|
||||
.color(color);
|
||||
}
|
||||
|
||||
public static TextBuilder wayText(float size, int color) {
|
||||
return new TextBuilder()
|
||||
.setFontSize(size)
|
||||
.setColor(color);
|
||||
public static TextBuilder<?> wayText(float size, int color) {
|
||||
return TextStyle.builder()
|
||||
.fontSize(size)
|
||||
.color(color);
|
||||
}
|
||||
|
||||
public static TextBuilder nodeText(float size, int color) {
|
||||
return new TextBuilder()
|
||||
.setFontSize(size)
|
||||
.setColor(color)
|
||||
.setCaption(true);
|
||||
public static TextBuilder<?> nodeText(float size, int color) {
|
||||
return TextStyle.builder()
|
||||
.fontSize(size)
|
||||
.color(color)
|
||||
.isCaption(true);
|
||||
}
|
||||
|
||||
public static RuleBuilder matchKey(String key) {
|
||||
|
@ -17,7 +17,6 @@ import org.oscim.renderer.bucket.TextBucket;
|
||||
import org.oscim.renderer.bucket.TextItem;
|
||||
import org.oscim.theme.styles.LineStyle;
|
||||
import org.oscim.theme.styles.TextStyle;
|
||||
import org.oscim.theme.styles.TextStyle.TextBuilder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -42,6 +41,10 @@ public class AtlasTest extends GdxMap {
|
||||
|
||||
TextureAtlas mAtlas = TextureAtlas.create(2048, 2048, 1);
|
||||
|
||||
TextBucket tl = new TextBucket();
|
||||
TextStyle t = TextStyle.builder().fontSize(20).color(Color.BLACK).build();
|
||||
buckets.set(tl);
|
||||
|
||||
LineBucket ll = buckets.getLineBucket(0);
|
||||
ll.line = new LineStyle(Color.BLUE, 3, Cap.BUTT);
|
||||
ll.scale = 1f;
|
||||
@ -54,10 +57,6 @@ public class AtlasTest extends GdxMap {
|
||||
ll3.line = new LineStyle(Color.GREEN, 3, Cap.BUTT);
|
||||
ll3.scale = 1f;
|
||||
|
||||
TextBucket tl = new TextBucket();
|
||||
TextStyle t = new TextBuilder().setFontSize(20).setColor(Color.BLACK).build();
|
||||
buckets.set(tl);
|
||||
|
||||
float[] points = new float[10];
|
||||
|
||||
for (int i = 0; i < 400; i++) {
|
||||
|
@ -44,7 +44,7 @@ import org.oscim.tiling.ITileDataSource;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class VectorTileLoader extends TileLoader implements IRenderTheme.Callback {
|
||||
public class VectorTileLoader extends TileLoader implements RenderStyle.Callback {
|
||||
|
||||
static final Logger log = LoggerFactory.getLogger(VectorTileLoader.class);
|
||||
|
||||
|
@ -25,7 +25,6 @@ import org.oscim.renderer.bucket.TextBucket;
|
||||
import org.oscim.renderer.bucket.TextItem;
|
||||
import org.oscim.theme.styles.LineStyle;
|
||||
import org.oscim.theme.styles.TextStyle;
|
||||
import org.oscim.theme.styles.TextStyle.TextBuilder;
|
||||
|
||||
public class GridRenderer extends BucketRenderer {
|
||||
|
||||
@ -39,7 +38,10 @@ public class GridRenderer extends BucketRenderer {
|
||||
|
||||
public GridRenderer() {
|
||||
this(1, new LineStyle(Color.LTGRAY, 1.2f, Cap.BUTT),
|
||||
new TextBuilder().setFontSize(22).setColor(Color.RED).build());
|
||||
TextStyle.builder()
|
||||
.fontSize(22)
|
||||
.color(Color.RED)
|
||||
.build());
|
||||
}
|
||||
|
||||
public GridRenderer(int numLines, LineStyle lineStyle, TextStyle textStyle) {
|
||||
|
@ -23,7 +23,7 @@ public class DebugTheme implements IRenderTheme {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
public void dispose() {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -19,13 +19,7 @@ package org.oscim.theme;
|
||||
|
||||
import org.oscim.core.GeometryBuffer.GeometryType;
|
||||
import org.oscim.core.TagSet;
|
||||
import org.oscim.theme.styles.AreaStyle;
|
||||
import org.oscim.theme.styles.CircleStyle;
|
||||
import org.oscim.theme.styles.ExtrusionStyle;
|
||||
import org.oscim.theme.styles.LineStyle;
|
||||
import org.oscim.theme.styles.RenderStyle;
|
||||
import org.oscim.theme.styles.SymbolStyle;
|
||||
import org.oscim.theme.styles.TextStyle;
|
||||
|
||||
public interface IRenderTheme {
|
||||
|
||||
@ -42,7 +36,7 @@ public interface IRenderTheme {
|
||||
* Must be called when this RenderTheme gets destroyed to clean up and free
|
||||
* resources.
|
||||
*/
|
||||
public abstract void destroy();
|
||||
public abstract void dispose();
|
||||
|
||||
/**
|
||||
* @return the number of distinct drawing levels required by this
|
||||
@ -65,61 +59,6 @@ public interface IRenderTheme {
|
||||
*/
|
||||
public abstract void scaleTextSize(float scaleFactor);
|
||||
|
||||
/**
|
||||
* Callback methods for rendering areas, ways and points of interest (POIs).
|
||||
*/
|
||||
public interface Callback {
|
||||
/**
|
||||
* Renders an area with the given parameters.
|
||||
*
|
||||
* @param area
|
||||
* @param level
|
||||
*/
|
||||
void renderArea(AreaStyle area, int level);
|
||||
|
||||
/**
|
||||
* Renders an extrusion with the given parameters.
|
||||
*
|
||||
* @param extrusion
|
||||
* @param level
|
||||
*/
|
||||
void renderExtrusion(ExtrusionStyle extrusion, int level);
|
||||
|
||||
/**
|
||||
* Renders a point of interest circle with the given parameters.
|
||||
*
|
||||
* @param circle
|
||||
* the circle.
|
||||
* @param level
|
||||
* the drawing level on which the circle should be rendered.
|
||||
*/
|
||||
void renderCircle(CircleStyle circle, int level);
|
||||
|
||||
/**
|
||||
* Renders a point of interest symbol with the given bitmap.
|
||||
*
|
||||
* @param symbol
|
||||
* the symbol to be rendered.
|
||||
*/
|
||||
void renderSymbol(SymbolStyle symbol);
|
||||
|
||||
/**
|
||||
* Renders a way with the given parameters.
|
||||
*
|
||||
* @param line
|
||||
* @param level
|
||||
*/
|
||||
void renderWay(LineStyle line, int level);
|
||||
|
||||
/**
|
||||
* Renders a way with the given text along the way path.
|
||||
*
|
||||
* @param text
|
||||
*/
|
||||
void renderText(TextStyle text);
|
||||
|
||||
}
|
||||
|
||||
public static class ThemeException extends IllegalArgumentException {
|
||||
public ThemeException(String string) {
|
||||
super(string);
|
||||
|
@ -88,7 +88,7 @@ public class RenderTheme implements IRenderTheme {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
public void dispose() {
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
mStyleCache[i].cache.clear();
|
||||
|
@ -128,12 +128,12 @@ public class XmlThemeBuilder extends DefaultHandler {
|
||||
private final HashMap<String, RenderStyle> mStyles =
|
||||
new HashMap<String, RenderStyle>(10);
|
||||
|
||||
private final HashMap<String, TextStyle.TextBuilder> mTextStyles =
|
||||
new HashMap<String, TextStyle.TextBuilder>(10);
|
||||
private final HashMap<String, TextStyle.TextBuilder<?>> mTextStyles =
|
||||
new HashMap<String, TextStyle.TextBuilder<?>>(10);
|
||||
|
||||
private final TextBuilder mTextBuilder = new TextBuilder();
|
||||
private final AreaBuilder mAreaBuilder = new AreaBuilder();
|
||||
private final LineBuilder mLineBuilder = new LineBuilder();
|
||||
private final TextBuilder<?> mTextBuilder = TextStyle.builder();
|
||||
private final AreaBuilder<?> mAreaBuilder = AreaStyle.builder();
|
||||
private final LineBuilder<?> mLineBuilder = LineStyle.builder();
|
||||
|
||||
private RuleBuilder mCurrentRule;
|
||||
private TextureAtlas mTextureAtlas;
|
||||
@ -387,7 +387,7 @@ public class XmlThemeBuilder extends DefaultHandler {
|
||||
*/
|
||||
private LineStyle createLine(LineStyle line, String elementName, Attributes attributes,
|
||||
int level, boolean isOutline) {
|
||||
LineBuilder b = mLineBuilder.set(line);
|
||||
LineBuilder<?> b = mLineBuilder.set(line);
|
||||
b.isOutline(isOutline);
|
||||
b.level(level);
|
||||
|
||||
@ -411,15 +411,15 @@ public class XmlThemeBuilder extends DefaultHandler {
|
||||
b.color(value);
|
||||
|
||||
else if ("width".equals(name) || "stroke-width".equals(name)) {
|
||||
b.width = parseFloat(value);
|
||||
b.strokeWidth = parseFloat(value);
|
||||
if (line == null) {
|
||||
if (!isOutline)
|
||||
validateNonNegative("width", b.width);
|
||||
validateNonNegative("width", b.strokeWidth);
|
||||
} else {
|
||||
/* use stroke width relative to 'line' */
|
||||
b.width += line.width;
|
||||
if (b.width <= 0)
|
||||
b.width = 1;
|
||||
b.strokeWidth += line.width;
|
||||
if (b.strokeWidth <= 0)
|
||||
b.strokeWidth = 1;
|
||||
}
|
||||
}
|
||||
else if ("cap".equals(name) || "stroke-linecap".equals(name))
|
||||
@ -486,7 +486,7 @@ public class XmlThemeBuilder extends DefaultHandler {
|
||||
*/
|
||||
private AreaStyle createArea(AreaStyle area, String elementName, Attributes attributes,
|
||||
int level) {
|
||||
AreaBuilder b = mAreaBuilder.set(area);
|
||||
AreaBuilder<?> b = mAreaBuilder.set(area);
|
||||
b.level(level);
|
||||
|
||||
String src = null;
|
||||
@ -691,7 +691,7 @@ public class XmlThemeBuilder extends DefaultHandler {
|
||||
boolean isCaption) throws SAXException {
|
||||
|
||||
String style = attributes.getValue("use");
|
||||
TextStyle.TextBuilder pt = null;
|
||||
TextBuilder<?> pt = null;
|
||||
|
||||
if (style != null) {
|
||||
pt = mTextStyles.get(style);
|
||||
@ -701,10 +701,10 @@ public class XmlThemeBuilder extends DefaultHandler {
|
||||
}
|
||||
}
|
||||
|
||||
TextBuilder b = createText(localName, attributes, isCaption, pt);
|
||||
TextBuilder<?> b = createText(localName, attributes, isCaption, pt);
|
||||
if (isStyle) {
|
||||
log.debug("put style {}", b.style);
|
||||
mTextStyles.put(b.style, new TextBuilder().setFrom(b));
|
||||
mTextStyles.put(b.style, TextStyle.builder().from(b));
|
||||
} else {
|
||||
mCurrentRule.addStyle(b.buildInternal());
|
||||
}
|
||||
@ -715,14 +715,14 @@ public class XmlThemeBuilder extends DefaultHandler {
|
||||
* ...
|
||||
* @return a new Text with the given rendering attributes.
|
||||
*/
|
||||
private TextStyle.TextBuilder createText(String elementName, Attributes attributes,
|
||||
boolean caption, TextBuilder style) {
|
||||
TextBuilder b;
|
||||
private TextBuilder<?> createText(String elementName, Attributes attributes,
|
||||
boolean caption, TextBuilder<?> style) {
|
||||
TextBuilder<?> b;
|
||||
if (style == null) {
|
||||
b = mTextBuilder.reset();
|
||||
b.caption = caption;
|
||||
} else
|
||||
b = mTextBuilder.setFrom(style);
|
||||
b = mTextBuilder.from(style);
|
||||
|
||||
for (int i = 0; i < attributes.getLength(); i++) {
|
||||
String name = attributes.getLocalName(i);
|
||||
@ -744,10 +744,10 @@ public class XmlThemeBuilder extends DefaultHandler {
|
||||
b.fontSize = Float.parseFloat(value);
|
||||
|
||||
else if ("fill".equals(name))
|
||||
b.color = Color.parseColor(value);
|
||||
b.fillColor = Color.parseColor(value);
|
||||
|
||||
else if ("stroke".equals(name))
|
||||
b.stroke = Color.parseColor(value);
|
||||
b.strokeColor = Color.parseColor(value);
|
||||
|
||||
else if ("stroke-width".equals(name))
|
||||
b.strokeWidth = Float.parseFloat(value);
|
||||
|
@ -328,4 +328,7 @@ public class Rule {
|
||||
}
|
||||
}
|
||||
|
||||
public static RuleBuilder builder() {
|
||||
return new RuleBuilder();
|
||||
}
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ public class RuleBuilder {
|
||||
|
||||
ArrayList<RenderStyle> renderStyles = new ArrayList<RenderStyle>(4);
|
||||
ArrayList<RuleBuilder> subRules = new ArrayList<RuleBuilder>(4);
|
||||
StyleBuilder[] styleBuilder;
|
||||
StyleBuilder<?>[] styleBuilder;
|
||||
|
||||
private static final String STRING_NEGATION = "~";
|
||||
private static final String STRING_EXCLUSIVE = "-";
|
||||
@ -134,7 +134,7 @@ public class RuleBuilder {
|
||||
Rule[] rules = null;
|
||||
|
||||
if (styleBuilder != null)
|
||||
for (StyleBuilder style : styleBuilder) {
|
||||
for (StyleBuilder<?> style : styleBuilder) {
|
||||
renderStyles.add(style.level(level[0]).build());
|
||||
level[0] += 2;
|
||||
}
|
||||
@ -193,7 +193,7 @@ public class RuleBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public RuleBuilder style(StyleBuilder... styles) {
|
||||
public RuleBuilder style(StyleBuilder<?>... styles) {
|
||||
styleBuilder = styles;
|
||||
return this;
|
||||
}
|
||||
|
@ -20,7 +20,6 @@ import static org.oscim.backend.canvas.Color.parseColor;
|
||||
|
||||
import org.oscim.backend.canvas.Color;
|
||||
import org.oscim.renderer.bucket.TextureItem;
|
||||
import org.oscim.theme.IRenderTheme.Callback;
|
||||
import org.oscim.utils.FastMath;
|
||||
|
||||
/*TODO
|
||||
@ -71,13 +70,13 @@ public class AreaStyle extends RenderStyle {
|
||||
this.strokeWidth = 1;
|
||||
}
|
||||
|
||||
public AreaStyle(AreaBuilder b) {
|
||||
public AreaStyle(AreaBuilder<?> b) {
|
||||
this.level = b.level;
|
||||
this.style = b.style;
|
||||
this.fadeScale = b.fadeScale;
|
||||
this.blendColor = b.blendColor;
|
||||
this.blendScale = b.blendScale;
|
||||
this.color = b.color;
|
||||
this.color = b.fillColor;
|
||||
this.texture = b.texture;
|
||||
|
||||
this.strokeColor = b.strokeColor;
|
||||
@ -90,8 +89,8 @@ public class AreaStyle extends RenderStyle {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderWay(Callback renderCallback) {
|
||||
renderCallback.renderArea(this, level);
|
||||
public void renderWay(Callback cb) {
|
||||
cb.renderArea(this, level);
|
||||
}
|
||||
|
||||
public boolean hasAlpha(int zoom) {
|
||||
@ -115,119 +114,6 @@ public class AreaStyle extends RenderStyle {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static class AreaBuilder implements StyleBuilder {
|
||||
public int level;
|
||||
public String style;
|
||||
public int color;
|
||||
public int fadeScale;
|
||||
public int blendColor;
|
||||
public int blendScale;
|
||||
|
||||
public int strokeColor;
|
||||
public float strokeWidth;
|
||||
|
||||
public TextureItem texture;
|
||||
|
||||
public AreaBuilder set(AreaStyle area) {
|
||||
if (area == null)
|
||||
return reset();
|
||||
|
||||
this.level = area.level;
|
||||
this.style = area.style;
|
||||
this.fadeScale = area.fadeScale;
|
||||
this.blendColor = area.blendColor;
|
||||
this.blendScale = area.blendScale;
|
||||
this.color = area.color;
|
||||
this.texture = area.texture;
|
||||
this.strokeColor = area.strokeColor;
|
||||
this.strokeWidth = area.strokeWidth;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public AreaBuilder style(String name) {
|
||||
this.style = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AreaBuilder level(int level) {
|
||||
this.level = level;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AreaBuilder outline(int color, float width) {
|
||||
this.strokeColor = color;
|
||||
this.strokeWidth = width;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AreaBuilder strokeColor(int color) {
|
||||
this.strokeColor = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AreaBuilder strokeColor(String color) {
|
||||
this.strokeColor = parseColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
public AreaBuilder strokeWidth(float width) {
|
||||
this.strokeWidth = width;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AreaBuilder color(int color) {
|
||||
this.color = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AreaBuilder color(String color) {
|
||||
this.color = parseColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
public AreaBuilder blendScale(int zoom) {
|
||||
this.blendScale = zoom;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AreaBuilder blendColor(int color) {
|
||||
this.blendColor = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AreaBuilder blendColor(String color) {
|
||||
this.blendColor = parseColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
public AreaBuilder texture(TextureItem texture) {
|
||||
this.texture = texture;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AreaBuilder fadeScale(int zoom) {
|
||||
this.fadeScale = zoom;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AreaBuilder reset() {
|
||||
color = Color.BLACK;
|
||||
strokeColor = Color.BLACK;
|
||||
strokeWidth = 0;
|
||||
fadeScale = -1;
|
||||
blendScale = -1;
|
||||
blendColor = Color.TRANSPARENT;
|
||||
style = null;
|
||||
texture = null;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AreaStyle build() {
|
||||
return new AreaStyle(this);
|
||||
}
|
||||
}
|
||||
|
||||
public float getFade(double scale) {
|
||||
if (fadeScale < 0)
|
||||
return 1;
|
||||
@ -244,4 +130,78 @@ public class AreaStyle extends RenderStyle {
|
||||
return FastMath.clamp(f, 0, 1);
|
||||
}
|
||||
|
||||
public static class AreaBuilder<T extends AreaBuilder<T>> extends StyleBuilder<T> {
|
||||
|
||||
public int fadeScale;
|
||||
public int blendColor;
|
||||
public int blendScale;
|
||||
|
||||
public TextureItem texture;
|
||||
|
||||
public AreaBuilder() {
|
||||
}
|
||||
|
||||
public T set(AreaStyle area) {
|
||||
if (area == null)
|
||||
return reset();
|
||||
|
||||
this.level = area.level;
|
||||
this.style = area.style;
|
||||
this.fadeScale = area.fadeScale;
|
||||
this.blendColor = area.blendColor;
|
||||
this.blendScale = area.blendScale;
|
||||
this.fillColor = area.color;
|
||||
this.texture = area.texture;
|
||||
this.strokeColor = area.strokeColor;
|
||||
this.strokeWidth = area.strokeWidth;
|
||||
|
||||
return self();
|
||||
}
|
||||
|
||||
public T blendScale(int zoom) {
|
||||
this.blendScale = zoom;
|
||||
return self();
|
||||
}
|
||||
|
||||
public T blendColor(int color) {
|
||||
this.blendColor = color;
|
||||
return self();
|
||||
}
|
||||
|
||||
public T blendColor(String color) {
|
||||
this.blendColor = parseColor(color);
|
||||
return self();
|
||||
}
|
||||
|
||||
public T texture(TextureItem texture) {
|
||||
this.texture = texture;
|
||||
return self();
|
||||
}
|
||||
|
||||
public T fadeScale(int zoom) {
|
||||
this.fadeScale = zoom;
|
||||
return self();
|
||||
}
|
||||
|
||||
public T reset() {
|
||||
fillColor = Color.BLACK;
|
||||
strokeColor = Color.BLACK;
|
||||
strokeWidth = 0;
|
||||
fadeScale = -1;
|
||||
blendScale = -1;
|
||||
blendColor = Color.TRANSPARENT;
|
||||
style = null;
|
||||
texture = null;
|
||||
return self();
|
||||
}
|
||||
|
||||
public AreaStyle build() {
|
||||
return new AreaStyle(this);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static AreaBuilder<?> builder() {
|
||||
return new AreaBuilder();
|
||||
}
|
||||
}
|
||||
|
@ -17,8 +17,6 @@
|
||||
*/
|
||||
package org.oscim.theme.styles;
|
||||
|
||||
import org.oscim.theme.IRenderTheme.Callback;
|
||||
|
||||
/**
|
||||
* Represents a round area on the map.
|
||||
*/
|
||||
@ -48,8 +46,8 @@ public final class CircleStyle extends RenderStyle {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderNode(Callback renderCallback) {
|
||||
renderCallback.renderCircle(this, this.level);
|
||||
public void renderNode(Callback cb) {
|
||||
cb.renderCircle(this, this.level);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -17,7 +17,6 @@
|
||||
package org.oscim.theme.styles;
|
||||
|
||||
import org.oscim.backend.canvas.Color;
|
||||
import org.oscim.theme.IRenderTheme.Callback;
|
||||
|
||||
public class ExtrusionStyle extends RenderStyle {
|
||||
|
||||
@ -57,8 +56,8 @@ public class ExtrusionStyle extends RenderStyle {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderWay(Callback renderCallback) {
|
||||
renderCallback.renderExtrusion(this, this.level);
|
||||
public void renderWay(Callback cb) {
|
||||
cb.renderExtrusion(this, this.level);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -21,7 +21,6 @@ import static org.oscim.backend.canvas.Color.parseColor;
|
||||
|
||||
import org.oscim.backend.canvas.Color;
|
||||
import org.oscim.backend.canvas.Paint.Cap;
|
||||
import org.oscim.theme.IRenderTheme.Callback;
|
||||
|
||||
public final class LineStyle extends RenderStyle {
|
||||
|
||||
@ -39,11 +38,11 @@ public final class LineStyle extends RenderStyle {
|
||||
public final int stippleColor;
|
||||
public final float stippleWidth;
|
||||
|
||||
private LineStyle(LineBuilder builer) {
|
||||
private LineStyle(LineBuilder<?> builer) {
|
||||
this.level = builer.level;
|
||||
this.style = builer.style;
|
||||
this.width = builer.width;
|
||||
this.color = builer.color;
|
||||
this.width = builer.strokeWidth;
|
||||
this.color = builer.fillColor;
|
||||
this.cap = builer.cap;
|
||||
this.outline = builer.outline;
|
||||
this.fixed = builer.fixed;
|
||||
@ -89,8 +88,8 @@ public final class LineStyle extends RenderStyle {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderWay(Callback renderCallback) {
|
||||
renderCallback.renderWay(this, level);
|
||||
public void renderWay(Callback cb) {
|
||||
cb.renderWay(this, level);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -98,12 +97,9 @@ public final class LineStyle extends RenderStyle {
|
||||
return (LineStyle) mCurrent;
|
||||
}
|
||||
|
||||
public final static class LineBuilder implements StyleBuilder {
|
||||
public int level;
|
||||
public static class LineBuilder<T extends LineBuilder<T>> extends StyleBuilder<T> {
|
||||
|
||||
public String style;
|
||||
public float width;
|
||||
public int color;
|
||||
public Cap cap;
|
||||
public boolean outline;
|
||||
public boolean fixed;
|
||||
@ -114,13 +110,13 @@ public final class LineStyle extends RenderStyle {
|
||||
public int stippleColor;
|
||||
public float stippleWidth;
|
||||
|
||||
public LineBuilder set(LineStyle line) {
|
||||
public T set(LineStyle line) {
|
||||
if (line == null)
|
||||
return reset();
|
||||
this.level = line.level;
|
||||
this.style = line.style;
|
||||
this.width = line.width;
|
||||
this.color = line.color;
|
||||
this.strokeWidth = line.width;
|
||||
this.fillColor = line.color;
|
||||
this.cap = line.cap;
|
||||
this.outline = line.outline;
|
||||
this.fixed = line.fixed;
|
||||
@ -129,15 +125,15 @@ public final class LineStyle extends RenderStyle {
|
||||
this.stipple = line.stipple;
|
||||
this.stippleColor = line.stippleColor;
|
||||
this.stippleWidth = line.stippleWidth;
|
||||
return this;
|
||||
return self();
|
||||
}
|
||||
|
||||
public LineBuilder reset() {
|
||||
public T reset() {
|
||||
level = -1;
|
||||
style = null;
|
||||
color = Color.BLACK;
|
||||
fillColor = Color.BLACK;
|
||||
cap = Cap.ROUND;
|
||||
width = 1;
|
||||
strokeWidth = 1;
|
||||
fixed = false;
|
||||
|
||||
fadeScale = -1;
|
||||
@ -147,71 +143,56 @@ public final class LineStyle extends RenderStyle {
|
||||
stippleWidth = 1;
|
||||
stippleColor = Color.BLACK;
|
||||
|
||||
return this;
|
||||
return self();
|
||||
}
|
||||
|
||||
public LineBuilder style(String name) {
|
||||
public T style(String name) {
|
||||
this.style = name;
|
||||
return this;
|
||||
return self();
|
||||
}
|
||||
|
||||
public LineBuilder level(int level) {
|
||||
this.level = level;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LineBuilder color(int color) {
|
||||
this.color = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LineBuilder width(float width) {
|
||||
this.width = width;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LineBuilder blur(float blur) {
|
||||
public T blur(float blur) {
|
||||
this.blur = blur;
|
||||
return this;
|
||||
return self();
|
||||
}
|
||||
|
||||
public LineBuilder fadeScale(int zoom) {
|
||||
public T fadeScale(int zoom) {
|
||||
this.fadeScale = zoom;
|
||||
return this;
|
||||
return self();
|
||||
}
|
||||
|
||||
public LineBuilder stippleColor(int color) {
|
||||
public T stippleColor(int color) {
|
||||
this.stippleColor = color;
|
||||
return this;
|
||||
return self();
|
||||
}
|
||||
|
||||
public LineBuilder color(String color) {
|
||||
this.color = parseColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
public LineBuilder stippleColor(String color) {
|
||||
public T stippleColor(String color) {
|
||||
this.stippleColor = parseColor(color);
|
||||
return this;
|
||||
return self();
|
||||
}
|
||||
|
||||
public LineBuilder isOutline(boolean outline) {
|
||||
public T isOutline(boolean outline) {
|
||||
this.outline = outline;
|
||||
return this;
|
||||
return self();
|
||||
}
|
||||
|
||||
public LineStyle build() {
|
||||
return new LineStyle(this);
|
||||
}
|
||||
|
||||
public LineBuilder cap(Cap cap) {
|
||||
public T cap(Cap cap) {
|
||||
this.cap = cap;
|
||||
return this;
|
||||
return self();
|
||||
}
|
||||
|
||||
public LineBuilder fixed(boolean b) {
|
||||
public T fixed(boolean b) {
|
||||
this.fixed = b;
|
||||
return this;
|
||||
return self();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static LineBuilder<?> builder() {
|
||||
return new LineBuilder();
|
||||
}
|
||||
}
|
||||
|
@ -17,17 +17,126 @@
|
||||
*/
|
||||
package org.oscim.theme.styles;
|
||||
|
||||
import org.oscim.theme.IRenderTheme.Callback;
|
||||
import static org.oscim.backend.canvas.Color.parseColor;
|
||||
|
||||
/**
|
||||
* A RenderInstruction is a basic graphical primitive to draw a map.
|
||||
*/
|
||||
public abstract class RenderStyle {
|
||||
|
||||
public interface StyleBuilder {
|
||||
RenderStyle build();
|
||||
public static abstract class StyleBuilder<T extends StyleBuilder<T>> {
|
||||
|
||||
public String style;
|
||||
|
||||
public int level;
|
||||
|
||||
public int fillColor;
|
||||
|
||||
public int strokeColor;
|
||||
public float strokeWidth;
|
||||
|
||||
public T setStyle(String style) {
|
||||
this.style = style;
|
||||
return self();
|
||||
}
|
||||
|
||||
public T level(int level) {
|
||||
this.level = level;
|
||||
return self();
|
||||
}
|
||||
|
||||
public T outline(int color, float width) {
|
||||
this.strokeColor = color;
|
||||
this.strokeWidth = width;
|
||||
return self();
|
||||
}
|
||||
|
||||
public T strokeColor(int color) {
|
||||
this.strokeColor = color;
|
||||
return self();
|
||||
}
|
||||
|
||||
public T strokeColor(String color) {
|
||||
this.strokeColor = parseColor(color);
|
||||
return self();
|
||||
}
|
||||
|
||||
public T strokeWidth(float width) {
|
||||
this.strokeWidth = width;
|
||||
return self();
|
||||
}
|
||||
|
||||
public T color(int color) {
|
||||
this.fillColor = color;
|
||||
return self();
|
||||
}
|
||||
|
||||
public T color(String color) {
|
||||
this.fillColor = parseColor(color);
|
||||
return self();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected T self() {
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public abstract RenderStyle build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback methods for rendering areas, ways and points of interest (POIs).
|
||||
*/
|
||||
public static interface Callback {
|
||||
/**
|
||||
* Renders an area with the given parameters.
|
||||
*
|
||||
* @param area
|
||||
* @param level
|
||||
*/
|
||||
void renderArea(AreaStyle area, int level);
|
||||
|
||||
/**
|
||||
* Renders an extrusion with the given parameters.
|
||||
*
|
||||
* @param extrusion
|
||||
* @param level
|
||||
*/
|
||||
void renderExtrusion(ExtrusionStyle extrusion, int level);
|
||||
|
||||
/**
|
||||
* Renders a point of interest circle with the given parameters.
|
||||
*
|
||||
* @param circle
|
||||
* the circle.
|
||||
* @param level
|
||||
* the drawing level on which the circle should be rendered.
|
||||
*/
|
||||
void renderCircle(CircleStyle circle, int level);
|
||||
|
||||
/**
|
||||
* Renders a point of interest symbol with the given bitmap.
|
||||
*
|
||||
* @param symbol
|
||||
* the symbol to be rendered.
|
||||
*/
|
||||
void renderSymbol(SymbolStyle symbol);
|
||||
|
||||
/**
|
||||
* Renders a way with the given parameters.
|
||||
*
|
||||
* @param line
|
||||
* @param level
|
||||
*/
|
||||
void renderWay(LineStyle line, int level);
|
||||
|
||||
/**
|
||||
* Renders a way with the given text along the way path.
|
||||
*
|
||||
* @param text
|
||||
*/
|
||||
void renderText(TextStyle text);
|
||||
|
||||
StyleBuilder level(int level);
|
||||
}
|
||||
|
||||
RenderStyle mCurrent = this;
|
||||
|
@ -18,7 +18,6 @@
|
||||
package org.oscim.theme.styles;
|
||||
|
||||
import org.oscim.renderer.atlas.TextureRegion;
|
||||
import org.oscim.theme.IRenderTheme.Callback;
|
||||
|
||||
/**
|
||||
* Represents an icon on the map.
|
||||
|
@ -23,13 +23,11 @@ import org.oscim.backend.canvas.Paint.Align;
|
||||
import org.oscim.backend.canvas.Paint.FontFamily;
|
||||
import org.oscim.backend.canvas.Paint.FontStyle;
|
||||
import org.oscim.renderer.atlas.TextureRegion;
|
||||
import org.oscim.theme.IRenderTheme.Callback;
|
||||
|
||||
public final class TextStyle extends RenderStyle {
|
||||
|
||||
public static class TextBuilder implements StyleBuilder {
|
||||
public static class TextBuilder<T extends TextBuilder<T>> extends StyleBuilder<T> {
|
||||
|
||||
public String style;
|
||||
public float fontSize;
|
||||
|
||||
public String textKey;
|
||||
@ -40,11 +38,7 @@ public final class TextStyle extends RenderStyle {
|
||||
public FontFamily fontFamily;
|
||||
public FontStyle fontStyle;
|
||||
|
||||
public int color;
|
||||
public int stroke;
|
||||
public float strokeWidth;
|
||||
|
||||
public TextBuilder reset() {
|
||||
public T reset() {
|
||||
fontFamily = FontFamily.DEFAULT;
|
||||
fontStyle = FontStyle.NORMAL;
|
||||
style = null;
|
||||
@ -53,11 +47,11 @@ public final class TextStyle extends RenderStyle {
|
||||
caption = false;
|
||||
priority = Integer.MAX_VALUE;
|
||||
texture = null;
|
||||
color = Color.BLACK;
|
||||
stroke = Color.BLACK;
|
||||
fillColor = Color.BLACK;
|
||||
strokeColor = Color.BLACK;
|
||||
strokeWidth = 0;
|
||||
dy = 0;
|
||||
return this;
|
||||
return self();
|
||||
}
|
||||
|
||||
public TextBuilder() {
|
||||
@ -75,89 +69,80 @@ public final class TextStyle extends RenderStyle {
|
||||
return new TextStyle(this);
|
||||
}
|
||||
|
||||
public TextBuilder setStyle(String style) {
|
||||
this.style = style;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TextBuilder setFontSize(float fontSize) {
|
||||
public T fontSize(float fontSize) {
|
||||
this.fontSize = fontSize;
|
||||
return this;
|
||||
return self();
|
||||
}
|
||||
|
||||
public TextBuilder setTextKey(String textKey) {
|
||||
public T textKey(String textKey) {
|
||||
this.textKey = textKey;
|
||||
return this;
|
||||
return self();
|
||||
}
|
||||
|
||||
public TextBuilder setCaption(boolean caption) {
|
||||
public T isCaption(boolean caption) {
|
||||
this.caption = caption;
|
||||
return this;
|
||||
return self();
|
||||
}
|
||||
|
||||
public TextBuilder setOffsetY(float dy) {
|
||||
public T offsetY(float dy) {
|
||||
this.dy = dy;
|
||||
return this;
|
||||
return self();
|
||||
}
|
||||
|
||||
public TextBuilder setPriority(int priority) {
|
||||
public T priority(int priority) {
|
||||
this.priority = priority;
|
||||
return this;
|
||||
return self();
|
||||
}
|
||||
|
||||
public TextBuilder setTexture(TextureRegion texture) {
|
||||
public T texture(TextureRegion texture) {
|
||||
this.texture = texture;
|
||||
return this;
|
||||
return self();
|
||||
}
|
||||
|
||||
public TextBuilder setFontFamily(FontFamily fontFamily) {
|
||||
public T fontFamily(FontFamily fontFamily) {
|
||||
this.fontFamily = fontFamily;
|
||||
return this;
|
||||
return self();
|
||||
}
|
||||
|
||||
public TextBuilder setFontStyle(FontStyle fontStyle) {
|
||||
public T fontStyle(FontStyle fontStyle) {
|
||||
this.fontStyle = fontStyle;
|
||||
return this;
|
||||
return self();
|
||||
}
|
||||
|
||||
public TextBuilder setColor(int color) {
|
||||
this.color = color;
|
||||
return this;
|
||||
public T from(TextBuilder<?> other) {
|
||||
fontFamily = other.fontFamily;
|
||||
fontStyle = other.fontStyle;
|
||||
style = other.style;
|
||||
textKey = other.textKey;
|
||||
fontSize = other.fontSize;
|
||||
caption = other.caption;
|
||||
priority = other.priority;
|
||||
texture = other.texture;
|
||||
fillColor = other.fillColor;
|
||||
strokeColor = other.strokeColor;
|
||||
strokeWidth = other.strokeWidth;
|
||||
dy = other.dy;
|
||||
return self();
|
||||
}
|
||||
|
||||
public TextBuilder setStroke(int stroke) {
|
||||
this.stroke = stroke;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TextBuilder setStrokeWidth(float strokeWidth) {
|
||||
this.strokeWidth = strokeWidth;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextBuilder level(int level) {
|
||||
return this;
|
||||
}
|
||||
|
||||
public TextBuilder setFrom(TextBuilder tb) {
|
||||
fontFamily = tb.fontFamily;
|
||||
fontStyle = tb.fontStyle;
|
||||
style = tb.style;
|
||||
textKey = tb.textKey;
|
||||
fontSize = tb.fontSize;
|
||||
caption = tb.caption;
|
||||
priority = tb.priority;
|
||||
texture = tb.texture;
|
||||
color = tb.color;
|
||||
stroke = tb.stroke;
|
||||
strokeWidth = tb.strokeWidth;
|
||||
dy = tb.dy;
|
||||
return this;
|
||||
public TextBuilder<?> from(TextStyle style) {
|
||||
this.style = style.style;
|
||||
this.textKey = style.textKey;
|
||||
this.caption = style.caption;
|
||||
this.dy = style.dy;
|
||||
this.priority = style.priority;
|
||||
this.texture = style.texture;
|
||||
this.fillColor = style.paint.getColor();
|
||||
this.fontFamily = FontFamily.DEFAULT;
|
||||
this.fontStyle = FontStyle.NORMAL;
|
||||
this.strokeColor = style.stroke.getColor();
|
||||
this.strokeWidth = 2;
|
||||
this.fontSize = style.fontSize;
|
||||
return self();
|
||||
}
|
||||
}
|
||||
|
||||
TextStyle(TextBuilder tb) {
|
||||
TextStyle(TextBuilder<?> tb) {
|
||||
this.style = tb.style;
|
||||
this.textKey = tb.textKey;
|
||||
this.caption = tb.caption;
|
||||
@ -169,7 +154,7 @@ public final class TextStyle extends RenderStyle {
|
||||
paint.setTextAlign(Align.CENTER);
|
||||
paint.setTypeface(tb.fontFamily, tb.fontStyle);
|
||||
|
||||
paint.setColor(tb.color);
|
||||
paint.setColor(tb.fillColor);
|
||||
paint.setTextSize(tb.fontSize);
|
||||
|
||||
if (tb.strokeWidth > 0) {
|
||||
@ -177,7 +162,7 @@ public final class TextStyle extends RenderStyle {
|
||||
stroke.setStyle(Paint.Style.STROKE);
|
||||
stroke.setTextAlign(Align.CENTER);
|
||||
stroke.setTypeface(tb.fontFamily, tb.fontStyle);
|
||||
stroke.setColor(tb.stroke);
|
||||
stroke.setColor(tb.strokeColor);
|
||||
stroke.setStrokeWidth(tb.strokeWidth);
|
||||
stroke.setTextSize(tb.fontSize);
|
||||
} else
|
||||
@ -226,4 +211,9 @@ public final class TextStyle extends RenderStyle {
|
||||
fontHeight = paint.getFontHeight();
|
||||
fontDescent = paint.getFontDescent();
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static TextBuilder<?> builder() {
|
||||
return new TextBuilder();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user