Add support for icon visible size (special case 0)

This commit is contained in:
Victor Shcherb 2014-06-19 21:03:32 +02:00
parent d0df0bad67
commit 5331180650
2 changed files with 35 additions and 17 deletions

View file

@ -46,6 +46,7 @@ public class RenderingRuleStorageProperties {
public static final String TEXT_BOLD = "textBold"; public static final String TEXT_BOLD = "textBold";
public static final String TEXT_ORDER = "textOrder"; public static final String TEXT_ORDER = "textOrder";
public static final String ICON_ORDER = "iconOrder"; public static final String ICON_ORDER = "iconOrder";
public static final String ICON_VISIBLE_SIZE = "iconVisibleSize";
public static final String TEXT_MIN_DISTANCE = "textMinDistance"; public static final String TEXT_MIN_DISTANCE = "textMinDistance";
public static final String TEXT_ON_PATH = "textOnPath"; public static final String TEXT_ON_PATH = "textOnPath";
public static final String ICON = "icon"; public static final String ICON = "icon";
@ -109,6 +110,7 @@ public class RenderingRuleStorageProperties {
public RenderingRuleProperty R_TEXT_MIN_DISTANCE; public RenderingRuleProperty R_TEXT_MIN_DISTANCE;
public RenderingRuleProperty R_TEXT_ON_PATH; public RenderingRuleProperty R_TEXT_ON_PATH;
public RenderingRuleProperty R_ICON; public RenderingRuleProperty R_ICON;
public RenderingRuleProperty R_ICON_VISIBLE_SIZE;
public RenderingRuleProperty R_LAYER; public RenderingRuleProperty R_LAYER;
public RenderingRuleProperty R_ORDER; public RenderingRuleProperty R_ORDER;
public RenderingRuleProperty R_POINT; public RenderingRuleProperty R_POINT;
@ -134,6 +136,7 @@ public class RenderingRuleStorageProperties {
final List<RenderingRuleProperty> rules ; final List<RenderingRuleProperty> rules ;
final List<RenderingRuleProperty> customRules ; final List<RenderingRuleProperty> customRules ;
public RenderingRuleStorageProperties() { public RenderingRuleStorageProperties() {
properties = new LinkedHashMap<String, RenderingRuleProperty>(); properties = new LinkedHashMap<String, RenderingRuleProperty>();
rules = new ArrayList<RenderingRuleProperty>(); rules = new ArrayList<RenderingRuleProperty>();
@ -184,6 +187,7 @@ public class RenderingRuleStorageProperties {
R_TEXT_SIZE = registerRuleInternal(RenderingRuleProperty.createOutputFloatProperty(TEXT_SIZE)); R_TEXT_SIZE = registerRuleInternal(RenderingRuleProperty.createOutputFloatProperty(TEXT_SIZE));
R_TEXT_ORDER = registerRuleInternal(RenderingRuleProperty.createOutputIntProperty(TEXT_ORDER)); R_TEXT_ORDER = registerRuleInternal(RenderingRuleProperty.createOutputIntProperty(TEXT_ORDER));
R_ICON_ORDER = registerRuleInternal(RenderingRuleProperty.createOutputIntProperty(ICON_ORDER)); R_ICON_ORDER = registerRuleInternal(RenderingRuleProperty.createOutputIntProperty(ICON_ORDER));
R_ICON_VISIBLE_SIZE = registerRuleInternal(RenderingRuleProperty.createOutputFloatProperty(ICON_VISIBLE_SIZE));
R_TEXT_MIN_DISTANCE = registerRuleInternal(RenderingRuleProperty.createOutputFloatProperty(TEXT_MIN_DISTANCE)); R_TEXT_MIN_DISTANCE = registerRuleInternal(RenderingRuleProperty.createOutputFloatProperty(TEXT_MIN_DISTANCE));
R_TEXT_SHIELD = registerRuleInternal(RenderingRuleProperty.createOutputStringProperty(TEXT_SHIELD)); R_TEXT_SHIELD = registerRuleInternal(RenderingRuleProperty.createOutputStringProperty(TEXT_SHIELD));

View file

@ -4,7 +4,6 @@ import gnu.trove.list.array.TIntArrayList;
import gnu.trove.map.hash.TIntObjectHashMap; import gnu.trove.map.hash.TIntObjectHashMap;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
@ -86,6 +85,7 @@ public class OsmandRenderer {
float y = 0; float y = 0;
String resId; String resId;
int iconOrder; int iconOrder;
float iconSize;
} }
@ -315,39 +315,52 @@ public class OsmandRenderer {
Bitmap ico = RenderingIcons.getIcon(context, icon.resId); Bitmap ico = RenderingIcons.getIcon(context, icon.resId);
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) {
float left = icon.x - ico.getWidth() / 2 * rc.screenDensityRatio; int visbleWidth = icon.iconSize >= 0 ? (int) icon.iconSize : ico.getWidth();
float top = icon.y - ico.getHeight() / 2 * rc.screenDensityRatio; int visbleHeight = icon.iconSize >= 0 ? (int) icon.iconSize : ico.getHeight();
float right = left + ico.getWidth() * rc.screenDensityRatio;
float bottom = top + ico.getHeight() * rc.screenDensityRatio;
RectF rf = new RectF(left, top, right , bottom);
boundIntersections.queryInBox(new QuadRect(left, top, right, bottom), result);
boolean intersects = false; boolean intersects = false;
RectF rf = calculateRect(rc, icon, ico.getWidth(), ico.getHeight());
if (visbleHeight > 0 && visbleWidth > 0) {
RectF visibleRect = calculateRect(rc, icon, visbleWidth, visbleHeight);
boundIntersections.queryInBox(new QuadRect(visibleRect.left, visibleRect.top, visibleRect.right, visibleRect.bottom), result);
for (RectF r : result) { for (RectF r : result) {
if(r.intersect(rf)) { if (r.intersect(visibleRect)) {
intersects = true; intersects = true;
break; break;
} }
} }
}
if (!intersects) { if (!intersects) {
if (rc.screenDensityRatio != 1f) { if (rc.screenDensityRatio != 1f) {
Rect src = new Rect(0, 0, ico.getWidth(), ico Rect src = new Rect(0, 0, ico.getWidth(), ico.getHeight());
.getHeight());
cv.drawBitmap(ico, src, rf, paintIcon); cv.drawBitmap(ico, src, rf, paintIcon);
} else { } else {
cv.drawBitmap(ico, left, top, paintIcon); cv.drawBitmap(ico, rf.left, rf.top, paintIcon);
} }
if(rf != null) {
rf.inset(-rf.width() / 4, -rf.height() / 4); rf.inset(-rf.width() / 4, -rf.height() / 4);
boundIntersections.insert(rf, new QuadRect(rf.left, rf.top, rf.right, rf.bottom)); boundIntersections.insert(rf, new QuadRect(rf.left, rf.top, rf.right, rf.bottom));
} }
} }
} }
} }
}
if (rc.interrupted) { if (rc.interrupted) {
return; return;
} }
} }
} }
private RectF calculateRect(RenderingContext rc, IconDrawInfo icon, int visbleWidth, int visbleHeight) {
RectF rf;
float left = icon.x - visbleWidth / 2 * rc.screenDensityRatio;
float top = icon.y - visbleHeight / 2 * rc.screenDensityRatio;
float right = left + visbleWidth * rc.screenDensityRatio;
float bottom = top + visbleHeight * rc.screenDensityRatio;
rf = new RectF(left, top, right, bottom);
return rf;
}
Comparator<MapDataObjectPrimitive> sortByOrder() { Comparator<MapDataObjectPrimitive> sortByOrder() {
return new Comparator<MapDataObjectPrimitive>() { return new Comparator<MapDataObjectPrimitive>() {
@ -742,6 +755,7 @@ public class OsmandRenderer {
ico.x = ps.x; ico.x = ps.x;
ico.y = ps.y; ico.y = ps.y;
ico.iconOrder = render.getIntPropertyValue(render.ALL.R_ICON_ORDER, 100); ico.iconOrder = render.getIntPropertyValue(render.ALL.R_ICON_ORDER, 100);
ico.iconSize = rc.getComplexValue(render, render.ALL.R_ICON_VISIBLE_SIZE, -1);
ico.resId = resId; ico.resId = resId;
rc.iconsToDraw.add(ico); rc.iconsToDraw.add(ico);
} }