Example usage for com.badlogic.gdx.math Rectangle Rectangle

List of usage examples for com.badlogic.gdx.math Rectangle Rectangle

Introduction

In this page you can find the example usage for com.badlogic.gdx.math Rectangle Rectangle.

Prototype

public Rectangle(Rectangle rect) 

Source Link

Document

Constructs a rectangle based on the given rectangle

Usage

From source file:com.kotcrab.vis.editor.module.scene.entitymanipulator.tool.AbstractGizmoTool.java

License:Apache License

@Override
public void render(ShapeRenderer shapeRenderer) {
    super.render(shapeRenderer);

    totalSelectionBounds = null;//  w w w .  jav a  2s  . c o  m

    for (SelectionFragment fragment : entityManipulator.getFragmentedSelection()) {
        Rectangle fragBounds = fragment.getBoundingRectangle();

        if (totalSelectionBounds == null)
            totalSelectionBounds = new Rectangle(fragBounds);
        else
            totalSelectionBounds.merge(fragBounds);
    }
}

From source file:com.kotcrab.vis.ui.widget.VisSplitPane.java

License:Apache License

/** @return first widgets bounds, changing returned rectangle values does not have any effect */
public Rectangle getFirstWidgetBounds() {
    return new Rectangle(firstWidgetBounds);
}

From source file:com.kotcrab.vis.ui.widget.VisSplitPane.java

License:Apache License

/** @return seconds widgets bounds, changing returned rectangle values does not have any effect */
public Rectangle getSecondWidgetBounds() {
    return new Rectangle(secondWidgetBounds);
}

From source file:com.laex.cg2d.screeneditor.handlers.ImportScreenContentsDialog.java

License:Open Source License

@Override
protected void okPressed() {
    // Before we proceed, we ask the user to save the file
    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor()
            .doSave(new NullProgressMonitor());

    String resFile = list.getSelection()[0];

    for (IResource res : resList) {
        if (res.getName().equals(resFile)) {
            IFile file = (IFile) res;//  w  w  w .  j av  a  2 s. c om
            try {
                CGScreenModel model = CGScreenModel.parseFrom(file.getContents());

                GameModel gameModel = ScreenModelAdapter.asGameModel(model);

                GameModel thisScreenModel = ScreenEditorUtil.getScreenModel();

                CompoundCommand cc = new CompoundCommand();

                boolean createNewLayer = btnImportInNew.getSelection();

                ILayerManager layerMgr = ScreenEditorUtil.getScreenLayerManager();
                Layer layer = null;

                if (createNewLayer) {
                    int newLayerId = layerMgr.getNewLayerId();
                    layer = new Layer(newLayerId, txtNewLayerName.getText() + newLayerId, true, false);
                    LayerAddCommand layerAddCmd = new LayerAddCommand(layer, thisScreenModel.getDiagram());
                    cc.add(layerAddCmd);
                } else {
                    // Use existing layer
                    layer = layerMgr.getCurrentLayer();

                    if (layer == null) {
                        // If we have layers, use the first one
                        if (layerMgr.layerCount() > 0) {
                            layer = layerMgr.getLayerAt(0);
                        } else {
                            MessageBox mb = new MessageBox(getShell(), SWT.ERROR);
                            mb.setMessage(
                                    "There are no layers in the screen. Please select the \"import\" feature before continuting");
                            mb.setText("No Layers in the screen");
                            mb.open();
                            return;
                        }
                    }
                }

                /*
                 * We need an id creator for model we're currently working on. not of
                 * the file were trying to import from.
                 */
                IDCreationStrategy idCreator = IDCreationStrategyFactory
                        .getIDCreator(ScreenEditorUtil.getScreenModel());

                int index = 0;

                for (int i = 0; i < txtColumnsRepeat.getSelection(); i++) {

                    for (Shape shape : gameModel.getDiagram().getChildren()) {
                        // add suffix to id
                        // TODO: Create a shape cloning mechanism
                        ModelCopier shapeCopier = new ShapeCopier();

                        Shape newShape = (Shape) shapeCopier.copy(shape);
                        newShape.setParentLayer(layer);

                        // make sure our items are really unique
                        StringBuffer sb = new StringBuffer(shape.getId()).append(txtSuffix.getText())
                                .append(index++);
                        boolean isIdUsed = idCreator.isIdUsed(newShape.getEditorShapeType(), sb.toString());
                        if (isIdUsed) {
                            newShape.setId(idCreator.newId(newShape.getEditorShapeType()));
                        } else {
                            newShape.setId(sb.toString());
                        }

                        Rectangle r = new Rectangle(shape.getBounds()); // make sure to
                                                                        // make a copy of
                                                                        // the bounds and
                                                                        // then modify its
                                                                        // coords

                        if (shape.getEditorShapeType().isBackground()) {
                            r.x = i * shape.getBounds().getWidth() - 1;
                        } else {
                            r.x += i * thisScreenModel.getScreenPrefs().getCardPrefs().getCardWidth();
                        }

                        newShape.setBounds(r);

                        ShapeCreateCommand scc = new ShapeCreateCommand(newShape, thisScreenModel.getDiagram());
                        cc.add(scc);
                    }

                }

                commandStack.execute(cc);

            } catch (IOException e) {
                Activator.log(e);
            } catch (CoreException e) {
                Activator.log(e);
            }

        }
    }

    super.okPressed();
}

