start to make line stipple themeable

This commit is contained in:
Hannes Janetzek
2013-02-23 02:02:11 +01:00
parent 87ea877705
commit d91ad535a2
7 changed files with 246 additions and 182 deletions

View File

@@ -47,24 +47,40 @@ public final class Line extends RenderInstruction {
*/
public static Line create(Line line, String elementName, Attributes attributes,
int level, boolean isOutline) {
String src = null;
int stroke = Color.BLACK;
float strokeWidth = 0;
int stipple = 0;
Cap strokeLinecap = Cap.ROUND;
// Style name
String style = null;
// Bitmap
//String src = null;
float width = 0;
Cap cap = Cap.ROUND;
// Extras
int fade = -1;
boolean fixed = false;
String style = null;
float blur = 0;
float min = 0;
// Stipple
int stipple = 0;
float stippleWidth = 0;
float[] color = null;
float[] stippleColor = null;
if (line != null) {
color = line.color;
fixed = line.fixed;
fade = line.fade;
strokeLinecap = line.cap;
cap = line.cap;
blur = line.blur;
min = line.min;
stipple = line.stipple;
stippleColor = line.stippleColor;
stippleWidth = line.stippleWidth;
}
for (int i = 0; i < attributes.getLength(); ++i) {
String name = attributes.getLocalName(i);
String value = attributes.getValue(i);
@@ -72,21 +88,27 @@ public final class Line extends RenderInstruction {
if ("name".equals(name))
style = value;
else if ("src".equals(name)) {
src = value;
//src = value;
} else if ("stroke".equals(name)) {
stroke = Color.parseColor(value);
int stroke = Color.parseColor(value);
color = GlUtils.colorToFloatP(stroke);
} else if ("width".equals(name)) {
strokeWidth = Float.parseFloat(value);
width = Float.parseFloat(value);
} else if ("cap".equals(name)) {
cap = Cap.valueOf(value.toUpperCase(Locale.ENGLISH));
} else if ("fixed".equals(name)) {
fixed = Boolean.parseBoolean(value);
} else if ("stipple".equals(name)) {
stipple = Integer.parseInt(value);
} else if ("cap".equals(name)) {
strokeLinecap = Cap.valueOf(value.toUpperCase(Locale.ENGLISH));
} else if ("stipple-stroke".equals(name)) {
int stroke = Color.parseColor(value);
stippleColor = GlUtils.colorToFloatP(stroke);
} else if ("stipple-width".equals(name)) {
stippleWidth = Float.parseFloat(value);
} else if ("fade".equals(name)) {
fade = Integer.parseInt(value);
} else if ("min".equals(name)) {
min = Float.parseFloat(value);
} else if ("fixed".equals(name)) {
fixed = Boolean.parseBoolean(value);
} else if ("blur".equals(name)) {
blur = Float.parseFloat(value);
} else if ("from".equals(name)) {
@@ -95,38 +117,27 @@ public final class Line extends RenderInstruction {
}
}
if (stipple != 0)
strokeLinecap = Cap.BUTT;
// hint that sth is missing
if (color == null)
color = GlUtils.colorToFloatP(Color.RED);
if (stipple != 0 && stippleColor == null)
stippleColor = GlUtils.colorToFloatP(Color.GREEN);
// inherit properties from 'line'
if (line != null) {
// use stroke width relative to 'line'
width = line.width + width;
if (width <= 0)
width = 1;
strokeWidth = line.width + strokeWidth;
if (strokeWidth <= 0)
strokeWidth = 1;
return new Line(line, style, src, stroke, strokeWidth, stipple,
strokeLinecap, level, fixed, fade, blur, isOutline, min);
} else if (!isOutline) {
validate(width);
}
if (!isOutline)
validate(strokeWidth);
return new Line(style, src, stroke, strokeWidth, stipple, strokeLinecap,
level, fixed, fade, blur, isOutline, min);
}
public Line(int stroke, float width, Cap cap) {
this.level = 0;
this.blur = 0;
this.cap = cap;
this.outline = false;
this.style = "";
this.width = width;
this.fixed = true;
this.fade = -1;
this.stipple = 2;
this.min = 0;
color = GlUtils.colorToFloatP(stroke);
return new Line(level, style, color, width, cap, fixed,
stipple, stippleColor, stippleWidth,
fade, blur, isOutline, min);
}
private static void validate(float strokeWidth) {
@@ -147,59 +158,28 @@ public final class Line extends RenderInstruction {
private final int level;
public final float width;
// public final boolean round;
public final float color[];
public final boolean outline;
public final boolean fixed;
public final int fade;
public final String style;
public final float width;
public final float[] color;
public final Cap cap;
public final boolean outline;
public final boolean fixed;
public final int fade;
public final float blur;
public final int stipple;
public final float min;
/**
* @param style
* ...
* @param src
* ...
* @param stroke
* ...
* @param strokeWidth
* ...
* @param stipple
* ...
* @param strokeLinecap
* ...
* @param level
* ...
* @param fixed
* ...
* @param fade
* ...
* @param blur
* ...
* @param isOutline
* ...
* @param min ...
*/
private Line(String style, String src, int stroke, float strokeWidth,
int stipple, Cap strokeLinecap, int level, boolean fixed,
int fade, float blur, boolean isOutline, float min) {
super();
public final int stipple;
public final float[] stippleColor;
public final float stippleWidth;
private Line(int level, String style, float[] stroke, float width,
Cap cap, boolean fixed,
int stipple, float[] stippleColor, float stippleWidth,
int fade, float blur, boolean isOutline, float min) {
this.level = level;
this.style = style;
this.outline = isOutline;
// paint = new Paint(Paint.ANTI_ALIAS_FLAG);
//
@@ -213,51 +193,55 @@ public final class Line extends RenderInstruction {
// if (strokeDasharray != null) {
// paint.setPathEffect(new DashPathEffect(strokeDasharray, 0));
// }
// paint.setStrokeCap(strokeLinecap);
// round = (strokeLinecap == Cap.ROUND);
this.cap = strokeLinecap;
color = GlUtils.colorToFloatP(stroke);
this.width = strokeWidth;
this.level = level;
this.outline = isOutline;
this.cap = cap;
this.color = stroke;
this.width = width;
this.fixed = fixed;
this.stipple = stipple;
this.stippleColor = stippleColor;
this.stippleWidth = stippleWidth;
this.blur = blur;
this.fade = fade;
this.stipple = stipple;
this.min = min;
}
public Line(int stroke, float width, Cap cap) {
this.level = 0;
this.blur = 0;
this.cap = cap;
this.outline = false;
this.style = "";
this.width = width;
this.fixed = true;
this.fade = -1;
this.stipple = 0;
this.stippleColor = null;
this.stippleWidth = 0;
this.min = 0;
this.color = GlUtils.colorToFloatP(stroke);
}
private Line(Line line, String style, String src, int stroke, float strokeWidth,
int stipple, Cap strokeLinecap, int level, boolean fixed,
int fade, float blur, boolean isOutline, float min) {
super();
this.style = style;
// round = (strokeLinecap == Cap.ROUND);
color = line.color;
this.width = strokeWidth;
this.level = level;
this.outline = isOutline;
this.fixed = fixed;
this.fade = fade;
this.cap = strokeLinecap;
this.blur = blur;
public Line(int stroke, float width, int stipple) {
this.level = 0;
this.blur = 0;
this.cap = Cap.BUTT;
this.outline = false;
this.style = "";
this.width = width;
this.fixed = true;
this.fade = -1;
this.stipple = stipple;
this.min = min;
this.stippleColor = null;
this.stippleWidth = 0;
this.min = 0;
color = GlUtils.colorToFloatP(stroke);
}
@Override
public void renderWay(IRenderCallback renderCallback, Tag[] tags) {
// renderCallback.renderWay(mPaint, mLevel, mColor, mStrokeWidth,
// mRound, mOutline);
renderCallback.renderWay(this, level);
}
@@ -266,7 +250,5 @@ public final class Line extends RenderInstruction {
// paint.setStrokeWidth(strokeWidth * scaleFactor);
// }
public int getLevel() {
return this.level;
}
}

View File

@@ -56,7 +56,12 @@
<style-line name="highway-service" from="residential" width="-0.6" />
<!-- track|footway|path|cycleway -->
<style-line name="footway" stroke="#c1bcb6" width="1.2" cap="butt" fixed="true"/>
<style-line name="footway" stroke="#aaffffff" width="1.8" cap="butt" fixed="true"
stipple="16" stipple-width="0.6" stipple-stroke="#cd7750"/>
<style-line name="highway:cycleway" from="footway" width="0.1" stipple-stroke="#4040ee"/>
<style-line name="highway:track" from="footway" width="0.1" stipple="10" stipple-stroke="#c3bb88"/>
<style-line name="highway:path" from="footway" width="0.1" stipple="10" stipple-stroke="#837b58"/>
<!-- <style-line name="footway:z16" from="footway" width="-0.95" fixed="false" fade="-1"/>-->
<style-line name="footway:z17" stroke="#faf8f5" width="0.3"/>
@@ -377,10 +382,22 @@
</rule>
<rule e="way" k="*" v="*" zoom-min="14">
<rule e="way" k="*" v="track|footway|path|cycleway" zoom-max="16">
<rule e="way" k="*" v="footway" zoom-max="16">
<use-line name="footway"/>
</rule>
<rule e="way" k="*" v="cycleway" zoom-max="16">
<use-line name="highway:cycleway"/>
</rule>
<rule e="way" k="*" v="track" zoom-max="16">
<use-line name="highway:track"/>
</rule>
<rule e="way" k="*" v="path" zoom-max="16">
<use-line name="highway:path"/>
</rule>
<rule e="way" k="*" v="bridleway">
<use-line name="bridleway"/>
</rule>
@@ -604,10 +621,22 @@
</rule>
<rule e="way" k="*" v="*" zoom-min="14">
<rule e="way" k="*" v="track|footway|path|cycleway" zoom-max="16">
<rule e="way" k="*" v="footway" zoom-max="16">
<use-line name="footway"/>
</rule>
<rule e="way" k="*" v="cycleway" zoom-max="16">
<use-line name="highway:cycleway"/>
</rule>
<rule e="way" k="*" v="track" zoom-max="16">
<use-line name="highway:track"/>
</rule>
<rule e="way" k="*" v="path" zoom-max="16">
<use-line name="highway:path"/>
</rule>
<rule e="way" k="*" v="bridleway">
<use-line name="bridleway"/>
</rule>
@@ -704,10 +733,18 @@
</rule>
<rule e="way" k="*" v="*" zoom-min="14">
<rule e="way" k="*" v="track|footway|path|cycleway" zoom-max="15">
<rule e="way" k="*" v="footway" zoom-max="15">
<use-line name="footway"/>
</rule>
<rule e="way" k="*" v="cycleway" zoom-max="16">
<use-line name="highway:cycleway"/>
</rule>
<rule e="way" k="*" v="track" zoom-max="16">
<use-line name="highway:track"/>
</rule>
<rule e="way" k="*" v="path" zoom-max="16">
<use-line name="highway:path"/>
</rule>
<rule e="way" k="*" v="bridleway">
<use-line name="bridleway"/>
</rule>
@@ -882,7 +919,8 @@
</rule>
<rule e="way" k="railway" v="rail|turntable" zoom-min="15">
<line stroke="#ddaa9988" width="2.0" cap="butt" fixed="true" fade="12" stipple="1"/>
<line stroke="#ddaa9988" width="2.0" cap="butt" fixed="true" fade="12"
stipple="4" stipple-width="0.7" stipple-stroke="#ffffff"/>
</rule>
<!-- <rule e="way" k="railway" v="rail" zoom-max="14" zoom-min="13">