Fix icons rendering
This commit is contained in:
parent
8d67b70a8e
commit
963abd78fd
6 changed files with 29 additions and 29 deletions
|
@ -46,6 +46,7 @@ public class RenderingContext {
|
|||
public int lastRenderedKey = 0;
|
||||
|
||||
// be aware field is using in C++
|
||||
public float screenDensityRatio = 1;
|
||||
public int shadowRenderingMode = ShadowRenderingMode.BLUR_SHADOW.value;
|
||||
public int shadowRenderingColor = 0xff969696;
|
||||
public String renderingDebugInfo;
|
||||
|
|
|
@ -568,6 +568,7 @@ public class MapRenderRepositories {
|
|||
currentRenderingContext.nightMode = nightMode;
|
||||
currentRenderingContext.useEnglishNames = prefs.USE_ENGLISH_NAMES.get();
|
||||
currentRenderingContext.setDensityValue(mapDensity);
|
||||
currentRenderingContext.screenDensityRatio = mapDensity / Math.max(1, requestedBox.getDensity()) ;
|
||||
// init rendering context
|
||||
currentRenderingContext.tileDivisor = tileDivisor;
|
||||
if (checkWhetherInterrupted()) {
|
||||
|
|
|
@ -32,6 +32,8 @@ import android.graphics.Canvas;
|
|||
import android.graphics.ColorFilter;
|
||||
import android.graphics.DashPathEffect;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.Paint.Cap;
|
||||
import android.graphics.Paint.Style;
|
||||
import android.graphics.Path;
|
||||
|
@ -301,7 +303,7 @@ public class OsmandRenderer {
|
|||
int[] alreadyDrawnIcons = new int[iconsW * iconsH / 32];
|
||||
for (IconDrawInfo icon : rc.iconsToDraw) {
|
||||
if (icon.resId != null) {
|
||||
Bitmap ico = RenderingIcons.getSmallPoiIcon(context, icon.resId);
|
||||
Bitmap ico = RenderingIcons.getIcon(context, icon.resId);
|
||||
if (ico != null) {
|
||||
if (icon.y >= 0 && icon.y < rc.height && icon.x >= 0 && icon.x < rc.width) {
|
||||
int z = (((int) icon.x / skewConstant) + ((int) icon.y / skewConstant) * iconsW);
|
||||
|
@ -314,8 +316,17 @@ public class OsmandRenderer {
|
|||
// check bit b if it is set
|
||||
if (((ind >> b) & 1) == 0) {
|
||||
alreadyDrawnIcons[i] = ind | (1 << b);
|
||||
cv.drawBitmap(ico, icon.x - ico.getWidth() / 2,
|
||||
icon.y - ico.getHeight() / 2, paintIcon);
|
||||
float left = icon.x - ico.getWidth() / 2 * rc.screenDensityRatio;
|
||||
float top = icon.y - ico.getHeight() / 2 * rc.screenDensityRatio;
|
||||
if(rc.screenDensityRatio != 1f){
|
||||
RectF rf = new RectF(left, top, left + ico.getWidth() * rc.screenDensityRatio ,
|
||||
top + ico.getHeight() * rc.screenDensityRatio);
|
||||
Rect src = new Rect(0, 0, ico.getWidth(), ico
|
||||
.getHeight());
|
||||
cv.drawBitmap(ico, src, rf, paintIcon);
|
||||
} else {
|
||||
cv.drawBitmap(ico, left, top, paintIcon);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -564,7 +575,6 @@ public class OsmandRenderer {
|
|||
if (shadowColor == 0) {
|
||||
shadowRadius = 0;
|
||||
}
|
||||
System.out.println("Shadow radius " + shadowRadius);
|
||||
p.setShadowLayer(shadowRadius, 0, 0, shadowColor);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,8 +16,6 @@ import android.content.Context;
|
|||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.WindowManager;
|
||||
|
||||
public class RenderingIcons {
|
||||
private static final Log log = PlatformUtil.getLog(RenderingIcons.class);
|
||||
|
@ -26,7 +24,7 @@ public class RenderingIcons {
|
|||
private static Map<String, Integer> smallIcons = new LinkedHashMap<String, Integer>();
|
||||
private static Map<String, Integer> bigIcons = new LinkedHashMap<String, Integer>();
|
||||
private static Map<String, Bitmap> iconsBmp = new LinkedHashMap<String, Bitmap>();
|
||||
private static DisplayMetrics dm;
|
||||
// private static DisplayMetrics dm;
|
||||
|
||||
public static boolean containsIcon(String s){
|
||||
return icons.containsKey(s);
|
||||
|
@ -83,29 +81,11 @@ public class RenderingIcons {
|
|||
return null;
|
||||
}
|
||||
|
||||
public static Bitmap getSmallPoiIcon(Context ctx, String s) {
|
||||
Integer resId = smallIcons.get(s);
|
||||
if (resId != null) {
|
||||
return BitmapFactory.decodeResource(ctx.getResources(), resId, null);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Bitmap getIcon(Context ctx, String s) {
|
||||
if (!iconsBmp.containsKey(s)) {
|
||||
Integer resId = icons.get(s);
|
||||
if (resId != null) {
|
||||
if (dm == null) {
|
||||
dm = new DisplayMetrics();
|
||||
WindowManager wmgr = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
|
||||
wmgr.getDefaultDisplay().getMetrics(dm);
|
||||
}
|
||||
// BitmapFactory.Options options = new BitmapFactory.Options();
|
||||
// options.inScaled = false;
|
||||
// options.inTargetDensity = dm.densityDpi;
|
||||
// options.inDensity = dm.densityDpi;
|
||||
Bitmap bmp = BitmapFactory.decodeResource(ctx.getResources(), resId, null);
|
||||
// Bitmap bmp = UnscaledBitmapLoader.loadFromResource(ctx.getResources(), resId.intValue(), null, dm);
|
||||
iconsBmp.put(s, bmp);
|
||||
} else {
|
||||
iconsBmp.put(s, null);
|
||||
|
|
|
@ -242,13 +242,21 @@ public class TextRenderer {
|
|||
if (text.shieldRes != null) {
|
||||
Bitmap ico = RenderingIcons.getIcon(context, text.shieldRes);
|
||||
if (ico != null) {
|
||||
float left = text.centerX - ico.getWidth() / 2
|
||||
float left = text.centerX - ico.getWidth() / 2 * rc.screenDensityRatio
|
||||
- 0.5f;
|
||||
float top = text.centerY - ico.getHeight() / 2
|
||||
float top = text.centerY - ico.getHeight() / 2 * rc.screenDensityRatio
|
||||
- rc.getDensityValue(4.5f);
|
||||
if(rc.screenDensityRatio != 1f){
|
||||
RectF rf = new RectF(left, top, left + ico.getWidth() * rc.screenDensityRatio ,
|
||||
top + ico.getHeight() * rc.screenDensityRatio);
|
||||
Rect src = new Rect(0, 0, ico.getWidth(), ico
|
||||
.getHeight());
|
||||
cv.drawBitmap(ico, src, rf, paintIcon);
|
||||
} else {
|
||||
cv.drawBitmap(ico, left, top, paintIcon);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
drawWrappedText(cv, text, textSize);
|
||||
}
|
||||
|
|
|
@ -183,7 +183,7 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
|
|||
id = tag.toString();
|
||||
}
|
||||
if(id != null){
|
||||
Bitmap bmp = RenderingIcons.getSmallPoiIcon(view.getContext(), id);
|
||||
Bitmap bmp = RenderingIcons.getIcon(view.getContext(), id);
|
||||
if(bmp != null){
|
||||
canvas.drawBitmap(bmp, x - bmp.getWidth() / 2, y - bmp.getHeight() / 2, paintIcon);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue