Search in sources :

Example 41 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 42 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 43 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 44 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)

Example 45 with Stage

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

the class ActionSequenceTest method create.

@Override
public void create() {
    stage = new Stage();
    texture = new Texture(Gdx.files.internal("data/badlogic.jpg"), false);
    texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    img = new Image(new TextureRegion(texture));
    img.setSize(100, 100);
    img.setOrigin(50, 50);
    img.setPosition(100, 100);
    img2 = new Image(new TextureRegion(texture));
    img2.setSize(100, 100);
    img2.setOrigin(50, 50);
    img2.setPosition(100, 100);
    img3 = new Image(new TextureRegion(texture));
    img3.setSize(100, 100);
    img3.setOrigin(50, 50);
    img3.setPosition(100, 100);
    stage.addActor(img);
    stage.addActor(img2);
    stage.addActor(img3);
    img.addAction(sequence());
    img2.addAction(parallel(sequence(), moveBy(100, 0, 1)));
    img3.addAction(sequence(parallel(moveBy(100, 200, 2)), Actions.run(this)));
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Image(com.badlogic.gdx.scenes.scene2d.ui.Image) Texture(com.badlogic.gdx.graphics.Texture)

Aggregations

Stage (com.badlogic.gdx.scenes.scene2d.Stage)72 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)36 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)32 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)25 Texture (com.badlogic.gdx.graphics.Texture)24 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)20 Actor (com.badlogic.gdx.scenes.scene2d.Actor)19 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)18 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)16 Image (com.badlogic.gdx.scenes.scene2d.ui.Image)16 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)15 ScreenViewport (com.badlogic.gdx.utils.viewport.ScreenViewport)14 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)13 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)13 ScrollPane (com.badlogic.gdx.scenes.scene2d.ui.ScrollPane)9 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)8 CheckBox (com.badlogic.gdx.scenes.scene2d.ui.CheckBox)6 ShapeRenderer (com.badlogic.gdx.graphics.glutils.ShapeRenderer)5 Group (com.badlogic.gdx.scenes.scene2d.Group)5 InputMultiplexer (com.badlogic.gdx.InputMultiplexer)4