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

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

Introduction

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

Prototype

public float getOriginY() 

Source Link

Usage

From source file:com.bagon.matchteam.mtx.utils.UtilsOrigin.java

License:Apache License

private static void setOrigin(Actor actor, Origin origin) {
    switch (origin) {
    case CENTER:/*www.  j  a  v  a 2s  .c o  m*/
        actor.setOrigin(actor.getWidth() / 2.0f, actor.getHeight() / 2.0f);
        break;
    case TOP_LEFT:
        actor.setOrigin(0.0f, actor.getHeight());
        break;
    case TOP_RIGHT:
        actor.setOrigin(actor.getWidth(), actor.getHeight());
        break;
    case BOTTOM_LEFT:
        actor.setOrigin(0.0f, 0.0f);
        break;
    case BOTTOM_RIGHT:
        actor.setOrigin(actor.getWidth(), 0.0f);
        break;
    case LEFT_CENTER:
        actor.setOrigin(0.0f, actor.getHeight() / 2.0f);
        break;
    case TOP_CENTER:
        actor.setOrigin(actor.getWidth() / 2.0f, actor.getHeight());
        break;
    case BOTTOM_CENTER:
        actor.setOrigin(actor.getWidth() / 2.0f, 0.0f);
        break;
    case RIGHT_CENTER:
        actor.setOrigin(actor.getWidth(), actor.getHeight() / 2.0f);
        break;
    default:
        actor.setOrigin(actor.getOriginX(), actor.getOriginY());
        break;
    }
}

From source file:com.sawan.mathattack.utils.UtilsOrigin.java

License:Open Source License

/**
 * Sets the origin./*from   w  w w  .  j av  a2s .c  om*/
 *
 * @param actor the actor
 * @param origin the origin
 */
private static void setOrigin(Actor actor, Origin origin) {
    switch (origin) {
    case CENTER:
        actor.setOrigin(actor.getWidth() / 2.0f, actor.getHeight() / 2.0f);
        break;
    case TOP_LEFT:
        actor.setOrigin(0.0f, actor.getHeight());
        break;
    case TOP_RIGHT:
        actor.setOrigin(actor.getWidth(), actor.getHeight());
        break;
    case BOTTOM_LEFT:
        actor.setOrigin(0.0f, 0.0f);
        break;
    case BOTTOM_RIGHT:
        actor.setOrigin(actor.getWidth(), 0.0f);
        break;
    case LEFT_CENTER:
        actor.setOrigin(0.0f, actor.getHeight() / 2.0f);
        break;
    case TOP_CENTER:
        actor.setOrigin(actor.getWidth() / 2.0f, actor.getHeight());
        break;
    case BOTTOM_CENTER:
        actor.setOrigin(actor.getWidth() / 2.0f, 0.0f);
        break;
    case RIGHT_CENTER:
        actor.setOrigin(actor.getWidth(), actor.getHeight() / 2.0f);
        break;
    default:
        actor.setOrigin(actor.getOriginX(), actor.getOriginY());
        break;
    }
}

From source file:com.uwsoft.editor.gdx.actors.SelectionRectangle.java

License:Apache License

public void update() {
    //setX(getHostAsActor().getX() - ((getHostAsActor().getScaleX()-1)*getHostAsActor().getWidth()/2));
    //setY(getHostAsActor().getY() - ((getHostAsActor().getScaleY()-1)*getHostAsActor().getHeight()/2));
    Actor hostAsActor = getHostAsActor();
    setX(hostAsActor.getX());//from   w  ww. j  av  a  2s  .  c o m
    setY(hostAsActor.getY());
    setOriginX(hostAsActor.getOriginX());
    setOriginY(hostAsActor.getOriginY());
    setRotation(hostAsActor.getRotation());
    setWidth(hostAsActor.getWidth() * (hostAsActor instanceof LabelItem ? 1 : hostAsActor.getScaleX()));
    setHeight(hostAsActor.getHeight() * (hostAsActor instanceof LabelItem ? 1 : hostAsActor.getScaleY()));

    positionTransformables();
}