From source file:com.redtoorange.game.components.physics.BulletPhysicsComponent.java

License:Open Source License

/**
 * Create a new bullet./*  ww  w  . j a  va2 s .  c  o m*/
 *
 * @param physicsSystem    The world's physicsSystem.
 * @param controlledBullet The Bullet GameObject that this body controls.
 * @param spriteComponent  The SpriteComponent attached to the parent GameObject.
 */
public BulletPhysicsComponent(PhysicsSystem physicsSystem, Bullet controlledBullet,
        SpriteComponent spriteComponent) {
    super(physicsSystem);

    this.controlledBullet = controlledBullet;
    this.bulletSpeedMultiplier = controlledBullet.getSpeed();

    bulletBoundingRect = new Rectangle(spriteComponent.getBoundingBox());
    bulletBoundingRect.setSize(spriteComponent.getWidth() / 4f, spriteComponent.getHeight() / 4f);
}

From source file:com.ridiculousRPG.video.cortado.CortadoPlayerAppletWrapper.java

License:Open Source License

/**
 * Instantiates a new video player. Don't forget to dispose the player!
 * /*from  w  w w . j a v a  2s  .  c om*/
 * @param url
 *            url to ogg / ogv file
 * @param screenBounds
 *            the screen position, width and height
 * @param projectToMap
 *            Defines whether to project the video onto the map or onto the
 *            screen coordinates
 * @param withAudio
 *            if false, the audio channel will be disabled.
 */
public CortadoPlayerAppletWrapper(URL url, Rectangle screenBounds, boolean projectToMap, boolean withAudio,
        boolean drawPlaceholder) {
    this.screenBounds = new Rectangle(screenBounds);
    this.projectToMap = projectToMap;
    if (!projectToMap) {
        GameBase gb = GameBase.$();
        this.screenBounds.width /= gb.getScreen().width;
        this.screenBounds.height /= gb.getScreen().height;
        this.screenBounds.x /= gb.getScreen().width;
        this.screenBounds.y /= gb.getScreen().height;
    }
    int width = (int) screenBounds.width;
    int height = (int) screenBounds.height;

    textureRef = TextureRegionLoader.obtainEmptyRegion(width, height, Format.RGBA8888);
    if (drawPlaceholder) {
        Pixmap placeholder = new Pixmap(width, height, Format.RGBA8888);
        placeholder.setColor(0, 0, 0, 1);
        placeholder.fillRectangle(0, 0, width, height);
        placeholder.setColor(.7f, .7f, .7f, 1);
        placeholder.fillCircle(width / 2, height / 2, Math.min(width, height) / 3);
        placeholder.setColor(.4f, .4f, .4f, 1);
        placeholder.drawRectangle(0, 0, width, height);
        placeholder.drawRectangle(2, 2, width - 4, height - 4);
        placeholder.drawLine(1, 0, width, height - 1);
        placeholder.drawLine(0, 1, width - 1, height);
        placeholder.drawLine(1, height, width, 1);
        placeholder.drawLine(0, height - 1, width - 1, 0);
        textureRef.draw(placeholder);
        placeholder.dispose();
    }
    graphicsPixmap = new VideoARGBintPixmapWrapper();
    player = new CortadoPlayerApplet(graphicsPixmap);
    initPlayer();
    player.setParam("url", url.toString());
    player.setParam("audio", String.valueOf(withAudio));
    player.setSize(width, height);
    player.setStub(this);
    player.init();
    player.start();
}

