Package com.ardor3d.math

Examples of com.ardor3d.math.Rectangle2


                    updateTerrain(x, y, radius, paint, offset);

                    // queue up an update alert for the rectangle updated
                    final int minY = Math.max(0, y - radius), maxY = Math.min(y + radius, side - 1);
                    final int minX = Math.max(0, x - radius), maxX = Math.min(x + radius, side - 1);
                    final Rectangle2 region = new Rectangle2(minX, minY, maxX - minX, maxY - minY);

                    // break up by clipmaplevel
                    // add to two queues since these updates are called in different threads potentially
                    for (int i = 0; i < clipmapLevels; i++) {
                        addTiles(region, updatedTerrainTiles[i]);
View Full Code Here


    public static void applyScissors(final RendererRecord rendRecord) {
        final Stack<ReadOnlyRectangle2> clips = rendRecord.getScissorClips();

        if (clips.size() > 0) {
            final Rectangle2 init = Rectangle2.fetchTempInstance();
            init.set(-1, -1, -1, -1);
            ReadOnlyRectangle2 r;
            boolean first = true;
            for (int i = clips.size(); --i >= 0;) {
                r = clips.get(i);

                if (r == null) {
                    break;
                }
                if (first) {
                    init.set(r);
                    first = false;
                } else {
                    init.intersect(r, init);
                }
                if (init.getWidth() <= 0 || init.getHeight() <= 0) {
                    init.setWidth(0);
                    init.setHeight(0);
                    break;
                }
            }

            if (init.getWidth() == -1) {
                setClippingEnabled(rendRecord, false);
            } else {
                setClippingEnabled(rendRecord, true);
                GL11.glScissor(init.getX(), init.getY(), init.getWidth(), init.getHeight());
            }
            Rectangle2.releaseTempInstance(init);
        } else {
            // no clips, so disable
            setClippingEnabled(rendRecord, false);
View Full Code Here

     *
     * @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);
    }
View Full Code Here

     *
     * @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);
    }
View Full Code Here

        final List<Spatial> content = container.getChildren();
        if (content == null) {
            return;
        }

        final Rectangle2 storeA = Rectangle2.fetchTempInstance();
        final Rectangle2 storeB = Rectangle2.fetchTempInstance();

        // Grab a list of components, squeezing them down to their min size on the flow axis
        List<UIComponent> comps = Lists.newArrayList();
        List<UIComponent> compsBack = Lists.newArrayList();
        for (int i = 0; i < content.size(); i++) {
            final Spatial spat = content.get(i);
            if (spat instanceof UIComponent) {
                final UIComponent comp = (UIComponent) spat;
                final Rectangle2 rect = comp.getRelativeComponentBounds(storeA);
                final Rectangle2 minRect = comp.getRelativeMinComponentBounds(storeB);
                if (_horizontal) {
                    comp.fitComponentIn(minRect.getWidth(), rect.getHeight());
                } else {
                    comp.fitComponentIn(rect.getWidth(), minRect.getHeight());
                }
                comps.add(comp);
            }
        }

        // if we have components to layout...
        if (!comps.isEmpty()) {

            // Determine how much space we feel we need.
            final int reqSpace = _horizontal ? getSumOfAllWidths(content) : getSumOfAllHeights(content);

            // How much extra space do we have?
            int freeSpace = (_horizontal ? container.getContentWidth() : container.getContentHeight()) - reqSpace;

            int relaxIndex = 0;
            // cycle through until we've given away all of the space
            while ((freeSpace > 0 || relaxIndex == 0) && !comps.isEmpty() && relaxIndex < RowLayout.MAX_RELAX) {
                final int extraPerComp = freeSpace / comps.size();
                while (!comps.isEmpty()) {
                    final UIComponent comp = comps.remove(0);
                    Rectangle2 rect = comp.getRelativeComponentBounds(storeA);
                    final Rectangle2 origRect = storeB.set(rect);
                    if (freeSpace < 0) {
                        freeSpace = 0;
                    }
                    if (_horizontal) {
                        final int height = _expandsVertically ? container.getContentHeight() : rect.getHeight();
                        final int width = (_expandsHorizontally ? extraPerComp : 0) + rect.getWidth();
                        if (height == rect.getHeight() && width == rect.getWidth()) {
                            continue;
                        }

                        comp.fitComponentIn(width, height);
                        rect = comp.getRelativeComponentBounds(storeA);
                        if (Math.abs(rect.getWidth() - width) <= 1) {
                            compsBack.add(comp);
                        }
                        freeSpace -= rect.getWidth() - origRect.getWidth();
                    } else {
                        final int width = _expandsHorizontally ? container.getContentWidth() : rect.getWidth();
                        final int height = (_expandsVertically ? extraPerComp : 0) + rect.getHeight();
                        if (height == rect.getHeight() && width == rect.getWidth()) {
                            continue;
                        }

                        comp.fitComponentIn(width, height);
                        rect = comp.getRelativeComponentBounds(storeA);
                        if (Math.abs(rect.getHeight() - height) <= 1) {
                            compsBack.add(comp);
                        }
                        freeSpace -= rect.getHeight() - origRect.getHeight();
                    }
                }
                final List<UIComponent> compsTemp = comps;
                comps = compsBack;
                compsBack = compsTemp;
                relaxIndex++;
            }

            int x = 0;
            int y = !_expandsVertically && !_horizontal ? container.getContentHeight() - reqSpace : 0;

            // Now, go through children and set proper location.
            for (int i = 0; i < content.size(); i++) {
                final Spatial spat = _horizontal ? content.get(i) : content.get(content.size() - i - 1);

                if (!(spat instanceof UIComponent)) {
                    continue;
                }
                final UIComponent comp = (UIComponent) spat;
                final Rectangle2 rect = comp.getRelativeComponentBounds(storeA);

                if (_horizontal) {
                    comp.setLocalXY(x - rect.getX(), Math.max(container.getContentHeight() / 2 - rect.getHeight() / 2
                            - rect.getY(), 0));
                    x += rect.getWidth();
                } else {
                    comp.setLocalXY(Math.max(container.getContentWidth() / 2 - rect.getWidth() / 2 - rect.getX(), 0), y
                            - rect.getY());
                    y += rect.getHeight();
                }
            }
        }

        Rectangle2.releaseTempInstance(storeA);
