Search in sources :

Example 1 with QuadTree

use of net.osmand.data.QuadTree in project Osmand by osmandapp.

the class TextRenderer method drawTextOverCanvas.

public void drawTextOverCanvas(RenderingContext rc, Canvas cv, String preferredLocale) {
    int size = rc.textToDraw.size();
    // 1. Sort text using text order
    Collections.sort(rc.textToDraw, new Comparator<TextDrawInfo>() {

        @Override
        public int compare(TextDrawInfo object1, TextDrawInfo object2) {
            return object1.textOrder - object2.textOrder;
        }
    });
    QuadRect r = new QuadRect(0, 0, rc.width, rc.height);
    r.inset(-100, -100);
    QuadTree<TextDrawInfo> nonIntersectedBounds = new QuadTree<TextDrawInfo>(r, 4, 0.6f);
    for (int i = 0; i < size; i++) {
        TextDrawInfo text = rc.textToDraw.get(i);
        if (text.text != null && text.text.length() > 0) {
            if (preferredLocale.length() > 0) {
                text.text = Junidecode.unidecode(text.text);
            }
            // sest text size before finding intersection (it is used there)
            float textSize = text.textSize * rc.textScale;
            paintText.setTextSize(textSize);
            if (text.bold && text.italic) {
                paintText.setTypeface(boldItalicTypeface);
            } else if (text.bold) {
                paintText.setTypeface(boldTypeface);
            } else if (text.italic) {
                paintText.setTypeface(italicTypeface);
            } else {
                paintText.setTypeface(defaultTypeface);
            }
            paintText.setFakeBoldText(text.bold);
            paintText.setColor(text.textColor);
            // align center y
            text.centerY += (-paintText.ascent());
            // calculate if there is intersection
            boolean intersects = findTextIntersection(cv, rc, nonIntersectedBounds, text);
            if (!intersects) {
                if (text.drawOnPath != null) {
                    if (text.textShadow > 0) {
                        paintText.setColor(text.textShadowColor);
                        paintText.setStyle(Style.STROKE);
                        paintText.setStrokeWidth(2 + text.textShadow);
                        cv.drawTextOnPath(text.text, text.drawOnPath, 0, text.vOffset - (paintText.ascent() / 2 + paintText.descent()), paintText);
                        // reset
                        paintText.setStyle(Style.FILL);
                        paintText.setStrokeWidth(2);
                        paintText.setColor(text.textColor);
                    }
                    cv.drawTextOnPath(text.text, text.drawOnPath, 0, text.vOffset - (paintText.ascent() / 2 + paintText.descent()), paintText);
                } else {
                    drawShieldIcon(rc, cv, text, text.shieldRes);
                    drawShieldIcon(rc, cv, text, text.shieldResIcon);
                    drawWrappedText(cv, text, textSize);
                }
            }
        }
    }
}
Also used : QuadTree(net.osmand.data.QuadTree) QuadRect(net.osmand.data.QuadRect) Paint(android.graphics.Paint)

Example 2 with QuadTree

use of net.osmand.data.QuadTree in project Osmand by osmandapp.

the class OsmandRenderer method drawIconsOverCanvas.