From source file:com.rubentxu.juegos.core.utils.dermetfan.box2d.Box2DMapObjectParser.java

License:Apache License

/**
 * creates a {@link Fixture} from a {@link MapObject}
 *
 * @param mapObject the {@link MapObject} to parse
 * @return the parsed {@link Fixture}// w  w  w  .j a  v  a2s  .  c  o  m
 */
public Fixture createFixture(MapObject mapObject) {
    MapProperties properties = mapObject.getProperties();

    String type = properties.get("type", String.class);

    Body body = bodies.get(
            type.equals(aliases.object) ? mapObject.getName() : properties.get(aliases.body, String.class));

    if (!type.equals(aliases.fixture) && !type.equals(aliases.object))
        throw new IllegalArgumentException("type of " + mapObject + " is  \"" + type + "\" instead of \""
                + aliases.fixture + "\" or \"" + aliases.object + "\"");

    FixtureDef fixtureDef = new FixtureDef();
    Shape shape = null;

    if (mapObject instanceof RectangleMapObject) {
        shape = new PolygonShape();
        Rectangle rectangle = new Rectangle(((RectangleMapObject) mapObject).getRectangle());
        rectangle.x *= unitScale;
        rectangle.y *= unitScale;
        rectangle.width *= unitScale;
        rectangle.height *= unitScale;
        ((PolygonShape) shape).setAsBox(rectangle.width / 2, rectangle.height / 2,
                new Vector2(rectangle.x - body.getPosition().x + rectangle.width / 2,
                        rectangle.y - body.getPosition().y + rectangle.height / 2),
                body.getAngle());
    } else if (mapObject instanceof PolygonMapObject) {
        shape = new PolygonShape();
        Polygon polygon = ((PolygonMapObject) mapObject).getPolygon();
        polygon.setPosition(polygon.getX() * unitScale - body.getPosition().x,
                polygon.getY() * unitScale - body.getPosition().y);
        polygon.setScale(unitScale, unitScale);
        ((PolygonShape) shape).set(polygon.getTransformedVertices());
    } else if (mapObject instanceof PolylineMapObject) {
        shape = new ChainShape();
        Polyline polyline = ((PolylineMapObject) mapObject).getPolyline();
        polyline.setPosition(polyline.getX() * unitScale - body.getPosition().x,
                polyline.getY() * unitScale - body.getPosition().y);
        polyline.setScale(unitScale, unitScale);
        float[] vertices = polyline.getTransformedVertices();
        Vector2[] vectores = new Vector2[vertices.length / 2];
        for (int i = 0, j = 0; i < vertices.length; i += 2, j++) {
            vectores[j].x = vertices[i];
            vectores[j].y = vertices[i + 1];
        }
        ((ChainShape) shape).createChain(vectores);
    } else if (mapObject instanceof CircleMapObject) {
        shape = new CircleShape();
        Circle circle = ((CircleMapObject) mapObject).getCircle();
        circle.setPosition(circle.x * unitScale - body.getPosition().x,
                circle.y * unitScale - body.getPosition().y);
        circle.radius *= unitScale;
        ((CircleShape) shape).setPosition(new Vector2(circle.x, circle.y));
        ((CircleShape) shape).setRadius(circle.radius);
    } else if (mapObject instanceof EllipseMapObject) {
        Ellipse ellipse = ((EllipseMapObject) mapObject).getEllipse();

        /*
        b2ChainShape* chain = (b2ChainShape*)addr;
        b2Vec2* verticesOut = new b2Vec2[numVertices];
        for( int i = 0; i < numVertices; i++ )
        verticesOut[i] = b2Vec2(verts[i<<1], verts[(i<<1)+1]);
        chain->CreateChain( verticesOut, numVertices );
        delete verticesOut;
        */

        if (ellipse.width == ellipse.height) {
            CircleMapObject circleMapObject = new CircleMapObject(ellipse.x, ellipse.y, ellipse.width / 2);
            circleMapObject.setName(mapObject.getName());
            circleMapObject.getProperties().putAll(mapObject.getProperties());
            circleMapObject.setColor(mapObject.getColor());
            circleMapObject.setVisible(mapObject.isVisible());
            circleMapObject.setOpacity(mapObject.getOpacity());
            return createFixture(circleMapObject);
        }

        IllegalArgumentException exception = new IllegalArgumentException(
                "Cannot parse " + mapObject.getName() + " because  that are not circles are not supported");
        Gdx.app.error(getClass().getName(), exception.getMessage(), exception);
        throw exception;
    } else if (mapObject instanceof TextureMapObject) {
        IllegalArgumentException exception = new IllegalArgumentException(
                "Cannot parse " + mapObject.getName() + " because s are not supported");
        Gdx.app.error(getClass().getName(), exception.getMessage(), exception);
        throw exception;
    } else
        assert false : mapObject + " is a not known subclass of " + MapObject.class.getName();

    fixtureDef.shape = shape;
    fixtureDef.density = getProperty(properties, aliases.density, fixtureDef.density);
    fixtureDef.filter.categoryBits = getProperty(properties, aliases.categoryBits, GRUPO.STATIC.getCategory());
    fixtureDef.filter.groupIndex = getProperty(properties, aliases.groupIndex, fixtureDef.filter.groupIndex);
    fixtureDef.filter.maskBits = getProperty(properties, aliases.maskBits, Box2DPhysicsObject.MASK_STATIC);
    fixtureDef.friction = getProperty(properties, aliases.friciton, fixtureDef.friction);
    fixtureDef.isSensor = getProperty(properties, aliases.isSensor, fixtureDef.isSensor);
    fixtureDef.restitution = getProperty(properties, aliases.restitution, fixtureDef.restitution);

    Fixture fixture = body.createFixture(fixtureDef);
    fixture.setUserData(body.getUserData());
    shape.dispose();

    String name = mapObject.getName();
    if (fixtures.containsKey(name)) {
        int duplicate = 1;
        while (fixtures.containsKey(name + duplicate))
            duplicate++;
        name += duplicate;
    }

    fixtures.put(name, fixture);

    return fixture;
}

