From 4ab941be0ad7abf7d2dabe6b67c3e665c537288f Mon Sep 17 00:00:00 2001 From: Andrey Novikov Date: Wed, 13 Mar 2024 22:57:52 +0300 Subject: [PATCH] VTM: Render theme callback improvements --- .../java/org/oscim/theme/ThemeCallback.java | 6 ++++-- .../java/org/oscim/theme/XmlThemeBuilder.java | 2 +- .../java/org/oscim/theme/styles/AreaStyle.java | 17 +++++++++-------- .../org/oscim/theme/styles/CircleStyle.java | 10 +++++----- .../org/oscim/theme/styles/ExtrusionStyle.java | 12 ++++++------ .../java/org/oscim/theme/styles/LineStyle.java | 8 ++++---- .../java/org/oscim/theme/styles/TextStyle.java | 10 +++++----- 7 files changed, 34 insertions(+), 31 deletions(-) diff --git a/app/src/main/java/org/oscim/theme/ThemeCallback.java b/app/src/main/java/org/oscim/theme/ThemeCallback.java index 617d68eb..256fe6f5 100644 --- a/app/src/main/java/org/oscim/theme/ThemeCallback.java +++ b/app/src/main/java/org/oscim/theme/ThemeCallback.java @@ -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 @@ -14,6 +14,8 @@ */ package org.oscim.theme; +import org.oscim.theme.styles.RenderStyle; + /** * Callback methods for render theme. */ @@ -21,5 +23,5 @@ public interface ThemeCallback { /** * @return the color-int */ - int getColor(int color); + int getColor(RenderStyle origin, int color); } diff --git a/app/src/main/java/org/oscim/theme/XmlThemeBuilder.java b/app/src/main/java/org/oscim/theme/XmlThemeBuilder.java index 04a73740..e8c47e0b 100644 --- a/app/src/main/java/org/oscim/theme/XmlThemeBuilder.java +++ b/app/src/main/java/org/oscim/theme/XmlThemeBuilder.java @@ -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); diff --git a/app/src/main/java/org/oscim/theme/styles/AreaStyle.java b/app/src/main/java/org/oscim/theme/styles/AreaStyle.java index 9434936c..0cadbda4 100644 --- a/app/src/main/java/org/oscim/theme/styles/AreaStyle.java +++ b/app/src/main/java/org/oscim/theme/styles/AreaStyle.java @@ -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). * @@ -24,7 +24,8 @@ import static org.oscim.backend.canvas.Color.parseColor; -/*TODO +/** + * TODO * - add custom shaders * - create distance field per tile? */ @@ -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; @@ -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; diff --git a/app/src/main/java/org/oscim/theme/styles/CircleStyle.java b/app/src/main/java/org/oscim/theme/styles/CircleStyle.java index 3b573b49..2e939b01 100644 --- a/app/src/main/java/org/oscim/theme/styles/CircleStyle.java +++ b/app/src/main/java/org/oscim/theme/styles/CircleStyle.java @@ -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). * @@ -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; } @@ -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; diff --git a/app/src/main/java/org/oscim/theme/styles/ExtrusionStyle.java b/app/src/main/java/org/oscim/theme/styles/ExtrusionStyle.java index 94786511..6a62d679 100644 --- a/app/src/main/java/org/oscim/theme/styles/ExtrusionStyle.java +++ b/app/src/main/java/org/oscim/theme/styles/ExtrusionStyle.java @@ -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); @@ -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; diff --git a/app/src/main/java/org/oscim/theme/styles/LineStyle.java b/app/src/main/java/org/oscim/theme/styles/LineStyle.java index c13db452..53123983 100644 --- a/app/src/main/java/org/oscim/theme/styles/LineStyle.java +++ b/app/src/main/java/org/oscim/theme/styles/LineStyle.java @@ -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; @@ -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; @@ -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; @@ -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; diff --git a/app/src/main/java/org/oscim/theme/styles/TextStyle.java b/app/src/main/java/org/oscim/theme/styles/TextStyle.java index 0fbf41ea..4aa8da8a 100644 --- a/app/src/main/java/org/oscim/theme/styles/TextStyle.java +++ b/app/src/main/java/org/oscim/theme/styles/TextStyle.java @@ -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). @@ -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; @@ -245,7 +245,7 @@ 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) { @@ -253,7 +253,7 @@ public TextBuilder set(TextStyle text) { 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;