diff --git a/vtm/src/org/oscim/renderer/elements/PolygonLayer.java b/vtm/src/org/oscim/renderer/elements/PolygonLayer.java index 6b5db5d5..6bbd5d11 100644 --- a/vtm/src/org/oscim/renderer/elements/PolygonLayer.java +++ b/vtm/src/org/oscim/renderer/elements/PolygonLayer.java @@ -194,10 +194,10 @@ public final class PolygonLayer extends RenderElement { GLState.blend(true); a.texture.bind(); - } else if (a.fade >= zoom) { + } else if (a.fadeScale >= zoom) { float f = 1.0f; /* fade in/out */ - if (a.fade >= zoom) { + if (a.fadeScale >= zoom) { if (scale > FADE_START) f = scale - 1; else @@ -207,11 +207,11 @@ public final class PolygonLayer extends RenderElement { GLUtils.setColor(hPolygonColor[shader], a.color, f); - } else if (a.blend > 0 && a.blend <= zoom) { + } else if (a.blendScale > 0 && a.blendScale <= zoom) { /* blend colors (not alpha) */ GLState.blend(false); - if (a.blend == zoom) + if (a.blendScale == zoom) GLUtils.setColorBlend(hPolygonColor[shader], a.color, a.blendColor, scale - 1.0f); else @@ -301,7 +301,7 @@ public final class PolygonLayer extends RenderElement { PolygonLayer pl = (PolygonLayer) l; // fade out polygon layers (set in RenderTheme) - if (pl.area.fade > 0 && pl.area.fade > zoom) + if (pl.area.fadeScale > 0 && pl.area.fadeScale > zoom) continue; if (cur == start) { diff --git a/vtm/src/org/oscim/theme/XmlThemeBuilder.java b/vtm/src/org/oscim/theme/XmlThemeBuilder.java index e22f56b1..7a496197 100644 --- a/vtm/src/org/oscim/theme/XmlThemeBuilder.java +++ b/vtm/src/org/oscim/theme/XmlThemeBuilder.java @@ -38,6 +38,7 @@ import org.oscim.theme.IRenderTheme.ThemeException; import org.oscim.theme.rule.Rule; import org.oscim.theme.rule.RuleBuilder; import org.oscim.theme.styles.Area; +import org.oscim.theme.styles.Area.AreaBuilder; import org.oscim.theme.styles.Circle; import org.oscim.theme.styles.Extrusion; import org.oscim.theme.styles.Line; @@ -127,6 +128,7 @@ public class XmlThemeBuilder extends DefaultHandler { new HashMap(10); private final TextBuilder mTextBuilder = new TextBuilder(); + private final AreaBuilder mAreaBuilder = new AreaBuilder(); private RuleBuilder mCurrentRule; private TextureAtlas mTextureAtlas; @@ -329,7 +331,7 @@ public class XmlThemeBuilder extends DefaultHandler { * is outline layer * @return a new Line with the given rendering attributes. */ - private static Line createLine(Line line, String elementName, Attributes attributes, + private Line createLine(Line line, String elementName, Attributes attributes, int level, boolean isOutline) { // Style name @@ -352,7 +354,7 @@ public class XmlThemeBuilder extends DefaultHandler { if (line != null) { color = line.color; fixed = line.fixed; - fade = line.fade; + fade = line.fadeScale; cap = line.cap; blur = line.blur; stipple = line.stipple; @@ -459,37 +461,18 @@ public class XmlThemeBuilder extends DefaultHandler { /** * @return a new Area with the given rendering attributes. */ - private static Area createArea(Area area, String elementName, Attributes attributes, int level) { + private Area createArea(Area area, String elementName, Attributes attributes, int level) { + AreaBuilder b = mAreaBuilder.set(area); + b.level(level); + String src = null; - int fill = Color.BLACK; - int stroke = Color.TRANSPARENT; - float strokeWidth = 1; - int fade = -1; - int blend = -1; - int blendFill = Color.TRANSPARENT; - String style = null; - - TextureItem texture = null; - - if (area != null) { - fill = area.color; - blend = area.blend; - blendFill = area.blendColor; - fade = area.fade; - // TODO texture = area.texture - - if (area.outline != null) { - stroke = area.outline.color; - strokeWidth = area.outline.width; - } - } for (int i = 0; i < attributes.getLength(); ++i) { String name = attributes.getLocalName(i); String value = attributes.getValue(i); if ("id".equals(name)) - style = value; + b.style = value; else if ("use".equals(name)) ;// ignore @@ -498,39 +481,39 @@ public class XmlThemeBuilder extends DefaultHandler { src = value; else if ("fill".equals(name)) - fill = Color.parseColor(value); + b.color(value); else if ("stroke".equals(name)) - stroke = Color.parseColor(value); + b.outlineColor(value); - else if ("stroke-width".equals(name)) - strokeWidth = Float.parseFloat(value); + else if ("stroke-width".equals(name)) { + float strokeWidth = Float.parseFloat(value); + validateNonNegative("stroke-width", strokeWidth); + b.outlineWidth = strokeWidth; - else if ("fade".equals(name)) - fade = Integer.parseInt(value); + } else if ("fade".equals(name)) + b.fadeScale = Integer.parseInt(value); else if ("blend".equals(name)) - blend = Integer.parseInt(value); + b.blendScale = Integer.parseInt(value); else if ("blend-fill".equals(name)) - blendFill = Color.parseColor(value); + b.blendColor(value); else logUnknownAttribute(elementName, name, value, i); } - validateNonNegative("stroke-width", strokeWidth); if (src != null) { try { - Bitmap b = CanvasAdapter.g.loadBitmapAsset(src); - if (b != null) - texture = new TextureItem(b, true); + Bitmap bitmap = CanvasAdapter.g.loadBitmapAsset(src); + if (bitmap != null) + b.texture = new TextureItem(bitmap, true); } catch (Exception e) { log.debug(e.getMessage()); } } - return new Area(style, fill, stroke, strokeWidth, fade, level, blend, - blendFill, texture); + return b.build(); } private void addOutline(String style) { diff --git a/vtm/src/org/oscim/theme/styles/Area.java b/vtm/src/org/oscim/theme/styles/Area.java index 6f487f23..6f9552e8 100644 --- a/vtm/src/org/oscim/theme/styles/Area.java +++ b/vtm/src/org/oscim/theme/styles/Area.java @@ -1,5 +1,4 @@ /* - * Copyright 2010, 2011, 2012 mapsforge.org * Copyright 2013 Hannes Janetzek * * This file is part of the OpenScienceMap project (http://www.opensciencemap.org). @@ -17,61 +16,37 @@ */ package org.oscim.theme.styles; +import static org.oscim.backend.canvas.Color.parseColor; + import org.oscim.backend.canvas.Color; import org.oscim.renderer.elements.TextureItem; import org.oscim.theme.IRenderTheme.Callback; -/** - * Represents a closed polygon on the map. - */ -public final class Area extends RenderStyle { +public class Area extends RenderStyle { - public static class AreaBuilder { - public int level; - public String style; - public Line outline; - public int color; - public int fade; - public int blendColor; - public int blend; - public TextureItem texture; + /** Drawing order level */ + private final int level; - public AreaBuilder set(Area area) { - this.level = area.level; - this.style = area.style; - this.fade = area.fade; - this.blendColor = area.blendColor; - this.blend = area.blend; - this.color = area.color; - this.texture = area.texture; - this.outline = area.outline; - return this; - } + /** Style name */ + public final String style; - public AreaBuilder setColor(int color) { - this.color = color; - return this; - } + /** Fill color */ + public final int color; - public AreaBuilder setColor(String color) { - this.color = Color.parseColor(color); - return this; - } + /** Fade-out zoom-level */ + public final int fadeScale; - public AreaBuilder setBlendColor(int color) { - this.blendColor = color; - return this; - } + /** Fade to blendColor zoom-level */ + public final int blendColor; - public AreaBuilder setBlendColor(String color) { - this.blendColor = Color.parseColor(color); - return this; - } + /** Blend fill color */ + public final int blendScale; - public Area build() { - return new Area(this); - } - } + /** Pattern texture */ + public final TextureItem texture; + + /** Outline */ + public final Line outline; public Area(int color) { this(0, color); @@ -80,42 +55,44 @@ public final class Area extends RenderStyle { public Area(int level, int color) { this.level = level; this.style = ""; - this.fade = -1; + this.fadeScale = -1; this.blendColor = 0; - this.blend = -1; + this.blendScale = -1; this.color = color; this.texture = null; this.outline = null; } - public Area(String style, int color, int stroke, float strokeWidth, - int fade, int level, int blend, int blendColor, TextureItem texture) { + public Area(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.texture = b.texture; - this.style = style; - this.color = color; - this.blendColor = blendColor; - this.blend = blend; - this.fade = fade; - this.level = level; - this.texture = texture; - - if (stroke == Color.TRANSPARENT) { + if (b.outline != null && + b.outlineColor == b.outline.color && + b.outlineWidth == b.outline.width) { + this.outline = b.outline; + } else if (b.outlineColor != Color.TRANSPARENT) { + this.outline = new Line(-1, b.outlineColor, b.outlineWidth); + } else { this.outline = null; - return; } - - this.outline = new Line(level + 1, stroke, strokeWidth); } - public Area(AreaBuilder areaBuilder) { - this.level = areaBuilder.level; - this.style = areaBuilder.style; - this.fade = areaBuilder.fade; - this.blendColor = areaBuilder.blendColor; - this.blend = areaBuilder.blend; - this.color = areaBuilder.color; - this.texture = areaBuilder.texture; - this.outline = areaBuilder.outline; + @Override + public void update() { + super.update(); + + if (outline != null) + outline.update(); + } + + public Area current() { + return (Area) (mCurrent == null ? this : mCurrent); } @Override @@ -126,19 +103,125 @@ public final class Area extends RenderStyle { renderCallback.renderWay(outline, level + 1); } - private final int level; - public final String style; - public final Line outline; - public final int color; - public final int fade; - public final int blendColor; - public final int blend; - public final TextureItem texture; + public static class AreaBuilder { + public int level; + public String style; + public Line outline; + public int color; + public int fadeScale; + public int blendColor; + public int blendScale; - public void update() { - super.update(); + public int outlineColor; + public float outlineWidth; - if (outline != null) - outline.update(); + public TextureItem texture; + + public AreaBuilder set(Area 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.outline = area.outline; + if (area.outline != null) { + this.outlineColor = outline.color; + this.outlineWidth = outline.width; + } else { + outlineColor = Color.TRANSPARENT; + outlineWidth = 1; + } + + 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.outlineColor = color; + this.outlineWidth = width; + return this; + } + + public AreaBuilder outlineColor(int color) { + this.outlineColor = color; + return this; + } + + public AreaBuilder outlineColor(String color) { + this.outlineColor = parseColor(color); + return this; + } + + public AreaBuilder outlineWidth(float width) { + this.outlineWidth = 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; + + outlineColor = Color.TRANSPARENT; + outlineWidth = 1; + + fadeScale = -1; + blendScale = -1; + blendColor = Color.TRANSPARENT; + style = null; + texture = null; + return this; + } + + public Area build() { + return new Area(this); + } } }