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

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

Introduction

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

Prototype

public void setOriginX(float originX) 

Source Link

Usage

From source file:com.agateau.ui.UiBuilder.java

License:Apache License

protected void applyActorProperties(Actor actor, XmlReader.Element element, Group parentActor) {
    AnchorGroup anchorGroup = null;/*from w w w.  java  2s.  c  o  m*/
    if (parentActor != null) {
        parentActor.addActor(actor);
        if (parentActor instanceof AnchorGroup) {
            anchorGroup = (AnchorGroup) parentActor;
        }
    }
    String attr = element.getAttribute("x", "");
    if (!attr.isEmpty()) {
        actor.setX(Float.parseFloat(attr));
    }
    attr = element.getAttribute("y", "");
    if (!attr.isEmpty()) {
        actor.setY(Float.parseFloat(attr));
    }
    attr = element.getAttribute("width", "");
    if (!attr.isEmpty()) {
        actor.setWidth(Float.parseFloat(attr));
    }
    attr = element.getAttribute("height", "");
    if (!attr.isEmpty()) {
        actor.setHeight(Float.parseFloat(attr));
    }
    attr = element.getAttribute("originX", "");
    if (!attr.isEmpty()) {
        actor.setOriginX(Float.parseFloat(attr));
    }
    attr = element.getAttribute("originY", "");
    if (!attr.isEmpty()) {
        actor.setOriginY(Float.parseFloat(attr));
    }
    attr = element.getAttribute("visible", "");
    if (!attr.isEmpty()) {
        actor.setVisible(Boolean.parseBoolean(attr));
    }
    attr = element.getAttribute("color", "");
    if (!attr.isEmpty()) {
        actor.setColor(Color.valueOf(attr));
    }
    attr = element.getAttribute("debug", "");
    if (!attr.isEmpty()) {
        if (actor instanceof Group) {
            Group group = (Group) actor;
            attr = attr.toLowerCase();
            if (attr.equals("true")) {
                group.debug();
            } else if (attr.equals("all")) {
                group.debugAll();
            }
        } else {
            actor.setDebug(Boolean.parseBoolean(attr));
        }
    }
    for (int idx = 0, size = ANCHOR_NAMES.length; idx < size; ++idx) {
        String anchorName = ANCHOR_NAMES[idx];
        attr = element.getAttribute(anchorName, "");
        if (!attr.isEmpty()) {
            if (anchorGroup == null) {
                throw new RuntimeException("Parent of " + actor + " is not an anchor group");
            }
            PositionRule rule = parseRule(attr, anchorGroup.getSpacing());
            rule.target = actor;
            rule.targetAnchor = ANCHORS[idx];
            anchorGroup.addRule(rule);
        }
    }
}