From source file:headmade.arttag.utils.MapUtils.java

License:Apache License

private static void createArtSensor(ArtTagScreen artTagScreen, final Art art) {
    Rectangle rectangle;//from   w  w  w .j  av a2 s . com
    // art sensor
    rectangle = new Rectangle(art.getRectangle());
    rectangle.y = MathUtils.floor(rectangle.y) + 0.1f;
    rectangle.height = 0.25f;
    final Body artTrigger = createSensor(artTagScreen, rectangle, ArtTag.CAT_ARTTRIGGER,
            ArtTag.MASK_ARTTRIGGER);
    artTrigger.setUserData(art);
    art.setArtTrigger(artTrigger);
}

From source file:headmade.arttag.utils.MapUtils.java

License:Apache License

private static Rectangle toWorldScale(Rectangle orgRect, float unitScale) {
    final Rectangle rectangle = new Rectangle(orgRect);
    rectangle.x *= unitScale;//from   w ww  .  ja va  2  s .  c  o  m
    rectangle.y *= unitScale;
    rectangle.height *= unitScale;
    rectangle.width *= unitScale;
    return rectangle;
}

From source file:net.mwplay.cocostudio.ui.widget.TImage.java

License:Apache License

public Rectangle copyBox() {
    return new Rectangle(box);
}