Render themes: text background color (highway shields)

This commit is contained in:
Emux
2019-08-04 18:36:52 +03:00
parent e6137163b9
commit dcb7b0d10c
12 changed files with 59 additions and 12 deletions

View File

@@ -1,5 +1,6 @@
/*
* Copyright 2012 Hannes Janetzek
* Copyright 2019 devemux86
*
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
*
@@ -89,7 +90,7 @@ public class TextBucket extends TextureBucket {
int advanceY = 0;
float x = 0;
float y = 0;
float yy;
float xx, yy;
TextureItem t = pool.get();
textures = t;
@@ -127,14 +128,18 @@ public class TextBucket extends TextureBucket {
}
}
xx = x + mFontPadX;
yy = y + height - it.text.fontDescent;
mCanvas.drawText(it.label, x, yy, it.text.paint, it.text.stroke);
// FIXME !!!
if (width > TEXTURE_WIDTH)
width = TEXTURE_WIDTH;
if (it.text.bgFill != null)
mCanvas.fillRectangle(x + mFontPadX, y + 1, width - 2 * mFontPadX, height, it.text.bgFill.getColor());
mCanvas.drawText(it.label, xx, yy, it.text.paint, it.text.stroke);
while (it != null) {
addItem(it, width, height, x, y);

View File

@@ -1012,6 +1012,9 @@ public class XmlThemeBuilder extends DefaultHandler {
else if ("size".equals(name) || "font-size".equals(name))
b.fontSize = Float.parseFloat(value);
else if ("bg-fill".equals(name))
b.bgFillColor = Color.parseColor(value);
else if ("fill".equals(name))
b.fillColor = Color.parseColor(value);

View File

@@ -26,6 +26,8 @@ import org.oscim.backend.canvas.Paint.FontFamily;
import org.oscim.backend.canvas.Paint.FontStyle;
import org.oscim.renderer.atlas.TextureRegion;
import static org.oscim.backend.canvas.Color.parseColor;
public final class TextStyle extends RenderStyle<TextStyle> {
public static class TextBuilder<T extends TextBuilder<T>> extends StyleBuilder<T> {
@@ -46,6 +48,8 @@ public final class TextStyle extends RenderStyle<TextStyle> {
public int symbolHeight;
public int symbolPercent;
public int bgFillColor;
public T reset() {
cat = null;
fontFamily = FontFamily.DEFAULT;
@@ -67,6 +71,8 @@ public final class TextStyle extends RenderStyle<TextStyle> {
symbolHeight = 0;
symbolPercent = 100;
bgFillColor = Color.TRANSPARENT;
return self();
}
@@ -151,6 +157,16 @@ public final class TextStyle extends RenderStyle<TextStyle> {
return self();
}
public T bgFillColor(int color) {
this.bgFillColor = color;
return self();
}
public T bgFillColor(String color) {
this.bgFillColor = parseColor(color);
return self();
}
public T from(TextBuilder<?> other) {
cat = other.cat;
fontFamily = other.fontFamily;
@@ -172,6 +188,8 @@ public final class TextStyle extends RenderStyle<TextStyle> {
symbolHeight = other.symbolHeight;
symbolPercent = other.symbolPercent;
bgFillColor = other.bgFillColor;
return self();
}
@@ -201,6 +219,9 @@ public final class TextStyle extends RenderStyle<TextStyle> {
this.symbolHeight = text.symbolHeight;
this.symbolPercent = text.symbolPercent;
if (text.bgFill != null)
this.bgFillColor = themeCallback != null ? themeCallback.getColor(text, text.bgFill.getColor()) : text.bgFill.getColor();
return self();
}
}
@@ -241,6 +262,12 @@ public final class TextStyle extends RenderStyle<TextStyle> {
this.symbolWidth = b.symbolWidth;
this.symbolHeight = b.symbolHeight;
this.symbolPercent = b.symbolPercent;
if (b.bgFillColor != Color.TRANSPARENT) {
bgFill = CanvasAdapter.newPaint();
bgFill.setColor(b.themeCallback != null ? b.themeCallback.getColor(this, b.bgFillColor) : b.bgFillColor);
} else
bgFill = null;
}
public final String style;
@@ -267,6 +294,8 @@ public final class TextStyle extends RenderStyle<TextStyle> {
public final int symbolHeight;
public final int symbolPercent;
public final Paint bgFill;
@Override
public void dispose() {
if (bitmap != null)