AndroidTextLayout(String text, TextFormat format, AndroidFont font, Paint.FontMetrics metrics, float width, float height) { // Android doesn't provide a way to get precise text bounds, so we half-ass it, woo! super(text, format, new Rectangle(0, 0, width, height), height); this.font = font; this.metrics = metrics; }
@Override // from RectangularShape public void setFrame (float x, float y, float width, float height) { setBounds(x, y, width, height); } }
/** Hides the native widgets under the given screen area, using platform clipping if * supported. The PlayN layers underneath the area should show through. Pointer events should * also not interact with the native widgets within the area. * @param area the new area to hide, in screen coordinates, or null to show all */ public void hideNativeOverlays (IRectangle area) { if ((_hidden == null && area == null) || (_hidden != null && _hidden.equals(area))) return; _hidden = area == null ? null : new Rectangle(area); updateHidden(); }
/** Confines a rectangle and updates the current best fit based on the moved distance. */ protected static float compareAndConfine ( IRectangle outer, IRectangle inner, Rectangle best, float bestDist) { // don't bother if there isn't even enough space if (outer.width() <= inner.width() || outer.height() < inner.height()) return bestDist; // confine Rectangle confined = confine(outer, new Rectangle(inner)); // check distance and overwrite the best fit if we have a new winner float dx = confined.x - inner.x(), dy = confined.y - inner.y(); float dist = dx * dx + dy * dy; if (dist < bestDist) { best.setBounds(confined); bestDist = dist; } return bestDist; }
/** * Returns how many times rectangle stripe cross shape or the are intersect */ public static int intersectShape (IShape s, float x, float y, float w, float h) { if (!s.bounds().intersects(x, y, w, h)) { return 0; } return intersectPath(s.pathIterator(null), x, y, w, h); }
/** * Expands the bounds of this rectangle to contain the supplied point. */ public void add (XY p) { add(p.x(), p.y()); }
/** Tries to place the inner bounds within the outer bounds, such that the inner bounds does * not contain the position. */ protected static boolean avoidPoint (IRectangle outer, Rectangle inner, IRectangle fingerprint) { Rectangle checkBounds = new Rectangle(); Rectangle best = new Rectangle(inner); float bestDist = Float.MAX_VALUE, edge; // confine to the left edge = fingerprint.x(); checkBounds.setBounds(outer.x(), outer.y(), edge - outer.x(), outer.height()); bestDist = compareAndConfine(checkBounds, inner, best, bestDist); // right edge = fingerprint.maxX(); checkBounds.setBounds(edge, outer.y(), outer.width() - edge, outer.height()); bestDist = compareAndConfine(checkBounds, inner, best, bestDist); // top edge = fingerprint.y(); checkBounds.setBounds(outer.x(), outer.y(), outer.width(), edge - outer.y()); bestDist = compareAndConfine(checkBounds, inner, best, bestDist); // bottom edge = fingerprint.maxY(); checkBounds.setBounds(outer.x(), edge, outer.width(), outer.height() - edge); bestDist = compareAndConfine(checkBounds, inner, best, bestDist); inner.setBounds(best); return bestDist < Float.MAX_VALUE; }
@Override // from interface IShape public boolean intersects (float x, float y, float width, float height) { if ((width <= 0f) || (height <= 0f)) { return false; } else if (!bounds().intersects(x, y, width, height)) { return false; } int crossCount = Crossing.intersectShape(this, x, y, width, height); return Crossing.isInsideEvenOdd(crossCount); }
/** * Expands the bounds of this rectangle to contain the supplied point. */ public void add (XY p) { add(p.x(), p.y()); }
AndroidTextLayout(String text, TextFormat format, AndroidFont font, Paint.FontMetrics metrics, float width) { // Android doesn't provide a way to get precise text bounds, so we half-ass it, woo! super(text, format, new Rectangle(0, 0, width, -metrics.ascent+metrics.descent)); this.font = font; this.metrics = metrics; }
/** * Constructs a rectangle with the specified upper-left corner and dimensions. */ public Rectangle (float x, float y, float width, float height) { setBounds(x, y, width, height); }
@Override // from interface IShape public boolean intersects (float x, float y, float width, float height) { if ((width <= 0f) || (height <= 0f)) { return false; } else if (!bounds().intersects(x, y, width, height)) { return false; } int crossCount = Crossing.intersectShape(this, x, y, width, height); return Crossing.isInsideEvenOdd(crossCount); }
/** Helper function for {@link #totalBounds}. */ protected static void addBounds (Layer root, Layer l, Rectangle bounds, Point scratch) { float w = l.width(), h = l.height(); if (w != 0 || h != 0) { // grow bounds bounds.add(LayerUtil.layerToParent(l, root, scratch.set(0, 0), scratch)); bounds.add(LayerUtil.layerToParent(l, root, scratch.set(w, h), scratch)); } if (l instanceof GroupLayer) { GroupLayer group = (GroupLayer) l; for (int ii = 0, ll = group.children(); ii < ll; ++ii) { addBounds(root, group.childAt(ii), bounds, scratch); } } } }
AndroidTextLayout(String text, TextFormat format, AndroidFont font, Paint.FontMetrics metrics, float width) { // Android doesn't provide a way to get precise text bounds, so we half-ass it, woo! super(text, format, new Rectangle(0, 0, width, -metrics.ascent+metrics.descent)); this.font = font; this.metrics = metrics; }
@Override // from RectangularShape public void setFrame (float x, float y, float width, float height) { setBounds(x, y, width, height); } }