Add drawing track border by params

This commit is contained in:
cepprice 2021-04-18 13:23:10 +05:00
parent 8487444779
commit 15fb2b6774
2 changed files with 33 additions and 7 deletions

View file

@ -58,6 +58,7 @@ public class Renderable {
public static abstract class RenderableSegment { public static abstract class RenderableSegment {
protected static final int MIN_CULLER_ZOOM = 16; protected static final int MIN_CULLER_ZOOM = 16;
protected static final int BORDER_TYPE_ZOOM_THRESHOLD = MapTileLayer.DEFAULT_MAX_ZOOM + MapTileLayer.OVERZOOM_IN;
public List<WptPt> points = null; // Original list of points public List<WptPt> points = null; // Original list of points
protected List<WptPt> culled = new ArrayList<>(); // Reduced/resampled list of points protected List<WptPt> culled = new ArrayList<>(); // Reduced/resampled list of points
@ -70,6 +71,7 @@ public class Renderable {
protected Paint paint = null; // MUST be set by 'updateLocalPaint' before use protected Paint paint = null; // MUST be set by 'updateLocalPaint' before use
protected Paint borderPaint; protected Paint borderPaint;
protected GradientScaleType scaleType = null; protected GradientScaleType scaleType = null;
protected boolean drawBorder = false;
protected GpxGeometryWay geometryWay; protected GpxGeometryWay geometryWay;
@ -101,6 +103,10 @@ public class Renderable {
this.scaleType = type; this.scaleType = type;
} }
public void shouldDrawBorder(boolean drawBorder) {
this.drawBorder = drawBorder;
}
public GpxGeometryWay getGeometryWay() { public GpxGeometryWay getGeometryWay() {
return geometryWay; return geometryWay;
} }
@ -119,8 +125,10 @@ public class Renderable {
updateLocalPaint(p); updateLocalPaint(p);
canvas.rotate(-tileBox.getRotate(), tileBox.getCenterPixelX(), tileBox.getCenterPixelY()); canvas.rotate(-tileBox.getRotate(), tileBox.getCenterPixelX(), tileBox.getCenterPixelY());
if (scaleType != null) { if (scaleType != null) {
if (drawBorder && zoom < BORDER_TYPE_ZOOM_THRESHOLD) {
drawSolid(points, borderPaint, canvas, tileBox); drawSolid(points, borderPaint, canvas, tileBox);
drawGradient(points, paint, canvas, tileBox); }
drawGradient(zoom, points, paint, canvas, tileBox);
} else { } else {
drawSolid(getPointsForDrawing(), paint, canvas, tileBox); drawSolid(getPointsForDrawing(), paint, canvas, tileBox);
} }
@ -186,8 +194,9 @@ public class Renderable {
} }
} }
protected void drawGradient(List<WptPt> pts, Paint p, Canvas canvas, RotatedTileBox tileBox) { protected void drawGradient(double zoom, List<WptPt> pts, Paint p, Canvas canvas, RotatedTileBox tileBox) {
QuadRect tileBounds = tileBox.getLatLonBounds(); QuadRect tileBounds = tileBox.getLatLonBounds();
boolean drawSegmentBorder = drawBorder && zoom >= BORDER_TYPE_ZOOM_THRESHOLD;
Path path = new Path(); Path path = new Path();
boolean recalculateLastXY = true; boolean recalculateLastXY = true;
WptPt lastPt = pts.get(0); WptPt lastPt = pts.get(0);
@ -196,6 +205,9 @@ public class Renderable {
List<Integer> gradientColors = new ArrayList<>(); List<Integer> gradientColors = new ArrayList<>();
float gradientAngle = 0; float gradientAngle = 0;
List<Path> paths = new ArrayList<>();
List<LinearGradient> gradients = new ArrayList<>();
for (int i = 1; i < pts.size(); i++) { for (int i = 1; i < pts.size(); i++) {
WptPt pt = pts.get(i); WptPt pt = pts.get(i);
WptPt nextPt = i + 1 < pts.size() ? pts.get(i + 1) : null; WptPt nextPt = i + 1 < pts.size() ? pts.get(i + 1) : null;
@ -209,8 +221,8 @@ public class Renderable {
lastX = tileBox.getPixXFromLatLon(lastPt.lat, lastPt.lon); lastX = tileBox.getPixXFromLatLon(lastPt.lat, lastPt.lon);
lastY = tileBox.getPixYFromLatLon(lastPt.lat, lastPt.lon); lastY = tileBox.getPixYFromLatLon(lastPt.lat, lastPt.lon);
if (!path.isEmpty()) { if (!path.isEmpty()) {
p.setShader(createGradient(gradientPoints, gradientColors)); paths.add(new Path(path));
canvas.drawPath(path, p); gradients.add(createGradient(gradientPoints, gradientColors));
} }
path.reset(); path.reset();
path.moveTo(lastX, lastY); path.moveTo(lastX, lastY);
@ -241,8 +253,21 @@ public class Renderable {
lastPt = pt; lastPt = pt;
} }
if (!path.isEmpty()) { if (!path.isEmpty()) {
p.setShader(createGradient(gradientPoints, gradientColors)); paths.add(new Path(path));
canvas.drawPath(path, p); gradients.add(createGradient(gradientPoints, gradientColors));
}
if (!paths.isEmpty()) {
if (drawSegmentBorder) {
canvas.drawPath(paths.get(0), borderPaint);
}
for (int i = 0; i < paths.size(); i++) {
if (drawSegmentBorder && i + 1 < paths.size()) {
canvas.drawPath(paths.get(i + 1), borderPaint);
}
p.setShader(gradients.get(i));
canvas.drawPath(paths.get(i), p);
}
} }
} }

View file

@ -721,6 +721,7 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
Renderable.RenderableSegment renderableSegment = (Renderable.RenderableSegment) ts.renderer; Renderable.RenderableSegment renderableSegment = (Renderable.RenderableSegment) ts.renderer;
renderableSegment.setBorderPaint(borderPaint); renderableSegment.setBorderPaint(borderPaint);
renderableSegment.setGradientScaleType(scaleType); renderableSegment.setGradientScaleType(scaleType);
renderableSegment.shouldDrawBorder(true);
renderableSegment.drawSegment(view.getZoom(), paint, canvas, tileBox); renderableSegment.drawSegment(view.getZoom(), paint, canvas, tileBox);
} }
} }