Search in sources :

Example 36 with Actor

use of com.badlogic.gdx.scenes.scene2d.Actor in project libgdx by libgdx.

the class BaseG3dHudTest method createHUD.

protected void createHUD() {
    hud = new Stage(new ScalingViewport(Scaling.fit, PREF_HUDWIDTH, PREF_HUDHEIGHT));
    hudWidth = hud.getWidth();
    hudHeight = hud.getHeight();
    skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    final List<String> modelsList = new List(skin);
    modelsList.setItems(models);
    modelsList.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            if (!modelsWindow.isCollapsed() && getTapCount() == 2) {
                onModelClicked(modelsList.getSelected());
                modelsWindow.collapse();
            }
        }
    });
    modelsWindow = addListWindow("Models", modelsList, 0, -1);
    fpsLabel = new Label("FPS: 999", skin);
    hud.addActor(fpsLabel);
    gridCheckBox = new CheckBox("Show grid", skin);
    gridCheckBox.setChecked(showAxes);
    gridCheckBox.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            showAxes = gridCheckBox.isChecked();
        }
    });
    gridCheckBox.setPosition(hudWidth - gridCheckBox.getWidth(), 0);
    hud.addActor(gridCheckBox);
    rotateCheckBox = new CheckBox("Rotate", skin);
    rotateCheckBox.setChecked(true);
    rotateCheckBox.setPosition(hudWidth - rotateCheckBox.getWidth(), gridCheckBox.getHeight());
    hud.addActor(rotateCheckBox);
    moveCheckBox = new CheckBox("Move", skin);
    moveCheckBox.setChecked(false);
    moveCheckBox.setPosition(hudWidth - moveCheckBox.getWidth(), rotateCheckBox.getTop());
    hud.addActor(moveCheckBox);
}
Also used : Label(com.badlogic.gdx.scenes.scene2d.ui.Label) CheckBox(com.badlogic.gdx.scenes.scene2d.ui.CheckBox) Actor(com.badlogic.gdx.scenes.scene2d.Actor) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) List(com.badlogic.gdx.scenes.scene2d.ui.List) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener) ScalingViewport(com.badlogic.gdx.utils.viewport.ScalingViewport)

Example 37 with Actor

use of com.badlogic.gdx.scenes.scene2d.Actor in project libgdx by libgdx.

the class Dialog method show.

/** {@link #pack() Packs} the dialog and adds it to the stage with custom action which can be null for instant show */
public Dialog show(Stage stage, Action action) {
    clearActions();
    removeCaptureListener(ignoreTouchDown);
    previousKeyboardFocus = null;
    Actor actor = stage.getKeyboardFocus();
    if (actor != null && !actor.isDescendantOf(this))
        previousKeyboardFocus = actor;
    previousScrollFocus = null;
    actor = stage.getScrollFocus();
    if (actor != null && !actor.isDescendantOf(this))
        previousScrollFocus = actor;
    pack();
    stage.addActor(this);
    stage.setKeyboardFocus(this);
    stage.setScrollFocus(this);
    if (action != null)
        addAction(action);
    return this;
}
Also used : Actor(com.badlogic.gdx.scenes.scene2d.Actor)

Example 38 with Actor

use of com.badlogic.gdx.scenes.scene2d.Actor in project libgdx by libgdx.

the class HorizontalGroup method layout.