From source file:es.eucm.ead.editor.control.actions.model.scene.ActorTransformToEntity.java

License:Open Source License

@Override
public CompositeCommand perform(Object... args) {
    Actor actor = (Actor) args[0];
    ModelEntity modelEntity = Q.getModelEntity(actor);

    if (modelEntity == null) {
        return null;
    }/*from   w  ww .  j  a v a2s. co m*/

    CompositeCommand compositeCommand = super.perform(args);

    if (actor.getOriginX() != modelEntity.getOriginX()) {
        compositeCommand.addCommand(new FieldCommand(modelEntity, FieldName.ORIGIN_X, actor.getOriginX()));
    }

    if (actor.getOriginY() != modelEntity.getOriginY()) {
        compositeCommand.addCommand(new FieldCommand(modelEntity, FieldName.ORIGIN_Y, actor.getOriginY()));
    }

    if (actor.getRotation() != modelEntity.getRotation()) {
        compositeCommand.addCommand(new FieldCommand(modelEntity, FieldName.ROTATION, actor.getRotation()));
    }

    if (actor.getScaleX() != modelEntity.getScaleX()) {
        compositeCommand.addCommand(new FieldCommand(modelEntity, FieldName.SCALE_X, actor.getScaleX()));
    }

    if (actor.getScaleY() != modelEntity.getScaleY()) {
        compositeCommand.addCommand(new FieldCommand(modelEntity, FieldName.SCALE_Y, actor.getScaleY()));
    }

    return compositeCommand;
}

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

License:Open Source License

/**
 * Applies the current transformation represented by the handles to given
 * actor/*ww w . j av  a  2s. c om*/
 */
