Shader icons
This commit is contained in:
parent
30aac2ca1d
commit
970fdd45e1
4 changed files with 39 additions and 48 deletions
|
@ -156,7 +156,7 @@ public class OsmandRenderer {
|
||||||
public Shader getShader(String resId){
|
public Shader getShader(String resId){
|
||||||
|
|
||||||
if(shaders.get(resId) == null){
|
if(shaders.get(resId) == null){
|
||||||
Bitmap bmp = RenderingIcons.getIcon(context, resId);
|
Bitmap bmp = RenderingIcons.getIcon(context, resId, true);
|
||||||
if(bmp != null){
|
if(bmp != null){
|
||||||
Shader sh = new BitmapShader(bmp, TileMode.REPEAT, TileMode.REPEAT);
|
Shader sh = new BitmapShader(bmp, TileMode.REPEAT, TileMode.REPEAT);
|
||||||
shaders.put(resId, sh);
|
shaders.put(resId, sh);
|
||||||
|
@ -319,7 +319,7 @@ public class OsmandRenderer {
|
||||||
|
|
||||||
for (IconDrawInfo icon : rc.iconsToDraw) {
|
for (IconDrawInfo icon : rc.iconsToDraw) {
|
||||||
if (icon.resId != null) {
|
if (icon.resId != null) {
|
||||||
Bitmap ico = RenderingIcons.getIcon(context, icon.resId);
|
Bitmap ico = RenderingIcons.getIcon(context, icon.resId, true);
|
||||||
if (ico != null) {
|
if (ico != null) {
|
||||||
if (icon.y >= 0 && icon.y < rc.height && icon.x >= 0 && icon.x < rc.width) {
|
if (icon.y >= 0 && icon.y < rc.height && icon.x >= 0 && icon.x < rc.width) {
|
||||||
int visbleWidth = icon.iconSize >= 0 ? (int) icon.iconSize : ico.getWidth();
|
int visbleWidth = icon.iconSize >= 0 ? (int) icon.iconSize : ico.getWidth();
|
||||||
|
@ -340,7 +340,7 @@ public class OsmandRenderer {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!intersects) {
|
if (!intersects) {
|
||||||
Bitmap shield = icon.shieldId == null ? null : RenderingIcons.getIcon(context, icon.shieldId);
|
Bitmap shield = icon.shieldId == null ? null : RenderingIcons.getIcon(context, icon.shieldId, true);
|
||||||
if(shield != null) {
|
if(shield != null) {
|
||||||
RectF shieldRf = calculateRect(rc, icon, shield.getWidth(), shield.getHeight());
|
RectF shieldRf = calculateRect(rc, icon, shield.getWidth(), shield.getHeight());
|
||||||
if (coeff != 1f) {
|
if (coeff != 1f) {
|
||||||
|
@ -352,19 +352,19 @@ public class OsmandRenderer {
|
||||||
}
|
}
|
||||||
if (coeff != 1f) {
|
if (coeff != 1f) {
|
||||||
Rect src = new Rect(0, 0, ico.getWidth(), ico.getHeight());
|
Rect src = new Rect(0, 0, ico.getWidth(), ico.getHeight());
|
||||||
drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId_1), rf, src);
|
drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId_1, true), rf, src);
|
||||||
drawBitmap(cv, ico, rf, src);
|
drawBitmap(cv, ico, rf, src);
|
||||||
drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId2), rf, src);
|
drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId2, true), rf, src);
|
||||||
drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId3), rf, src);
|
drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId3, true), rf, src);
|
||||||
drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId4), rf, src);
|
drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId4, true), rf, src);
|
||||||
drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId5), rf, src);
|
drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId5, true), rf, src);
|
||||||
} else {
|
} else {
|
||||||
drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId_1), rf);
|
drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId_1, true), rf);
|
||||||
drawBitmap(cv, ico, rf);
|
drawBitmap(cv, ico, rf);
|
||||||
drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId2), rf);
|
drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId2, true), rf);
|
||||||
drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId3), rf);
|
drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId3, true), rf);
|
||||||
drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId4), rf);
|
drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId4, true), rf);
|
||||||
drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId5), rf);
|
drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId5, true), rf);
|
||||||
}
|
}
|
||||||
if(visibleRect != null) {
|
if(visibleRect != null) {
|
||||||
visibleRect.inset(-visibleRect.width() / 4, -visibleRect.height() / 4);
|
visibleRect.inset(-visibleRect.width() / 4, -visibleRect.height() / 4);
|
||||||
|
|
|
@ -20,14 +20,14 @@ import android.graphics.drawable.Drawable;
|
||||||
public class RenderingIcons {
|
public class RenderingIcons {
|
||||||
private static final Log log = PlatformUtil.getLog(RenderingIcons.class);
|
private static final Log log = PlatformUtil.getLog(RenderingIcons.class);
|
||||||
|
|
||||||
private static Map<String, Integer> icons = new LinkedHashMap<String, Integer>();
|
private static Map<String, Integer> shaderIcons = new LinkedHashMap<String, Integer>();
|
||||||
private static Map<String, Integer> smallIcons = new LinkedHashMap<String, Integer>();
|
private static Map<String, Integer> smallIcons = new LinkedHashMap<String, Integer>();
|
||||||
private static Map<String, Integer> bigIcons = 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 Map<String, Bitmap> iconsBmp = new LinkedHashMap<String, Bitmap>();
|
||||||
// private static DisplayMetrics dm;
|
// private static DisplayMetrics dm;
|
||||||
|
|
||||||
public static boolean containsIcon(String s){
|
public static boolean containsSmallIcon(String s){
|
||||||
return icons.containsKey(s);
|
return smallIcons.containsKey(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean containsBigIcon(String s){
|
public static boolean containsBigIcon(String s){
|
||||||
|
@ -35,9 +35,10 @@ public class RenderingIcons {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] getIconRawData(Context ctx, String s) {
|
public static byte[] getIconRawData(Context ctx, String s) {
|
||||||
Integer resId = icons.get(s);
|
Integer resId = shaderIcons.get(s);
|
||||||
|
if(resId == null) {
|
||||||
// Quite bad error
|
resId = smallIcons.get(s);
|
||||||
|
}
|
||||||
if(resId == null)
|
if(resId == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
@ -81,12 +82,15 @@ public class RenderingIcons {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Bitmap getIcon(Context ctx, String s) {
|
public static Bitmap getIcon(Context ctx, String s, boolean includeShader) {
|
||||||
if(s == null) {
|
if(s == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
if(includeShader && shaderIcons.containsKey(s)) {
|
||||||
|
s = "h_" + s;
|
||||||
|
}
|
||||||
if (!iconsBmp.containsKey(s)) {
|
if (!iconsBmp.containsKey(s)) {
|
||||||
Integer resId = icons.get(s);
|
Integer resId = s.startsWith("h_") ? shaderIcons.get(s.substring(2)) : smallIcons.get(s);
|
||||||
if (resId != null) {
|
if (resId != null) {
|
||||||
Bitmap bmp = BitmapFactory.decodeResource(ctx.getResources(), resId, null);
|
Bitmap bmp = BitmapFactory.decodeResource(ctx.getResources(), resId, null);
|
||||||
iconsBmp.put(s, bmp);
|
iconsBmp.put(s, bmp);
|
||||||
|
@ -105,31 +109,18 @@ public class RenderingIcons {
|
||||||
public static void initIcons() {
|
public static void initIcons() {
|
||||||
Class<? extends drawable> cl = R.drawable.class;
|
Class<? extends drawable> cl = R.drawable.class;
|
||||||
for (Field f : cl.getDeclaredFields()) {
|
for (Field f : cl.getDeclaredFields()) {
|
||||||
if (f.getName().startsWith("h_") || f.getName().startsWith("mm_")) {
|
try {
|
||||||
try {
|
if (f.getName().startsWith("h_")) {
|
||||||
String id = f.getName().substring(f.getName().startsWith("mm_") ? 3 : 2);
|
shaderIcons.put(f.getName().substring(2), f.getInt(null));
|
||||||
int i = f.getInt(null);
|
} else if( f.getName().startsWith("mm_")) {
|
||||||
// don't override shader or map icons (h)
|
smallIcons.put(f.getName().substring(3), f.getInt(null));
|
||||||
if(f.getName().startsWith("h_") || !icons.containsKey(id)) {
|
} else if (f.getName().startsWith("mx_")) {
|
||||||
icons.put(id, i);
|
|
||||||
}
|
|
||||||
if(f.getName().startsWith("mm_")) {
|
|
||||||
smallIcons.put(id, i);
|
|
||||||
}
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (f.getName().startsWith("mx_") ) {
|
|
||||||
try {
|
|
||||||
bigIcons.put(f.getName().substring(3), f.getInt(null));
|
bigIcons.put(f.getName().substring(3), f.getInt(null));
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -268,7 +268,7 @@ public class TextRenderer {
|
||||||
private void drawShieldIcon(RenderingContext rc, Canvas cv, TextDrawInfo text, String sr) {
|
private void drawShieldIcon(RenderingContext rc, Canvas cv, TextDrawInfo text, String sr) {
|
||||||
if (sr != null) {
|
if (sr != null) {
|
||||||
float coef = rc.getDensityValue(rc.screenDensityRatio * rc.textScale);
|
float coef = rc.getDensityValue(rc.screenDensityRatio * rc.textScale);
|
||||||
Bitmap ico = RenderingIcons.getIcon(context, sr);
|
Bitmap ico = RenderingIcons.getIcon(context, sr, true);
|
||||||
if (ico != null) {
|
if (ico != null) {
|
||||||
float left = text.centerX - ico.getWidth() / 2 * coef - 0.5f;
|
float left = text.centerX - ico.getWidth() / 2 * coef - 0.5f;
|
||||||
float top = text.centerY - ico.getHeight() / 2 * coef - paintText.descent() - 0.5f;
|
float top = text.centerY - ico.getHeight() / 2 * coef - paintText.descent() - 0.5f;
|
||||||
|
|
|
@ -253,14 +253,14 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
|
||||||
String id = null;
|
String id = null;
|
||||||
PoiType st = o.getType().getPoiTypeByKeyName(o.getSubType());
|
PoiType st = o.getType().getPoiTypeByKeyName(o.getSubType());
|
||||||
if (st != null) {
|
if (st != null) {
|
||||||
if (RenderingIcons.containsIcon(st.getIconKeyName())) {
|
if (RenderingIcons.containsSmallIcon(st.getIconKeyName())) {
|
||||||
id = st.getIconKeyName();
|
id = st.getIconKeyName();
|
||||||
} else if (RenderingIcons.containsIcon(st.getOsmTag() + "_" + st.getOsmValue())) {
|
} else if (RenderingIcons.containsSmallIcon(st.getOsmTag() + "_" + st.getOsmValue())) {
|
||||||
id = st.getOsmTag() + "_" + st.getOsmValue();
|
id = st.getOsmTag() + "_" + st.getOsmValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (id != null) {
|
if (id != null) {
|
||||||
Bitmap bmp = RenderingIcons.getIcon(view.getContext(), id);
|
Bitmap bmp = RenderingIcons.getIcon(view.getContext(), id, false);
|
||||||
if (bmp != null) {
|
if (bmp != null) {
|
||||||
canvas.drawBitmap(bmp, x - bmp.getWidth() / 2, y - bmp.getHeight() / 2, paintIcon);
|
canvas.drawBitmap(bmp, x - bmp.getWidth() / 2, y - bmp.getHeight() / 2, paintIcon);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue