Search in sources :

Example 56 with Stage

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

the class TextField method next.

/** Focuses the next TextField. If none is found, the keyboard is hidden. Does nothing if the text field is not in a stage.
	 * @param up If true, the TextField with the same or next smallest y coordinate is found, else the next highest. */
public void next(boolean up) {
    Stage stage = getStage();
    if (stage == null)
        return;
    TextField current = this;
    while (true) {
        current.getParent().localToStageCoordinates(tmp1.set(getX(), getY()));
        TextField textField = current.findNextTextField(stage.getActors(), null, tmp2, tmp1, up);
        if (textField == null) {
            // Try to wrap around.
            if (up)
                tmp1.set(Float.MIN_VALUE, Float.MIN_VALUE);
            else
                tmp1.set(Float.MAX_VALUE, Float.MAX_VALUE);
            textField = current.findNextTextField(getStage().getActors(), null, tmp2, tmp1, up);
        }
        if (textField == null) {
            Gdx.input.setOnscreenKeyboardVisible(false);
            break;
        }
        if (stage.setKeyboardFocus(textField))
            break;
        current = textField;
    }
}
Also used : Stage(com.badlogic.gdx.scenes.scene2d.Stage)

Example 57 with Stage

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

the class Widget method validate.

public void validate() {
    if (!layoutEnabled)
        return;
    Group parent = getParent();
    if (fillParent && parent != null) {
        float parentWidth, parentHeight;
        Stage stage = getStage();
        if (stage != null && parent == stage.getRoot()) {
            parentWidth = stage.getWidth();
            parentHeight = stage.getHeight();
        } else {
            parentWidth = parent.getWidth();
            parentHeight = parent.getHeight();
        }
        setSize(parentWidth, parentHeight);
    }
    if (!needsLayout)
        return;
    needsLayout = false;
    layout();
}
Also used : Group(com.badlogic.gdx.scenes.scene2d.Group) Stage(com.badlogic.gdx.scenes.scene2d.Stage)

Example 58 with Stage

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

the class WidgetGroup method validate.

public void validate() {
    if (!layoutEnabled)
        return;
    Group parent = getParent();
    if (fillParent && parent != null) {
        float parentWidth, parentHeight;
        Stage stage = getStage();
        if (stage != null && parent == stage.getRoot()) {
            parentWidth = stage.getWidth();
            parentHeight = stage.getHeight();
        } else {
            parentWidth = parent.getWidth();
            parentHeight = parent.getHeight();
        }
        if (getWidth() != parentWidth || getHeight() != parentHeight) {
            setWidth(parentWidth);
            setHeight(parentHeight);
            invalidate();
        }
    }
    if (!needsLayout)
        return;
    needsLayout = false;
    layout();
}
Also used : Group(com.badlogic.gdx.scenes.scene2d.Group) Stage(com.badlogic.gdx.scenes.scene2d.Stage)

Example 59 with Stage

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

the class Window method keepWithinStage.

void keepWithinStage() {
    if (!keepWithinStage)
        return;
    Stage stage = getStage();
    Camera camera = stage.getCamera();
    if (camera instanceof OrthographicCamera) {
        OrthographicCamera orthographicCamera = (OrthographicCamera) camera;
        float parentWidth = stage.getWidth();
        float parentHeight = stage.getHeight();
        if (getX(Align.right) - camera.position.x > parentWidth / 2 / orthographicCamera.zoom)
            setPosition(camera.position.x + parentWidth / 2 / orthographicCamera.zoom, getY(Align.right), Align.right);
        if (getX(Align.left) - camera.position.x < -parentWidth / 2 / orthographicCamera.zoom)
            setPosition(camera.position.x - parentWidth / 2 / orthographicCamera.zoom, getY(Align.left), Align.left);
        if (getY(Align.top) - camera.position.y > parentHeight / 2 / orthographicCamera.zoom)
            setPosition(getX(Align.top), camera.position.y + parentHeight / 2 / orthographicCamera.zoom, Align.top);
        if (getY(Align.bottom) - camera.position.y < -parentHeight / 2 / orthographicCamera.zoom)
            setPosition(getX(Align.bottom), camera.position.y - parentHeight / 2 / orthographicCamera.zoom, Align.bottom);
    } else if (getParent() == stage.getRoot()) {
        float parentWidth = stage.getWidth();
        float parentHeight = stage.getHeight();
        if (getX() < 0)
            setX(0);
        if (getRight() > parentWidth)
            setX(parentWidth - getWidth());
        if (getY() < 0)
            setY(0);
        if (getTop() > parentHeight)
            setY(parentHeight - getHeight());
    }
}
Also used : Stage(com.badlogic.gdx.scenes.scene2d.Stage) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) Camera(com.badlogic.gdx.graphics.Camera) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera)

Example 60 with Stage

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

the class DragNDropTest method create.

@Override
public void create() {
    BufferedImage image = new BufferedImage(10, 10, BufferedImage.TYPE_4BYTE_ABGR);
    stage = new Stage();
    skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    Gdx.input.setInputProcessor(stage);
    root = new Table();
    root.setFillParent(true);
    root.align(Align.left | Align.top);
    stage.addActor(root);
}
Also used : Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) BufferedImage(java.awt.image.BufferedImage)

Aggregations

Stage (com.badlogic.gdx.scenes.scene2d.Stage)107 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)46 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)46 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)38 Texture (com.badlogic.gdx.graphics.Texture)36 Actor (com.badlogic.gdx.scenes.scene2d.Actor)32 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)30 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)30 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)28 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)22 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)22 ScreenViewport (com.badlogic.gdx.utils.viewport.ScreenViewport)20 Image (com.badlogic.gdx.scenes.scene2d.ui.Image)19 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)18 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)15 TextureRegionDrawable (com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable)13 ScrollPane (com.badlogic.gdx.scenes.scene2d.ui.ScrollPane)12 InputListener (com.badlogic.gdx.scenes.scene2d.InputListener)11 Sprite (com.badlogic.gdx.graphics.g2d.Sprite)10 TextField (com.badlogic.gdx.scenes.scene2d.ui.TextField)10