Example usage for com.badlogic.gdx.scenes.scene2d Actor localToParentCoordinates

List of usage examples for com.badlogic.gdx.scenes.scene2d Actor localToParentCoordinates

Introduction

In this page you can find the example usage for com.badlogic.gdx.scenes.scene2d Actor localToParentCoordinates.

Prototype

public Vector2 localToParentCoordinates(Vector2 localCoords) 

Source Link

Document

Transforms the specified point in the actor's coordinates to be in the parent's coordinates.

Usage

From source file:es.eucm.ead.editor.view.widgets.groupeditor.Modifier.java

License:Open Source License

/**
 * Calculate the bounds of the given actors as a group
 * /*w w w .  j av  a 2s .co  m*/
 * @param actors
 *            the actors
 * @param resultOrigin
 *            result origin of the bounds
 * @param resultSize
 *            result size of the bounds
 */
public void calculateBounds(Array<Actor> actors, Vector2 resultOrigin, Vector2 resultSize) {
    resultOrigin.set(0, 0);
    resultSize.set(0, 0);
    if (actors.size == 0) {
        return;
    }

    float minX = Float.POSITIVE_INFINITY;
    float minY = Float.POSITIVE_INFINITY;
    float maxX = Float.NEGATIVE_INFINITY;
    float maxY = Float.NEGATIVE_INFINITY;
    for (Actor actor : actors) {
        // Ignore the modifier itself to calculate bounds
        if (actor != this) {
            tmp1.set(0, 0);
            tmp2.set(actor.getWidth(), 0);
            tmp3.set(0, actor.getHeight());
            tmp4.set(actor.getWidth(), actor.getHeight());
            actor.localToParentCoordinates(tmp1);
            actor.localToParentCoordinates(tmp2);
            actor.localToParentCoordinates(tmp3);
            actor.localToParentCoordinates(tmp4);

            minX = Math.min(minX, Math.min(tmp1.x, Math.min(tmp2.x, Math.min(tmp3.x, tmp4.x))));
            minY = Math.min(minY, Math.min(tmp1.y, Math.min(tmp2.y, Math.min(tmp3.y, tmp4.y))));
            maxX = Math.max(maxX, Math.max(tmp1.x, Math.max(tmp2.x, Math.max(tmp3.x, tmp4.x))));
            maxY = Math.max(maxY, Math.max(tmp1.y, Math.max(tmp2.y, Math.max(tmp3.y, tmp4.y))));
        }
    }
    resultOrigin.set(minX, minY);
    resultSize.set(maxX - minX, maxY - minY);
}

From source file:es.eucm.ead.engine.utils.EngineUtils.java

License:Open Source License

/**
 * Calculate the bounds of the given actors as a group
 * //from  w  w w .j a  va  2s  .c o  m
 * @param actors
 *            the actors
 * @param resultOrigin
 *            result origin of the bounds
 * @param resultSize
 *            result size of the bounds
 */
public static void calculateBounds(Array<Actor> actors, Vector2 resultOrigin, Vector2 resultSize) {
    resultOrigin.set(0, 0);
    resultSize.set(0, 0);
    if (actors.size == 0) {
        return;
    }

    Vector2 origin = Pools.obtain(Vector2.class);
    Vector2 size = Pools.obtain(Vector2.class);
    Vector2 leftTop = Pools.obtain(Vector2.class);
    Vector2 rightBottom = Pools.obtain(Vector2.class);
    float minX = Float.POSITIVE_INFINITY;
    float minY = Float.POSITIVE_INFINITY;
    float maxX = Float.NEGATIVE_INFINITY;
    float maxY = Float.NEGATIVE_INFINITY;
    for (Actor actor : actors) {
        calculateBounds(actor, origin, size);
        size.add(origin);
        leftTop.set(origin.x, size.y);
        rightBottom.set(size.x, origin.y);
        actor.localToParentCoordinates(origin);
        actor.localToParentCoordinates(size);
        actor.localToParentCoordinates(leftTop);
        actor.localToParentCoordinates(rightBottom);

        minX = Math.min(minX, Math.min(origin.x, Math.min(size.x, Math.min(leftTop.x, rightBottom.x))));
        minY = Math.min(minY, Math.min(origin.y, Math.min(size.y, Math.min(leftTop.y, rightBottom.y))));
        maxX = Math.max(maxX, Math.max(origin.x, Math.max(size.x, Math.max(leftTop.x, rightBottom.x))));
        maxY = Math.max(maxY, Math.max(origin.y, Math.max(size.y, Math.max(leftTop.y, rightBottom.y))));
    }
    Pools.free(origin);
    Pools.free(size);
    Pools.free(leftTop);
    Pools.free(rightBottom);
    resultOrigin.set(minX, minY);
    resultSize.set(maxX - minX, maxY - minY);
}