View Full Code Here

        int minW = 0, minH = 0;
        if (container.getNumberOfChildren() > 0) {
            final List<Spatial> content = container.getChildren();

            // compute the min width and height of the container
            final Rectangle2 store = new Rectangle2();
            for (final Spatial s : content) {
                if (!(s instanceof UIComponent)) {
                    continue;
                }
                final UIComponent comp = (UIComponent) s;
                final Rectangle2 rect = comp.getRelativeMinComponentBounds(store);
                if (_horizontal) {
                    minW += rect.getWidth();
                    if (minH < rect.getHeight()) {
                        minH = rect.getHeight();
                    }
                } else {
                    if (minW < rect.getWidth()) {
                        minW = rect.getWidth();
                    }
                    minH += rect.getHeight();
                }
            }
        }
        container.setMinimumContentSize(minW, minH);
    }
View Full Code Here

    }

    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;
    }
View Full Code Here

    }

    private int getSumOfAllWidths(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.getWidth();
                }
            }
        }
        return sum;
    }
View Full Code Here

    private void visit(final UIComponent toVisit) {
        // get the anchor record (if any) for this component
        final AnchorRecord aRecord = _records.get(toVisit);
        if (aRecord != null) {
            final Rectangle2 rect = new Rectangle2();
            for (int x = aRecord.dependants.size(); --x >= 0;) {
                final UIComponent dep = aRecord.dependants.get(x);
                if (dep.getLayoutData() instanceof AnchorLayoutData) {
                    dep.getRelativeComponentBounds(rect);
                    AnchorLayout.applyAnchor(dep, (AnchorLayoutData) dep.getLayoutData());

                    // update min/max
                    final int posX = Math.round(dep.getTranslation().getXf()) + rect.getWidth() - rect.getX();
                    final int negX = Math.round(dep.getTranslation().getXf()) - rect.getX();
                    final int posY = Math.round(dep.getTranslation().getYf()) + rect.getHeight() - rect.getY();
                    final int negY = Math.round(dep.getTranslation().getYf()) - rect.getY();
                    if (posX > _maxX) {
                        _maxX = posX;
                    }
                    if (posY > _maxY) {
                        _maxY = posY;
View Full Code Here

     * @param store
     *            the object to store our results in. If null, a new Rectangle2 is created and returned.
     * @return
     */
    public Rectangle2 getRelativeMinComponentBounds(final Rectangle2 store) {
        Rectangle2 rVal = store;
        if (rVal == null) {
            rVal = new Rectangle2();
        }
        final int height = getMinimumLocalComponentHeight();
        final int width = getMinimumLocalComponentWidth();
        return getRelativeComponentBounds(rVal, width, height);
    }
View Full Code Here

TOP

Related Classes of com.ardor3d.math.Rectangle2

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.