Skip to content

Commit

Permalink
VTM: Render theme callback improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
andreynovikov committed Dec 21, 2024
1 parent 6341e50 commit 4ab941b
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 31 deletions.
6 changes: 4 additions & 2 deletions app/src/main/java/org/oscim/theme/ThemeCallback.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016 devemux86
* Copyright 2016-2019 devemux86
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
Expand All @@ -14,12 +14,14 @@
*/
package org.oscim.theme;

import org.oscim.theme.styles.RenderStyle;

/**
* Callback methods for render theme.
*/
public interface ThemeCallback {
/**
* @return the color-int
*/
int getColor(int color);
int getColor(RenderStyle origin, int color);
}
2 changes: 1 addition & 1 deletion app/src/main/java/org/oscim/theme/XmlThemeBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,7 @@ private void createRenderTheme(String elementName, Attributes attributes) {
else if ("map-background".equals(name)) {
mapBackground = parseColor(value);
if (mThemeCallback != null)
mapBackground = mThemeCallback.getColor(mapBackground);
mapBackground = mThemeCallback.getColor(null, mapBackground);

} else if ("base-stroke-width".equals(name))
baseStrokeWidth = Float.parseFloat(value);
Expand Down
17 changes: 9 additions & 8 deletions app/src/main/java/org/oscim/theme/styles/AreaStyle.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
* Copyright 2014 Hannes Janetzek
* Copyright 2016-2017 devemux86
* Copyright 2016-2019 devemux86
*
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
*
Expand All @@ -24,7 +24,8 @@

import static org.oscim.backend.canvas.Color.parseColor;

/*TODO
/**
* TODO
* - add custom shaders
* - create distance field per tile?
*/
Expand Down Expand Up @@ -114,11 +115,11 @@ public AreaStyle(AreaBuilder<?> b) {
this.level = b.level;
this.style = b.style;
this.fadeScale = b.fadeScale;
this.blendColor = b.themeCallback != null ? b.themeCallback.getColor(b.blendColor) : b.blendColor;
this.blendColor = b.themeCallback != null ? b.themeCallback.getColor(this, b.blendColor) : b.blendColor;
this.blendScale = b.blendScale;
this.color = b.themeCallback != null ? b.themeCallback.getColor(b.fillColor) : b.fillColor;
this.color = b.themeCallback != null ? b.themeCallback.getColor(this, b.fillColor) : b.fillColor;
this.texture = b.texture;
this.strokeColor = b.themeCallback != null ? b.themeCallback.getColor(b.strokeColor) : b.strokeColor;
this.strokeColor = b.themeCallback != null ? b.themeCallback.getColor(this, b.strokeColor) : b.strokeColor;
this.strokeWidth = b.strokeWidth;
this.mesh = b.mesh;

Expand Down Expand Up @@ -204,11 +205,11 @@ public T set(AreaStyle area) {
this.level = area.level;
this.style = area.style;
this.fadeScale = area.fadeScale;
this.blendColor = themeCallback != null ? themeCallback.getColor(area.blendColor) : area.blendColor;
this.blendColor = themeCallback != null ? themeCallback.getColor(area, area.blendColor) : area.blendColor;
this.blendScale = area.blendScale;
this.fillColor = themeCallback != null ? themeCallback.getColor(area.color) : area.color;
this.fillColor = themeCallback != null ? themeCallback.getColor(area, area.color) : area.color;
this.texture = area.texture;
this.strokeColor = themeCallback != null ? themeCallback.getColor(area.strokeColor) : area.strokeColor;
this.strokeColor = themeCallback != null ? themeCallback.getColor(area, area.strokeColor) : area.strokeColor;
this.strokeWidth = area.strokeWidth;
this.mesh = area.mesh;

Expand Down
10 changes: 5 additions & 5 deletions app/src/main/java/org/oscim/theme/styles/CircleStyle.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
* Copyright 2013 Hannes Janetzek
* Copyright 2016 devemux86
* Copyright 2016-2019 devemux86
*
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
*
Expand Down Expand Up @@ -46,8 +46,8 @@ public CircleStyle(CircleBuilder<?> b) {
this.cat = b.cat;
this.radius = b.radius;
this.scaleRadius = b.scaleRadius;
this.fillColor = b.themeCallback != null ? b.themeCallback.getColor(b.fillColor) : b.fillColor;
this.strokeColor = b.themeCallback != null ? b.themeCallback.getColor(b.strokeColor) : b.strokeColor;
this.fillColor = b.themeCallback != null ? b.themeCallback.getColor(this, b.fillColor) : b.fillColor;
this.strokeColor = b.themeCallback != null ? b.themeCallback.getColor(this, b.strokeColor) : b.strokeColor;
this.strokeWidth = b.strokeWidth;
this.level = b.level;
}
Expand Down Expand Up @@ -76,8 +76,8 @@ public T set(CircleStyle circle) {

this.radius = circle.radius;
this.scaleRadius = circle.scaleRadius;
this.fillColor = themeCallback != null ? themeCallback.getColor(circle.fillColor) : circle.fillColor;
this.strokeColor = themeCallback != null ? themeCallback.getColor(circle.strokeColor) : circle.strokeColor;
this.fillColor = themeCallback != null ? themeCallback.getColor(circle, circle.fillColor) : circle.fillColor;
this.strokeColor = themeCallback != null ? themeCallback.getColor(circle, circle.strokeColor) : circle.strokeColor;
this.strokeWidth = circle.strokeWidth;
this.cat = circle.cat;
this.level = circle.level;
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/java/org/oscim/theme/styles/ExtrusionStyle.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ public ExtrusionStyle(ExtrusionBuilder<?> b) {
this.cat = b.cat;
this.level = b.level;

this.colorSide = b.themeCallback != null ? b.themeCallback.getColor(b.colorSide) : b.colorSide;
this.colorTop = b.themeCallback != null ? b.themeCallback.getColor(b.colorTop) : b.colorTop;
this.colorLine = b.themeCallback != null ? b.themeCallback.getColor(b.colorLine) : b.colorLine;
this.colorSide = b.themeCallback != null ? b.themeCallback.getColor(this, b.colorSide) : b.colorSide;
this.colorTop = b.themeCallback != null ? b.themeCallback.getColor(this, b.colorTop) : b.colorTop;
this.colorLine = b.themeCallback != null ? b.themeCallback.getColor(this, b.colorLine) : b.colorLine;
this.colors = new float[16];
fillColors(colorSide, colorTop, colorLine, colors);

Expand Down Expand Up @@ -129,9 +129,9 @@ public T set(ExtrusionStyle extrusion) {

this.cat = extrusion.cat;
this.level = extrusion.level;
this.colorSide = themeCallback != null ? themeCallback.getColor(extrusion.colorSide) : extrusion.colorSide;
this.colorTop = themeCallback != null ? themeCallback.getColor(extrusion.colorTop) : extrusion.colorTop;
this.colorLine = themeCallback != null ? themeCallback.getColor(extrusion.colorLine) : extrusion.colorLine;
this.colorSide = themeCallback != null ? themeCallback.getColor(extrusion, extrusion.colorSide) : extrusion.colorSide;
this.colorTop = themeCallback != null ? themeCallback.getColor(extrusion, extrusion.colorTop) : extrusion.colorTop;
this.colorLine = themeCallback != null ? themeCallback.getColor(extrusion, extrusion.colorLine) : extrusion.colorLine;
this.hsvHue = extrusion.hsv.hue;
this.hsvSaturation = extrusion.hsv.saturation;
this.hsvValue = extrusion.hsv.value;
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/org/oscim/theme/styles/LineStyle.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private LineStyle(LineBuilder<?> b) {
this.level = b.level;
this.style = b.style;
this.width = b.strokeWidth;
this.color = b.themeCallback != null ? b.themeCallback.getColor(b.fillColor) : b.fillColor;
this.color = b.themeCallback != null ? b.themeCallback.getColor(this, b.fillColor) : b.fillColor;
this.cap = b.cap;
this.outline = b.outline;
this.fixed = b.fixed;
Expand All @@ -132,7 +132,7 @@ private LineStyle(LineBuilder<?> b) {
this.fadeScale = b.fadeScale;
this.blur = b.blur;
this.stipple = b.stipple;
this.stippleColor = b.themeCallback != null ? b.themeCallback.getColor(b.stippleColor) : b.stippleColor;
this.stippleColor = b.themeCallback != null ? b.themeCallback.getColor(this, b.stippleColor) : b.stippleColor;
this.stippleWidth = b.stippleWidth;
this.stippleRatio = b.stippleRatio;
this.texture = b.texture;
Expand Down Expand Up @@ -201,7 +201,7 @@ public T set(LineStyle line) {
this.level = line.level;
this.style = line.style;
this.strokeWidth = line.width;
this.fillColor = themeCallback != null ? themeCallback.getColor(line.color) : line.color;
this.fillColor = themeCallback != null ? themeCallback.getColor(line, line.color) : line.color;
this.cap = line.cap;
this.outline = line.outline;
this.fixed = line.fixed;
Expand All @@ -210,7 +210,7 @@ public T set(LineStyle line) {
this.fadeScale = line.fadeScale;
this.blur = line.blur;
this.stipple = line.stipple;
this.stippleColor = themeCallback != null ? themeCallback.getColor(line.stippleColor) : line.stippleColor;
this.stippleColor = themeCallback != null ? themeCallback.getColor(line, line.stippleColor) : line.stippleColor;
this.stippleWidth = line.stippleWidth;
this.stippleRatio = line.stippleRatio;
this.texture = line.texture;
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/java/org/oscim/theme/styles/TextStyle.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright 2013 Hannes Janetzek
* Copyright 2016-2017 devemux86
* Copyright 2016-2019 devemux86
* Copyright 2016 Andrey Novikov
*
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
Expand Down Expand Up @@ -210,11 +210,11 @@ public TextBuilder<?> set(TextStyle text) {
this.areaSize = text.areaSize;
this.bitmap = text.bitmap;
this.texture = text.texture;
this.fillColor = themeCallback != null ? themeCallback.getColor(text.paint.getColor()) : text.paint.getColor();
this.fillColor = themeCallback != null ? themeCallback.getColor(text, text.paint.getColor()) : text.paint.getColor();
this.fontFamily = text.fontFamily;
this.fontStyle = text.fontStyle;
if (text.stroke != null) {
this.strokeColor = themeCallback != null ? themeCallback.getColor(text.stroke.getColor()) : text.stroke.getColor();
this.strokeColor = themeCallback != null ? themeCallback.getColor(text, text.stroke.getColor()) : text.stroke.getColor();
this.strokeWidth = text.stroke.getStrokeWidth();
}
this.fontSize = text.fontSize;
Expand Down Expand Up @@ -245,15 +245,15 @@ public TextBuilder<?> set(TextStyle text) {
paint.setTextAlign(Paint.Align.CENTER);
paint.setTypeface(b.fontFamily, b.fontStyle);

paint.setColor(b.themeCallback != null ? b.themeCallback.getColor(b.fillColor) : b.fillColor);
paint.setColor(b.themeCallback != null ? b.themeCallback.getColor(this, b.fillColor) : b.fillColor);
paint.setTextSize(b.fontSize);

if (b.strokeWidth > 0) {
stroke = CanvasAdapter.newPaint();
stroke.setStyle(Paint.Style.STROKE);
stroke.setTextAlign(Paint.Align.CENTER);
stroke.setTypeface(b.fontFamily, b.fontStyle);
stroke.setColor(b.themeCallback != null ? b.themeCallback.getColor(b.strokeColor) : b.strokeColor);
stroke.setColor(b.themeCallback != null ? b.themeCallback.getColor(this, b.strokeColor) : b.strokeColor);
stroke.setStrokeWidth(b.strokeWidth);
stroke.setTextSize(b.fontSize);
strokeWidth = b.strokeWidth;
Expand Down

0 comments on commit 4ab941b

Please sign in to comment.