public int getMinY() { return _bounds.getY() - _bounds.getHeight() / 2; }
public int getMaxY() { return _bounds.getY() + _bounds.getHeight() / 2; }
private int getSumOfAllHeights(final List<Spatial> content) { int sum = 0; if (content != null) { final Rectangle2 store = new Rectangle2(); for (final Spatial spat : content) { if (spat instanceof UIComponent) { final Rectangle2 rect = ((UIComponent) spat).getRelativeMinComponentBounds(store); sum += rect.getHeight(); } } } return sum; }
private int getSumOfAllHeights(final List<Spatial> content) { int sum = 0; if (content != null) { final Rectangle2 store = new Rectangle2(); for (final Spatial spat : content) { if (spat instanceof UIComponent) { final Rectangle2 rect = ((UIComponent) spat).getRelativeMinComponentBounds(store); sum += rect.getHeight(); } } } return sum; }
private int getMinimumHeight(final List<Spatial> content) { int minH = 0; int maxEWCH = 0; if (content != null) { final Rectangle2 store = new Rectangle2(); for (final Spatial s : content) { if (!(s instanceof UIComponent)) { continue; } final UIComponent comp = (UIComponent) s; comp.getRelativeMinComponentBounds(store); final BorderLayoutData bld = (BorderLayoutData) comp.getLayoutData(); if (bld == null) { continue; } if (bld == BorderLayoutData.SOUTH || bld == BorderLayoutData.NORTH) { minH += store.getHeight(); } else { final int h = store.getHeight(); if (h > maxEWCH) { maxEWCH = h; } } } } return minH + maxEWCH; }
public Rectangle2 intersect(final ReadOnlyRectangle2 other, final Rectangle2 store) { Rectangle2 rVal = store; if (rVal == null) { rVal = new Rectangle2(); } final int x1 = Math.max(getX(), other.getX()); final int y1 = Math.max(getY(), other.getY()); final int x2 = Math.min(getX() + getWidth(), other.getX() + other.getWidth()); final int y2 = Math.min(getY() + getHeight(), other.getY() + other.getHeight()); rVal.set(x1, y1, x2 - x1, y2 - y1); return rVal; }
public Rectangle2 intersect(final ReadOnlyRectangle2 other, final Rectangle2 store) { Rectangle2 rVal = store; if (rVal == null) { rVal = new Rectangle2(); } final int x1 = Math.max(getX(), other.getX()); final int y1 = Math.max(getY(), other.getY()); final int x2 = Math.min(getX() + getWidth(), other.getX() + other.getWidth()); final int y2 = Math.min(getY() + getHeight(), other.getY() + other.getHeight()); rVal.set(x1, y1, x2 - x1, y2 - y1); return rVal; }
/** * @return true if this frame can be fully contained by the hud. */ public boolean smallerThanWindow() { final int dispWidth = uiDrawer.getHud().getWidth(); final int dispHeight = uiDrawer.getHud().getHeight(); final Rectangle2 rect = uiDrawer.getRelativeComponentBounds(null); return rect.getWidth() <= dispWidth && rect.getHeight() <= dispHeight; }
/** * @return true if this frame can be fully contained by the hud. */ public boolean smallerThanWindow() { final int dispWidth = uiFrame.getHud().getWidth(); final int dispHeight = uiFrame.getHud().getHeight(); final Rectangle2 rect = uiFrame.getRelativeComponentBounds(null); return rect.getWidth() <= dispWidth && rect.getHeight() <= dispHeight; }
/** * Centers this component on the location of the given component. * * @param comp * the component to center on. */ public void centerOn(final UIComponent comp) { final Rectangle2 rectA = comp.getRelativeComponentBounds(null); final Rectangle2 rectB = getRelativeComponentBounds(null); int x = (rectA.getWidth() - rectB.getWidth()) / 2; int y = (rectA.getHeight() - rectB.getHeight()) / 2; x += comp.getHudX() - rectA.getX() + rectB.getX(); y += comp.getHudY() - rectA.getY() + rectB.getY(); setHudXY(x, y); }
/** * @return true if this frame can be fully contained by the hud. */ public boolean smallerThanWindow() { final int dispWidth = uiFrame.getHud().getWidth(); final int dispHeight = uiFrame.getHud().getHeight(); final Rectangle2 rect = uiFrame.getRelativeComponentBounds(null); return rect.getWidth() <= dispWidth && rect.getHeight() <= dispHeight; }
/** * Centers this frame on the location of the given component. * * @param comp * the component to center on. */ public void setLocationRelativeTo(final UIComponent comp) { final Rectangle2 rectA = comp.getRelativeComponentBounds(null); final Rectangle2 rectB = getRelativeComponentBounds(null); int x = (rectA.getWidth() - rectB.getWidth()) / 2; int y = (rectA.getHeight() - rectB.getHeight()) / 2; x += comp.getHudX() - rectA.getX() + rectB.getX(); y += comp.getHudY() - rectA.getY() + rectB.getY(); setHudXY(x, y); updateGeometricState(0); }
/** * Centers this frame on the view of the camera * * @param cam * the camera to center on. */ public void centerOn(final UIHud hud) { final Rectangle2 rectA = getRelativeComponentBounds(null); int x = (hud.getWidth() - rectA.getWidth()) / 2; int y = (hud.getHeight() - rectA.getHeight()) / 2; x -= rectA.getX(); y -= rectA.getY(); setHudXY(x, y); }
/** * Attempt to force this component to fit in the given rectangle. * * @param width * @param height */ public void fitComponentIn(final int width, final int height) { final ReadOnlyTransform local = getTransform(); if (local.isIdentity() || local.getMatrix().isIdentity()) { setLocalComponentSize(width, height); return; } final Vector3 temp = Vector3.fetchTempInstance(); temp.set(1, 0, 0); local.applyForwardVector(temp); if (Math.abs(temp.getX()) >= 0.99999) { setLocalComponentSize(width, height); } else if (Math.abs(temp.getY()) >= 0.99999) { setLocalComponentSize(height, width); } else { final Rectangle2 rect = getRelativeMinComponentBounds(null); final float ratio = Math.min((float) width / rect.getWidth(), (float) height / rect.getHeight()); setLocalComponentSize(Math.round(getMinimumLocalComponentWidth() * ratio), Math.round(getMinimumLocalComponentHeight() * ratio)); } }
/** * @param o * the object to compare for equality * @return true if this rectangle and the provided rectangle have the same origin and dimensions */ @Override public boolean equals(final Object o) { if (this == o) { return true; } if (!(o instanceof ReadOnlyRectangle2)) { return false; } final ReadOnlyRectangle2 comp = (ReadOnlyRectangle2) o; return comp.getX() == getX() && comp.getY() == getY() && comp.getWidth() == getWidth() && comp.getHeight() == getHeight(); }
/** * @param o * the object to compare for equality * @return true if this rectangle and the provided rectangle have the same origin and dimensions */ @Override public boolean equals(final Object o) { if (this == o) { return true; } if (!(o instanceof ReadOnlyRectangle2)) { return false; } final ReadOnlyRectangle2 comp = (ReadOnlyRectangle2) o; return comp.getX() == getX() && comp.getY() == getY() && comp.getWidth() == getWidth() && comp.getHeight() == getHeight(); }
/** * Centers this frame on the view of the camera * * @param cam * the camera to center on. */ public void setLocationRelativeTo(final Camera cam) { final Rectangle2 rectA = getRelativeComponentBounds(null); int x = (cam.getWidth() - rectA.getWidth()) / 2; int y = (cam.getHeight() - rectA.getHeight()) / 2; x -= rectA.getX(); y -= rectA.getY(); setHudXY(x, y); updateGeometricState(0); }
protected void addTiles(final Rectangle2 bounds, final Set<Tile> store) { for (int i = 0; i <= clipmapLevels; i++) { final double scale = 1.0 / (tileSize * MathUtils.pow2(i)); final int minX = (int) MathUtils.floor(bounds.getX() * scale); final int minY = (int) MathUtils.floor(bounds.getY() * scale); final int maxX = (int) MathUtils.floor((bounds.getX() + bounds.getWidth() - 1) * scale); final int maxY = (int) MathUtils.floor((bounds.getY() + bounds.getHeight() - 1) * scale); Tile tile; for (int y = minY; y <= maxY; y++) { for (int x = minX; x <= maxX; x++) { tile = new Tile(x, y); synchronized (store) { store.add(tile); } } } } }
protected void addTiles(final Rectangle2 bounds, final Set<Tile> store) { for (int i = 0; i <= clipmapLevels; i++) { final double scale = 1.0 / (tileSize * MathUtils.pow2(i)); final int minX = (int) MathUtils.floor(bounds.getX() * scale); final int minY = (int) MathUtils.floor(bounds.getY() * scale); final int maxX = (int) MathUtils.floor((bounds.getX() + bounds.getWidth() - 1) * scale); final int maxY = (int) MathUtils.floor((bounds.getY() + bounds.getHeight() - 1) * scale); Tile tile; for (int y = minY; y <= maxY; y++) { for (int x = minX; x <= maxX; x++) { tile = new Tile(x, y); synchronized (store) { store.add(tile); } } } } }
@Test public void testIntersect() { final Rectangle2 rect1 = new Rectangle2(0, 0, 10, 10); final Rectangle2 rect2 = new Rectangle2(5, 5, 10, 10); Rectangle2 intersection = rect1.intersect(rect2, Rectangle2.fetchTempInstance()); assertTrue(5 == intersection.getX()); assertTrue(5 == intersection.getY()); assertTrue(5 == intersection.getWidth()); assertTrue(5 == intersection.getHeight()); Rectangle2.releaseTempInstance(intersection); assertNotNull(rect1.intersect(rect2, null)); intersection = Rectangle2.intersect(rect1, rect2, Rectangle2.fetchTempInstance()); assertTrue(5 == intersection.getX()); assertTrue(5 == intersection.getY()); assertTrue(5 == intersection.getWidth()); assertTrue(5 == intersection.getHeight()); Rectangle2.releaseTempInstance(intersection); assertNotNull(Rectangle2.intersect(rect1, rect2, null)); } }