Improved streetrendering with better shadows.

This commit is contained in:
seeebek 2011-10-06 07:14:11 +08:00 committed by Victor Shcherb
parent 81f58d03b0
commit bd1b80f6ea

View file

@ -25,6 +25,7 @@ import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BitmapShader;
import android.graphics.BlurMaskFilter;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.DashPathEffect;
@ -62,6 +63,8 @@ public class OsmandRenderer {
private Map<Integer, Bitmap> cachedIcons = new LinkedHashMap<Integer, Bitmap>();
private final Context context;
//for street shadows
private Canvas streetcv;
private DisplayMetrics dm;
@ -287,6 +290,12 @@ public class OsmandRenderer {
// fill area
Canvas cv = new Canvas(bmp);
//needed for better street shadows
Bitmap streetbmp = Bitmap.createBitmap(cv.getWidth(), cv.getHeight(), Bitmap.Config.ARGB_8888);
streetcv = new Canvas(streetbmp);
if(renderer != null){
int dc = renderer.getDefaultColor(rc.nightMode);
if(dc != 0){
@ -401,6 +410,10 @@ public class OsmandRenderer {
}
}
notifyListeners(notifyList);
//Draw streets here
drawStreetsWithShadow(cv, streetbmp);
drawTextOverCanvas(rc, cv, useEnglishNames);
long time = System.currentTimeMillis() - now;
rc.renderingDebugInfo = String.format("Rendering done in %s (%s text) ms\n" +
@ -412,6 +425,18 @@ public class OsmandRenderer {
return bmp;
}
// Draw nice shadow under all streets
//but also other linear objects which is not very good
private void drawStreetsWithShadow(Canvas cv, Bitmap streetbmp){
Paint shadowpaint = new Paint();
shadowpaint.setColor(Color.BLACK);
shadowpaint.setMaskFilter(new BlurMaskFilter(1, BlurMaskFilter.Blur.SOLID));
Bitmap shadowImage = streetbmp.extractAlpha();
cv.drawBitmap(shadowImage, 0, 0, shadowpaint);// <----
cv.drawBitmap(streetbmp, 0, 0, null);
}
private void notifyListeners(List<IMapDownloaderCallback> notifyList) {
if (notifyList != null) {
@ -890,6 +915,8 @@ public class OsmandRenderer {
private void drawPolyline(BinaryMapDataObject obj, BaseOsmandRender render, Canvas canvas, RenderingContext rc, TagValuePair pair, int layer) {
if(render == null || pair == null){
return;
@ -954,19 +981,21 @@ public class OsmandRenderer {
}
if (path != null) {
rc.main.updatePaint(paint);
canvas.drawPath(path, paint);
//changed canvas to the global one for streets
streetcv.drawPath(path, paint);
if (rc.second.strokeWidth != 0) {
rc.second.updatePaint(paint);
canvas.drawPath(path, paint);
streetcv.drawPath(path, paint);
if (rc.third.strokeWidth != 0) {
rc.third.updatePaint(paint);
canvas.drawPath(path, paint);
streetcv.drawPath(path, paint);
}
}
if (rc.adds != null) {
for (int i = 0; i < rc.adds.length; i++) {
rc.adds[i].updatePaint(paint);
canvas.drawPath(path, paint);
streetcv.drawPath(path, paint);
}
}
if (obj.getName() != null && obj.getName().length() > 0) {
@ -1032,6 +1061,11 @@ public class OsmandRenderer {
}
}
}
private static RenderingPaintProperties[] oneWay = null;
public static RenderingPaintProperties[] getOneWayProperties(){
if(oneWay == null){