public void applyTransformation(Actor influencedActor, Vector2 origin, Vector2 tangent, Vector2 normal) {
    /*
     * We are going to calculate the affine transformation for the actor to
     * fit the bounds represented by the handles. The affine transformation
     * is defined as follows:
     */
    // |a b tx|
    // |c d ty|=|Translation Matrix| x |Scale Matrix| x |Rotation
    // Matrix|
    // |0 0 1 |
    /*
     * More info about affine transformations:
     * https://people.gnome.org/~mathieu
     * /libart/libart-affine-transformation-matrices.html, To obtain the
     * matrix, we want to resolve the following equation system:
     */
    // | a b tx| |0| |o.x|
    // | c d ty|*|0|=|o.y|
    // | 0 0 1 | |1| | 1 |
    //
    // | a b tx| |w| |t.x|
    // | c d ty|*|0|=|t.y|
    // | 0 0 1 | |1| | 1 |
    //
    // | a b tx| |0| |n.x|
    // | c d ty|*|h|=|n.y|
    // | 0 0 1 | |1| | 1 |
    /*
     * where o is handles[0] (origin), t is handles[2] (tangent) and n is
     * handles[6] (normal), w is actor.getWidth() and h is
     * actor.getHeight().
     * 
     * This matrix defines that the 3 points defining actor bounds are
     * transformed to the 3 points defining modifier bounds. E.g., we want
     * that actor origin (0,0) is transformed to (handles[0].x,
     * handles[0].y), and that is expressed in the first equation.
     * 
     * Resolving these equations is obtained:
     */
    // a = (t.x - o.y) / w
    // b = (t.y - o.y) / w
    // c = (n.x - o.x) / h
    // d = (n.y - o.y) / h
    /*
     * Values for translation, scale and rotation contained by the matrix
     * can be obtained directly making operations over a, b, c and d:
     */
    // tx = o.x
    // ty = o.y
    // sx = sqrt(a^2+b^2)
    // sy = sqrt(c^2+d^2)
    // rotation = atan(c/d)
    // or
    // rotation = atan(-b/a)
    /*
     * Rotation can give two different values (this happens when there is
     * more than one way of obtaining the same transformation). To avoid
     * that, we ignore the rotation to obtain the final values.
     */

    Vector2 o = tmp1.set(origin.x, origin.y);
    Vector2 t = tmp2.set(tangent.x, tangent.y);
    Vector2 n = tmp3.set(normal.x, normal.y);

    Vector2 vt = tmp4.set(t).sub(o);
    Vector2 vn = tmp5.set(n).sub(o);

    // Ignore rotation
    float rotation = influencedActor.getRotation();
    vt.rotate(-rotation);
    vn.rotate(-rotation);

    t.set(vt).add(o);
    n.set(vn).add(o);

    float a = (t.x - o.x) / influencedActor.getWidth();
    float c = (t.y - o.y) / influencedActor.getWidth();
    float b = (n.x - o.x) / influencedActor.getHeight();
    float d = (n.y - o.y) / influencedActor.getHeight();

    // Math.sqrt gives a positive value, but it also have a negatives.
    // The
    // signum is calculated computing the current rotation
    float signumX = vt.angle() > 90.0f && vt.angle() < 270.0f ? -1.0f : 1.0f;
    float signumY = vn.angle() > 180.0f ? -1.0f : 1.0f;

    float scaleX = (float) Math.sqrt(a * a + b * b) * signumX;
    float scaleY = (float) Math.sqrt(c * c + d * d) * signumY;

    influencedActor.setScale(scaleX, scaleY);

    /*
     * To obtain the correct translation value we need to subtract the
     * amount of translation due to the origin.
     */
    tmpMatrix.setToTranslation(influencedActor.getOriginX(), influencedActor.getOriginY());
    tmpMatrix.rotate(influencedActor.getRotation());
    tmpMatrix.scale(influencedActor.getScaleX(), influencedActor.getScaleY());
    tmpMatrix.translate(-influencedActor.getOriginX(), -influencedActor.getOriginY());

    /*
     * Now, the matrix has how much translation is due to the origin
     * involved in the rotation and scaling operations
     */
    float x = o.x - tmpMatrix.getValues()[Matrix3.M02];
    float y = o.y - tmpMatrix.getValues()[Matrix3.M12];
    influencedActor.setPosition(x, y);
}

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

License:Open Source License

public void setSelectedWidget(int index) {
    if (widgets.size > index) {
        Actor newBar = widgets.get(index);

        if (newBar != toShow) {
            Color color = colors.get(index);
            setColor(color == null ? style.color : color);

            for (Actor widget : widgets) {
                widget.clearActions();//w w  w. jav  a2 s.  c  om
            }

            Actor current = getActor();
            if (current != null) {
                current.setTouchable(Touchable.disabled);
            } else {
                current = toShow;
            }

            toShow = newBar;

            Actor toHide = current;
            toHide.setOrigin(Align.center);

            if (toShow.getScaleY() == 1) {
                toShow.setScaleY(0);
                toShow.setOriginY(toHide.getOriginY());
                toShow.getColor().a = 0;
            }

            float timeHide = ANIM_TIME * Math.abs(toHide.getScaleY());

            Action actionShow = Actions.run(actionAddActor);
            Action actionHide = Actions.parallel(Actions.scaleTo(1, 0, timeHide, Interpolation.sineOut),
                    Actions.fadeOut(timeHide));

            if (newBar == current) {
                toHide.addAction(actionShow);
            } else {
                toHide.addAction(Actions.sequence(actionHide, actionShow));
            }
        }
    }
}

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

License:Open Source License

/**
 * Sets position, rotation, scale and origin in actor to meet the 3 given
 * points/*ww  w .jav a  2  s  .c  om*/
 */