public void layout() {
    if (sizeInvalid)
        computeSize();
    if (wrap) {
        layoutWrapped();
        return;
    }
    boolean round = this.round;
    int align = this.align;
    float space = this.space, padBottom = this.padBottom, fill = this.fill;
    float rowHeight = (expand ? getHeight() : prefHeight) - padTop - padBottom, x = padLeft;
    if ((align & Align.right) != 0)
        x += getWidth() - prefWidth;
    else if (// center
    (align & Align.left) == 0)
        x += (getWidth() - prefWidth) / 2;
    float startY;
    if ((align & Align.bottom) != 0)
        startY = padBottom;
    else if ((align & Align.top) != 0)
        startY = getHeight() - padTop - rowHeight;
    else
        startY = padBottom + (getHeight() - padBottom - padTop - rowHeight) / 2;
    align = rowAlign;
    SnapshotArray<Actor> children = getChildren();
    int i = 0, n = children.size, incr = 1;
    if (reverse) {
        i = n - 1;
        n = -1;
        incr = -1;
    }
    for (int r = 0; i != n; i += incr) {
        Actor child = children.get(i);
        float width, height;
        Layout layout = null;
        if (child instanceof Layout) {
            layout = (Layout) child;
            width = layout.getPrefWidth();
            height = layout.getPrefHeight();
        } else {
            width = child.getWidth();
            height = child.getHeight();
        }
        if (fill > 0)
            height = rowHeight * fill;
        if (layout != null) {
            height = Math.max(height, layout.getMinHeight());
            float maxHeight = layout.getMaxHeight();
            if (maxHeight > 0 && height > maxHeight)
                height = maxHeight;
        }
        float y = startY;
        if ((align & Align.top) != 0)
            y += rowHeight - height;
        else if (// center
        (align & Align.bottom) == 0)
            y += (rowHeight - height) / 2;
        if (round)
            child.setBounds(Math.round(x), Math.round(y), Math.round(width), Math.round(height));
        else
            child.setBounds(x, y, width, height);
        x += width + space;
        if (layout != null)
            layout.validate();
    }
}
Also used : Layout(com.badlogic.gdx.scenes.scene2d.utils.Layout) Actor(com.badlogic.gdx.scenes.scene2d.Actor)

Example 39 with Actor

use of com.badlogic.gdx.scenes.scene2d.Actor in project libgdx by libgdx.

the class Tooltip method enter.

public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {
    if (pointer != -1)
        return;
    if (Gdx.input.isTouched())
        return;
    Actor actor = event.getListenerActor();
    if (fromActor != null && fromActor.isDescendantOf(actor))
        return;
    setContainerPosition(actor, x, y);
    manager.enter(this);
}
Also used : Actor(com.badlogic.gdx.scenes.scene2d.Actor)

Example 40 with Actor

use of com.badlogic.gdx.scenes.scene2d.Actor in project libgdx by libgdx.

the class Tree method computeSize.

private void computeSize(Array<Node> nodes, float indent) {
    float ySpacing = this.ySpacing;
    float spacing = iconSpacingLeft + iconSpacingRight;
    for (int i = 0, n = nodes.size; i < n; i++) {
        Node node = nodes.get(i);
        float rowWidth = indent + iconSpacingRight;
        Actor actor = node.actor;
        if (actor instanceof Layout) {
            Layout layout = (Layout) actor;
            rowWidth += layout.getPrefWidth();
            node.height = layout.getPrefHeight();
            layout.pack();
        } else {
            rowWidth += actor.getWidth();
            node.height = actor.getHeight();
        }
        if (node.icon != null) {
            rowWidth += spacing + node.icon.getMinWidth();
            node.height = Math.max(node.height, node.icon.getMinHeight());
        }
        prefWidth = Math.max(prefWidth, rowWidth);
        prefHeight -= node.height + ySpacing;
        if (node.expanded)
            computeSize(node.children, indent + indentSpacing);
    }
}
Also used : Layout(com.badlogic.gdx.scenes.scene2d.utils.Layout) Actor(com.badlogic.gdx.scenes.scene2d.Actor)

Aggregations

Actor (com.badlogic.gdx.scenes.scene2d.Actor)67 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)26 Stage (com.badlogic.gdx.scenes.scene2d.Stage)19 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)19 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)18 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)15 Layout (com.badlogic.gdx.scenes.scene2d.utils.Layout)11 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)10 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)9 Texture (com.badlogic.gdx.graphics.Texture)8 Group (com.badlogic.gdx.scenes.scene2d.Group)8 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)7 InputListener (com.badlogic.gdx.scenes.scene2d.InputListener)7 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)6 Dialog (com.badlogic.gdx.scenes.scene2d.ui.Dialog)6 Image (com.badlogic.gdx.scenes.scene2d.ui.Image)6 ScreenViewport (com.badlogic.gdx.utils.viewport.ScreenViewport)6 CheckBox (com.badlogic.gdx.scenes.scene2d.ui.CheckBox)5 ScrollPane (com.badlogic.gdx.scenes.scene2d.ui.ScrollPane)5 Slider (com.badlogic.gdx.scenes.scene2d.ui.Slider)5