private void drawIconsOverCanvas(RenderingContext rc, Canvas cv) {
    // 1. Sort text using text order
    Collections.sort(rc.iconsToDraw, new Comparator<IconDrawInfo>() {

        @Override
        public int compare(IconDrawInfo object1, IconDrawInfo object2) {
            return object1.iconOrder - object2.iconOrder;
        }
    });
    QuadRect bounds = new QuadRect(0, 0, rc.width, rc.height);
    bounds.inset(-bounds.width() / 4, -bounds.height() / 4);
    QuadTree<RectF> boundIntersections = new QuadTree<RectF>(bounds, 4, 0.6f);
    List<RectF> result = new ArrayList<RectF>();
    for (IconDrawInfo icon : rc.iconsToDraw) {
        if (icon.resId != null) {
            Bitmap ico = RenderingIcons.getIcon(context, icon.resId, true);
            if (ico != null) {
                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 visbleHeight = icon.iconSize >= 0 ? (int) icon.iconSize : ico.getHeight();
                    boolean intersects = false;
                    float coeff = rc.getDensityValue(rc.screenDensityRatio * rc.textScale);
                    RectF rf = calculateRect(rc, icon, ico.getWidth(), ico.getHeight());
                    RectF visibleRect = null;
                    if (visbleHeight > 0 && visbleWidth > 0) {
                        visibleRect = calculateRect(rc, icon, visbleWidth, visbleHeight);
                        boundIntersections.queryInBox(new QuadRect(visibleRect.left, visibleRect.top, visibleRect.right, visibleRect.bottom), result);
                        for (RectF r : result) {
                            if (r.intersects(visibleRect.left, visibleRect.top, visibleRect.right, visibleRect.bottom)) {
                                intersects = true;
                                break;
                            }
                        }
                    }
                    if (!intersects) {
                        Bitmap shield = icon.shieldId == null ? null : RenderingIcons.getIcon(context, icon.shieldId, true);
                        if (shield != null) {
                            RectF shieldRf = calculateRect(rc, icon, shield.getWidth(), shield.getHeight());
                            if (coeff != 1f) {
                                Rect src = new Rect(0, 0, shield.getWidth(), shield.getHeight());
                                drawBitmap(cv, shield, shieldRf, src);
                            } else {
                                drawBitmap(cv, shield, shieldRf);
                            }
                        }
                        if (coeff != 1f) {
                            Rect src = new Rect(0, 0, ico.getWidth(), ico.getHeight());
                            drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId_1, true), rf, src);
                            drawBitmap(cv, ico, rf, src);
                            drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId2, true), rf, src);
                            drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId3, true), rf, src);
                            drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId4, true), rf, src);
                            drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId5, true), rf, src);
                        } else {
                            drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId_1, true), rf);
                            drawBitmap(cv, ico, rf);
                            drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId2, true), rf);
                            drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId3, true), rf);
                            drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId4, true), rf);
                            drawBitmap(cv, RenderingIcons.getIcon(context, icon.resId5, true), rf);
                        }
                        if (visibleRect != null) {
                            visibleRect.inset(-visibleRect.width() / 4, -visibleRect.height() / 4);
                            boundIntersections.insert(visibleRect, new QuadRect(visibleRect.left, visibleRect.top, visibleRect.right, visibleRect.bottom));
                        }
                    }
                }
            }
        }
        if (rc.interrupted) {
            return;
        }
    }
}
Also used : QuadTree(net.osmand.data.QuadTree) Rect(android.graphics.Rect) QuadRect(net.osmand.data.QuadRect) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) QuadRect(net.osmand.data.QuadRect) Paint(android.graphics.Paint) RectF(android.graphics.RectF) Bitmap(android.graphics.Bitmap)

Example 3 with QuadTree

use of net.osmand.data.QuadTree in project Osmand by osmandapp.

the class OsmandMapLayer method initBoundIntersections.

@NonNull
public QuadTree<QuadRect> initBoundIntersections(RotatedTileBox tileBox) {
    QuadRect bounds = new QuadRect(0, 0, tileBox.getPixWidth(), tileBox.getPixHeight());
    bounds.inset(-bounds.width() / 4, -bounds.height() / 4);
    return new QuadTree<>(bounds, 4, 0.6f);
}
Also used : QuadTree(net.osmand.data.QuadTree) QuadRect(net.osmand.data.QuadRect) NonNull(android.support.annotation.NonNull)

Aggregations

QuadRect (net.osmand.data.QuadRect)3 QuadTree (net.osmand.data.QuadTree)3 Paint (android.graphics.Paint)2 Bitmap (android.graphics.Bitmap)1 Rect (android.graphics.Rect)1 RectF (android.graphics.RectF)1 NonNull (android.support.annotation.NonNull)1 TIntArrayList (gnu.trove.list.array.TIntArrayList)1 ArrayList (java.util.ArrayList)1