public static void applyTransformation(Actor actor, Vector2 origin, Vector2 tangent, Vector2 normal) {
    /*
     * We are going to calculate the affine transformation for the actor to
     * fit the bounds represented by the handles. The affine transformation
     * is defined as follows:
     */
    // |a b tx|
    // |c d ty|=|Translation Matrix| x |Scale Matrix| x |Rotation
    // Matrix|
    // |0 0 1 |
    /*
     * More info about affine transformations:
     * https://people.gnome.org/~mathieu
     * /libart/libart-affine-transformation-matrices.html, To obtain the
     * matrix, we want to resolve the following equation system:
     */
    // | a b tx| |0| |o.x|
    // | c d ty|*|0|=|o.y|
    // | 0 0 1 | |1| | 1 |
    //
    // | a b tx| |w| |t.x|
    // | c d ty|*|0|=|t.y|
    // | 0 0 1 | |1| | 1 |
    //
    // | a b tx| |0| |n.x|
    // | c d ty|*|h|=|n.y|
    // | 0 0 1 | |1| | 1 |
    /*
     * where o is handles[0] (origin), t is handles[2] (tangent) and n is
     * handles[6] (normal), w is actor.getWidth() and h is
     * actor.getHeight().
     * 
     * This matrix defines that the 3 points defining actor bounds are
     * transformed to the 3 points defining modifier bounds. E.g., we want
     * that actor origin (0,0) is transformed to (handles[0].x,
     * handles[0].y), and that is expressed in the first equation.
     * 
     * Resolving these equations is obtained:
     */
    // a = (t.x - o.y) / w
    // b = (t.y - o.y) / w
    // c = (n.x - o.x) / h
    // d = (n.y - o.y) / h
    /*
     * Values for translation, scale and rotation contained by the matrix
     * can be obtained directly making operations over a, b, c and d:
     */
    // tx = o.x
    // ty = o.y
    // sx = sqrt(a^2+b^2)
    // sy = sqrt(c^2+d^2)
    // rotation = atan(c/d)
    // or
    // rotation = atan(-b/a)
    /*
     * Rotation can give two different values (this happens when there is
     * more than one way of obtaining the same transformation). To avoid
     * that, we ignore the rotation to obtain the final values.
     */

    Vector2 tmp1 = Pools.obtain(Vector2.class);
    Vector2 tmp2 = Pools.obtain(Vector2.class);
    Vector2 tmp3 = Pools.obtain(Vector2.class);
    Vector2 tmp4 = Pools.obtain(Vector2.class);
    Vector2 tmp5 = Pools.obtain(Vector2.class);

    Vector2 o = tmp1.set(origin.x, origin.y);
    Vector2 t = tmp2.set(tangent.x, tangent.y);
    Vector2 n = tmp3.set(normal.x, normal.y);

    Vector2 vt = tmp4.set(t).sub(o);
    Vector2 vn = tmp5.set(n).sub(o);

    // Ignore rotation
    float rotation = actor.getRotation();
    vt.rotate(-rotation);
    vn.rotate(-rotation);

    t.set(vt).add(o);
    n.set(vn).add(o);

    Vector2 bottomLeft = Pools.obtain(Vector2.class);
    Vector2 size = Pools.obtain(Vector2.class);

    calculateBounds(actor, bottomLeft, size);

    float a = (t.x - o.x) / size.x;
    float c = (t.y - o.y) / size.x;
    float b = (n.x - o.x) / size.y;
    float d = (n.y - o.y) / size.y;

    Pools.free(tmp1);
    Pools.free(tmp2);
    Pools.free(tmp3);
    Pools.free(tmp4);
    Pools.free(tmp5);
    Pools.free(bottomLeft);
    Pools.free(size);

    // Math.sqrt gives a positive value, but it also have a negatives.
    // The
    // signum is calculated computing the current rotation
    float signumX = vt.angle() > 90.0f && vt.angle() < 270.0f ? -1.0f : 1.0f;
    float signumY = vn.angle() > 180.0f ? -1.0f : 1.0f;

    float scaleX = (float) Math.sqrt(a * a + b * b) * signumX;
    float scaleY = (float) Math.sqrt(c * c + d * d) * signumY;

    actor.setScale(scaleX, scaleY);

    /*
     * To obtain the correct translation value we need to subtract the
     * amount of translation due to the origin.
     */
    tmpMatrix.setToTranslation(actor.getOriginX(), actor.getOriginY());
    tmpMatrix.rotate(actor.getRotation());
    tmpMatrix.scale(actor.getScaleX(), actor.getScaleY());
    tmpMatrix.translate(-actor.getOriginX(), -actor.getOriginY());

    /*
     * Now, the matrix has how much translation is due to the origin
     * involved in the rotation and scaling operations
     */
    float x = o.x - tmpMatrix.getValues()[Matrix3.M02];
    float y = o.y - tmpMatrix.getValues()[Matrix3.M12];
    actor.setPosition(x, y);
}

