Package com.ardor3d.math

Examples of com.ardor3d.math.Rectangle2


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


     * @param store
     *            the object to store our results in. If null, a new Rectangle2 is created and returned.
     * @return the current bounds of this component, in the coordinate space of its parent.
     */
    public Rectangle2 getRelativeComponentBounds(final Rectangle2 store) {
        Rectangle2 rVal = store;
        if (rVal == null) {
            rVal = new Rectangle2();
        }
        final int height = getLocalComponentHeight();
        final int width = getLocalComponentWidth();
        return getRelativeComponentBounds(rVal, width, height);
    }
View Full Code Here

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

    private static Vector2 getOffsets(final UIComponent comp, final Alignment point, Vector2 store) {
        if (store == null) {
            store = new Vector2();
        }

        final Rectangle2 rect = new Rectangle2();
        comp.getRelativeComponentBounds(rect);
        switch (point) {
            case TOP_LEFT:
                store.set(rect.getX(), rect.getHeight() + rect.getY());
                break;
            case TOP:
                store.set(rect.getWidth() / 2f + rect.getX(), rect.getHeight() + rect.getY());
                break;
            case TOP_RIGHT:
                store.set(rect.getWidth() + rect.getX(), rect.getHeight() + rect.getY());
                break;
            case LEFT:
                store.set(rect.getX(), rect.getHeight() / 2f + rect.getY());
                break;
            case MIDDLE:
                store.set(rect.getWidth() / 2f + rect.getX(), rect.getHeight() / 2f + rect.getY());
                break;
            case RIGHT:
                store.set(rect.getWidth() + rect.getX(), rect.getHeight() / 2f + rect.getY());
                break;
            case BOTTOM_LEFT:
                store.set(rect.getX(), rect.getY());
                break;
            case BOTTOM:
                store.set(rect.getWidth() / 2f + rect.getX(), rect.getY());
                break;
            case BOTTOM_RIGHT:
                store.set(rect.getWidth() + rect.getX(), rect.getY());
                break;
        }

        return store;
    }
View Full Code Here

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

        int heightNorth = 0;
        int heightSouth = 0;
        final List<Spatial> content = container.getChildren();

        // Go through each component in the given container and determine the width and height of our edges.
        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 data = (BorderLayoutData) comp.getLayoutData();
            if (data != null) {
                switch (data) {
                    case NORTH:
                        heightNorth = store.getHeight();
                        break;
                    case SOUTH:
                        heightSouth = store.getHeight();
                        break;
                    case EAST:
                        widthEast = store.getWidth();
                        break;
                    case WEST:
                        widthWest = store.getWidth();
                        break;
                    case CENTER:
                        // nothing to do
                        break;
                }
            }
        }

        // Using the information from the last pass, set the position and size of each component in the container.
        for (final Spatial s : content) {
            if (!(s instanceof UIComponent)) {
                continue;
            }
            final UIComponent comp = (UIComponent) s;
            comp.getRelativeMinComponentBounds(store);

            final BorderLayoutData data = (BorderLayoutData) comp.getLayoutData();

            if (data != null) {
                switch (data) {
                    case NORTH:
                        comp.fitComponentIn(container.getContentWidth(), store.getHeight());
                        comp.getRelativeComponentBounds(store);
                        comp.setLocalXY(-store.getX(), container.getContentHeight() - heightNorth - store.getY());
                        break;
                    case SOUTH:
                        comp.fitComponentIn(container.getContentWidth(), store.getHeight());
                        comp.getRelativeComponentBounds(store);
                        comp.setLocalXY(-store.getX(), -store.getY());
                        break;
                    case EAST:
                        comp.fitComponentIn(store.getWidth(), container.getContentHeight() - heightNorth - heightSouth);
                        comp.getRelativeComponentBounds(store);
                        comp.setLocalXY(container.getContentWidth() - store.getWidth() - 1 - store.getX(), heightSouth
                                - store.getY());
                        break;
                    case WEST:
                        comp.fitComponentIn(store.getWidth(), container.getContentHeight() - heightNorth - heightSouth);
                        comp.getRelativeComponentBounds(store);
                        comp.setLocalXY(-store.getX(), heightSouth - store.getY());
                        break;
                    case CENTER:
                        comp.fitComponentIn(container.getContentWidth() - widthEast - widthWest, container
                                .getContentHeight()
                                - heightSouth - heightNorth);
                        comp.getRelativeComponentBounds(store);
                        comp.setLocalXY(widthWest - store.getX(), heightSouth - store.getY());
                }
            }
        }
    }
View Full Code Here

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

    private int getMinimumWidth(final List<Spatial> content) {
        int minWidth = 0;
        int maxNSWidth = 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 data = (BorderLayoutData) comp.getLayoutData();
                if (data == BorderLayoutData.EAST || data == BorderLayoutData.WEST || data == BorderLayoutData.CENTER
                        || data == null) {
                    minWidth += store.getWidth();
                } else {
                    final int width = store.getWidth();
                    if (width > maxNSWidth) {
                        maxNSWidth = width;
                    }
                }
View Full Code Here

    public static void applyScissors(final RendererRecord rendRecord) {
        final GL gl = GLContext.getCurrentGL();
        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);
                gl.glScissor(init.getX(), init.getY(), init.getWidth(), init.getHeight());
            }
            Rectangle2.releaseTempInstance(init);
        } else {
            // no clips, so disable
            setClippingEnabled(rendRecord, false);
View Full Code Here

    public AtlasPacker(final int width, final int height) {
        rootNode = new AtlasNode(width, height);
    }

    public AtlasNode insert(final int width, final int height) {
        return rootNode.insert(new Rectangle2(0, 0, 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.