From source file:mobi.shad.s3lib.gui.GuiUtil.java

License:Apache License

/**
 * @param source/*  ww w . j a v a 2  s  . c  om*/
 * @param destination
 */
public static void copyActor(Actor source, Actor destination) {
    destination.setBounds(source.getX(), source.getY(), source.getWidth(), source.getHeight());
    destination.setColor(source.getColor());
    destination.setName(source.getName());
    destination.setOrigin(source.getOriginX(), source.getOriginY());
    destination.setRotation(source.getRotation());
    destination.setScale(source.getScaleX(), source.getScaleY());
    destination.setTouchable(source.getTouchable());
    destination.setUserObject(source.getUserObject());
    destination.setVisible(source.isVisible());
    destination.setZIndex(source.getZIndex());
    destination.getStage();
}

From source file:net.mwplay.cocostudio.ui.BaseWidgetParser.java

License:Apache License

/**
 * common attribute parser//from   ww w.j  a  va2s  .co m
 * according cocstudio ui setting properties of the configuration file
 *
 * @param editor
 * @param widget
 * @param parent
 * @param actor
 * @return
 */
public Actor commonParse(CocoStudioUIEditor editor, ObjectData widget, Group parent, Actor actor) {
    this.editor = editor;
    actor.setName(widget.getName());
    actor.setSize(widget.getSize().getX(), widget.getSize().getY());
    // set origin
    if (widget.getAnchorPoint() != null) {
        actor.setOrigin(widget.getAnchorPoint().getScaleX() * actor.getWidth(),
                widget.getAnchorPoint().getScaleY() * actor.getHeight());
    }

    //?Postion
    if (widget.getPosition() != null) {
        actor.setPosition(widget.getPosition().getX() - actor.getOriginX(),
                widget.getPosition().getY() - actor.getOriginY());
    }

    // CocoStudioScaleX,ScaleY 
    //?Scale
    if (widget.getScale() != null) {
        actor.setScale(widget.getScale().getScaleX(), widget.getScale().getScaleY());
    }

    if (widget.getRotation() != 0) {// CocoStudio ?,?.
        actor.setRotation(360 - widget.getRotation() % 360);
    }
    //
    if (widget.getRotationSkewX() != 0 && widget.getRotationSkewX() == widget.getRotationSkewY()) {
        actor.setRotation(360 - widget.getRotationSkewX() % 360);
    }

    // ??
    actor.setVisible(widget.isVisibleForFrame());

    Color color = editor.getColor(widget.getCColor(), widget.getAlpha());

    actor.setColor(color);

    actor.setTouchable(deduceTouchable(actor, widget));

    // callback

    addCallback(actor, widget);
    // callback

    addActor(editor, actor, widget);

    if (widget.getChildren() == null || widget.getChildren().size() == 0) {
        //Action
        parseAction(actor, widget);

        return actor;
    }

    return null;
}

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

License:Apache License

public TImage origon(Actor actor) {
    setOrigin(actor.getOriginX(), actor.getOriginY());
    return this;
}