Search in sources :

Example 31 with Label

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

the class ParticleControllerTest method setupUI.

private void setupUI() {
    Skin skin = assets.get(DEFAULT_SKIN);
    Table table = new Table();
    table.setFillParent(true);
    table.top().left().add(new Label("FPS ", skin)).left();
    table.add(fpsLabel = new Label("", skin)).left().expandX().row();
    ui.addActor(table);
}
Also used : Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin)

Example 32 with Label

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

the class GwtTestWrapper method create.

@Override
public void create() {
    Gdx.app.setLogLevel(Application.LOG_DEBUG);
    Gdx.app.log("GdxTestGwt", "Setting up for " + tests.length + " tests.");
    ui = new Stage();
    skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false);
    container = new Table();
    ui.addActor(container);
    container.debug();
    Table table = new Table();
    ScrollPane scroll = new ScrollPane(table);
    container.add(scroll).expand().fill();
    table.pad(10).defaults().expandX().space(4);
    Arrays.sort(tests, new Comparator<Instancer>() {

        @Override
        public int compare(Instancer o1, Instancer o2) {
            return o1.instance().getClass().getName().compareTo(o2.instance().getClass().getName());
        }
    });
    for (final Instancer instancer : tests) {
        table.row();
        TextButton button = new TextButton(instancer.instance().getClass().getName(), skin);
        button.addListener(new ClickListener() {

            @Override
            public void clicked(InputEvent event, float x, float y) {
                ((InputWrapper) Gdx.input).multiplexer.removeProcessor(ui);
                test = instancer.instance();
                Gdx.app.log("GdxTestGwt", "Clicked on " + test.getClass().getName());
                test.create();
                test.resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
            }
        });
        table.add(button).expandX().fillX();
    }
    container.row();
    container.add(new Label("Click on a test to start it, press ESC to close it.", new LabelStyle(font, Color.WHITE))).pad(5, 5, 5, 5);
    Gdx.input = new InputWrapper(Gdx.input) {

        @Override
        public boolean keyUp(int keycode) {
            if (keycode == Keys.ESCAPE) {
                if (test != null) {
                    Gdx.app.log("GdxTestGwt", "Exiting current test.");
                    dispose = true;
                }
            }
            return false;
        }

        @Override
        public boolean touchDown(int screenX, int screenY, int pointer, int button) {
            if (screenX < Gdx.graphics.getWidth() / 10.0 && screenY < Gdx.graphics.getHeight() / 10.0) {
                if (test != null) {
                    dispose = true;
                }
            }
            return false;
        }
    };
    ((InputWrapper) Gdx.input).multiplexer.addProcessor(ui);
    Gdx.app.log("GdxTestGwt", "Test picker UI setup complete.");
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) LabelStyle(com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle) ScrollPane(com.badlogic.gdx.scenes.scene2d.ui.ScrollPane) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Example 33 with Label

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

the class NetAPITest method create.

@Override
public void create() {
    batch = new SpriteBatch();
    skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    font = new BitmapFont();
    stage = new Stage();
    Gdx.input.setInputProcessor(stage);
    {
        statusLabel = new Label("", skin);
        statusLabel.setWrap(true);
        statusLabel.setWidth(Gdx.graphics.getWidth() * 0.96f);
        statusLabel.setAlignment(Align.center);
        statusLabel.setPosition(Gdx.graphics.getWidth() * 0.5f - statusLabel.getWidth() * 0.5f, 30f);
        statusLabel.setColor(Color.CYAN);
        stage.addActor(statusLabel);
    }
    {
        ClickListener clickListener = new ClickListener() {

            @Override
            public void clicked(InputEvent event, float x, float y) {
                super.clicked(event, x, y);
                clickedButton = event.getListenerActor();
                setButtonDisabled(true);
                if (texture != null)
                    texture.dispose();
                texture = null;
                text = null;
                String url;
                String httpMethod = Net.HttpMethods.GET;
                String requestContent = null;
                if (clickedButton == btnDownloadImage)
                    url = "http://i.imgur.com/vxomF.jpg";
                else if (clickedButton == btnDownloadText)
                    url = "http://www.apache.org/licenses/LICENSE-2.0.txt";
                else if (clickedButton == btnDownloadLarge)
                    url = "http://libgdx.badlogicgames.com/releases/libgdx-1.2.0.zip";
                else if (clickedButton == btnDownloadError)
                    url = "http://www.badlogicgames.com/doesnotexist";
                else if (clickedButton == btnOpenUri) {
                    Gdx.net.openURI("http://libgdx.badlogicgames.com/");
                    return;
                } else {
                    url = "http://posttestserver.com/post.php?dump";
                    httpMethod = Net.HttpMethods.POST;
                    requestContent = "name1=value1&name2=value2";
                }
                httpRequest = new HttpRequest(httpMethod);
                httpRequest.setUrl(url);
                httpRequest.setContent(requestContent);
                Gdx.net.sendHttpRequest(httpRequest, NetAPITest.this);
                statusLabel.setText("Downloading data from " + httpRequest.getUrl());
            }
        };
        ClickListener cancelListener = new ClickListener() {

            @Override
            public void clicked(InputEvent event, float x, float y) {
                super.clicked(event, x, y);
                if (httpRequest != null) {
                    Gdx.net.cancelHttpRequest(httpRequest);
                    Gdx.app.log("NetAPITest", "Cancelling request " + httpRequest.getUrl());
                    statusLabel.setText("Cancelling request " + httpRequest.getUrl());
                }
            }
        };
        btnCancel = new TextButton("Cancel", skin);
        btnCancel.setPosition(Gdx.graphics.getWidth() * 0.10f, 60f);
        btnCancel.addListener(cancelListener);
        stage.addActor(btnCancel);
        btnDownloadImage = new TextButton("GET Image", skin);
        btnDownloadImage.setPosition(btnCancel.getX() + btnCancel.getWidth() + 10, 60f);
        btnDownloadImage.addListener(clickListener);
        stage.addActor(btnDownloadImage);
        btnDownloadText = new TextButton("GET Text", skin);
        btnDownloadText.setPosition(btnDownloadImage.getX() + btnDownloadImage.getWidth() + 10, 60f);
        btnDownloadText.addListener(clickListener);
        stage.addActor(btnDownloadText);
        btnDownloadLarge = new TextButton("GET Large", skin);
        btnDownloadLarge.setPosition(btnDownloadText.getX() + btnDownloadText.getWidth() + 10, 60f);
        btnDownloadLarge.addListener(clickListener);
        stage.addActor(btnDownloadLarge);
        btnDownloadError = new TextButton("GET Error", skin);
        btnDownloadError.setPosition(btnDownloadLarge.getX() + btnDownloadLarge.getWidth() + 10, 60f);
        btnDownloadError.addListener(clickListener);
        stage.addActor(btnDownloadError);
        btnPost = new TextButton("POST", skin);
        btnPost.setPosition(btnDownloadError.getX() + btnDownloadError.getWidth() + 10, 60f);
        btnPost.addListener(clickListener);
        stage.addActor(btnPost);
        btnOpenUri = new TextButton("Open URI", skin);
        btnOpenUri.setPosition(btnPost.getX() + btnPost.getWidth() + 10, 60f);
        btnOpenUri.addListener(clickListener);
        stage.addActor(btnOpenUri);
    }
}
Also used : HttpRequest(com.badlogic.gdx.Net.HttpRequest) TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Example 34 with Label

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

the class ProjectiveTextureTest method setupUI.

public void setupUI() {
    ui = new Stage();
    skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    TextButton reload = new TextButton("Reload Shaders", skin.get(TextButtonStyle.class));
    camera = new SelectBox(skin.get(SelectBoxStyle.class));
    camera.setItems("Camera", "Light");
    fps = new Label("fps: ", skin.get(LabelStyle.class));
    Table table = new Table();
    table.setFillParent(true);
    table.top().padTop(15);
    table.add(reload).spaceRight(5);
    table.add(camera).spaceRight(5);
    table.add(fps);
    ui.addActor(table);
    reload.addListener(new ClickListener() {

        public void clicked(InputEvent event, float x, float y) {
            ShaderProgram prog = new ShaderProgram(Gdx.files.internal("data/shaders/projtex-vert.glsl").readString(), Gdx.files.internal("data/shaders/projtex-frag.glsl").readString());
            if (prog.isCompiled() == false) {
                Gdx.app.log("GLSL ERROR", "Couldn't reload shaders:\n" + prog.getLog());
            } else {
                projTexShader.dispose();
                projTexShader = prog;
            }
        }
    });
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) ShaderProgram(com.badlogic.gdx.graphics.glutils.ShaderProgram) SelectBox(com.badlogic.gdx.scenes.scene2d.ui.SelectBox) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) Stage(com.badlogic.gdx.scenes.scene2d.Stage) TextButtonStyle(com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Example 35 with Label

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

the class Scene2dTest method create.

public void create() {
    stage = new Stage();
    Gdx.input.setInputProcessor(stage);
    final TextureRegion region = new TextureRegion(new Texture("data/badlogic.jpg"));
    final Actor actor = new Actor() {

        public void draw(Batch batch, float parentAlpha) {
            Color color = getColor();
            batch.setColor(color.r, color.g, color.b, parentAlpha);
            batch.draw(region, getX(), getY(), getOriginX(), getOriginY(), getWidth(), getHeight(), getScaleX(), getScaleY(), getRotation());
        }
    };
    actor.setBounds(15, 15, 100, 100);
    actor.setOrigin(50, 50);
    stage.addActor(actor);
    actor.addListener(new InputListener() {

        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            System.out.println("down");
            return true;
        }

        public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
            System.out.println("up " + event.getTarget());
        }
    });
    Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    VerticalGroup g = new VerticalGroup().space(5).reverse().pad(5).fill();
    for (int i = 0; i < 10; i++) g.addActor(new TextButton("button " + i, skin));
    g.addActor(new TextButton("longer button", skin));
    Table table = new Table().debug();
    table.add(g);
    table.pack();
    table.setPosition(5, 100);
    stage.addActor(table);
    HorizontalGroup h = new HorizontalGroup().space(5).reverse().pad(5).fill();
    for (int i = 0; i < 5; i++) h.addActor(new TextButton("button " + i, skin));
    h.addActor(new TextButton("some taller\nbutton", skin));
    table = new Table().debug();
    table.add(h);
    table.pack();
    table.setPosition(130, 100);
    stage.addActor(table);
    table.toFront();
    final TextButton button = new TextButton("Fancy Background", skin);
    // button.addListener(new ClickListener() {
    // public void clicked (InputEvent event, float x, float y) {
    // System.out.println("click! " + x + " " + y);
    // }
    // });
    button.addListener(new ActorGestureListener() {

        public boolean longPress(Actor actor, float x, float y) {
            System.out.println("long press " + x + ", " + y);
            return true;
        }

        public void fling(InputEvent event, float velocityX, float velocityY, int button) {
            System.out.println("fling " + velocityX + ", " + velocityY);
        }

        public void zoom(InputEvent event, float initialDistance, float distance) {
            System.out.println("zoom " + initialDistance + ", " + distance);
        }

        public void pan(InputEvent event, float x, float y, float deltaX, float deltaY) {
            event.getListenerActor().moveBy(deltaX, deltaY);
            if (deltaX < 0)
                System.out.println("panning " + deltaX + ", " + deltaY + " " + event.getTarget());
        }
    });
    // button.addListener(new ChangeListener() {
    // public void changed (ChangeEvent event, Actor actor) {
    // // event.cancel();
    // }
    // });
    button.setPosition(50, 50);
    stage.addActor(button);
    // List select = new List(skin);
    // select.setBounds(200, 200, 100, 100);
    // select.setItems(new Object[] {1, 2, 3, 4, 5});
    // stage.addActor(select);
    // stage.addListener(new ChangeListener() {
    // public void changed (ChangeEvent event, Actor actor) {
    // System.out.println(actor);
    // }
    // });
    meow.setDuration(2);
    actor.addAction(forever(sequence(moveBy(50, 0, 2), moveBy(-50, 0, 2), run(new Runnable() {

        public void run() {
            actor.setZIndex(0);
        }
    }))));
    // actor.addAction(parallel(rotateBy(90, 2), rotateBy(90, 2)));
    // actor.addAction(parallel(moveTo(250, 250, 2, elasticOut), color(RED, 6), delay(0.5f), rotateTo(180, 5, swing)));
    // actor.addAction(forever(sequence(scaleTo(2, 2, 0.5f), scaleTo(1, 1, 0.5f), delay(0.5f))));
    patch = new TiledDrawable(skin.getRegion("default-round"));
    Window window = new Window("Moo", skin);
    Label lbl = new Label("ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJ", skin);
    lbl.setWrap(true);
    window.row();
    window.add(lbl).width(400);
    window.pack();
    window.pack();
    stage.addActor(window);
    ImageTextButtonStyle style = new ImageTextButtonStyle(skin.get("default", TextButtonStyle.class));
    style.imageUp = skin.getDrawable("default-round");
    ImageTextButton buttonLeft = new ImageTextButton("HI IM LEFT", style);
    ImageTextButton buttonRight = new ImageTextButton("HI IM RIGHT", style) {

        {
            clearChildren();
            add(getLabel());
            add(getImage());
        }
    };
    CheckBox checkBoxLeft = new CheckBox("HI IM LEFT", skin, "default");
    CheckBox checkBoxRight = new CheckBox("HI IM RIGHT", skin, "default") {

        {
            clearChildren();
            add(getLabel());
            add(getImage());
        }
    };
    buttonLeft.setPosition(300, 400);
    buttonRight.setPosition(300, 370);
    checkBoxLeft.setPosition(150, 400);
    checkBoxRight.setPosition(150, 370);
    stage.addActor(buttonLeft);
    stage.addActor(buttonRight);
    stage.addActor(checkBoxLeft);
    stage.addActor(checkBoxRight);
    buttonLeft.debug();
    buttonRight.debug();
    checkBoxLeft.debug();
    checkBoxRight.debug();
}
Also used : ImageTextButton(com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton) TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Window(com.badlogic.gdx.scenes.scene2d.ui.Window) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) ImageTextButton(com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton) Color(com.badlogic.gdx.graphics.Color) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) VerticalGroup(com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup) Texture(com.badlogic.gdx.graphics.Texture) ActorGestureListener(com.badlogic.gdx.scenes.scene2d.utils.ActorGestureListener) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) InputListener(com.badlogic.gdx.scenes.scene2d.InputListener) Batch(com.badlogic.gdx.graphics.g2d.Batch) TiledDrawable(com.badlogic.gdx.scenes.scene2d.utils.TiledDrawable) CheckBox(com.badlogic.gdx.scenes.scene2d.ui.CheckBox) Actor(com.badlogic.gdx.scenes.scene2d.Actor) Stage(com.badlogic.gdx.scenes.scene2d.Stage) ImageTextButtonStyle(com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton.ImageTextButtonStyle) TextButtonStyle(com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) HorizontalGroup(com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ImageTextButtonStyle(com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton.ImageTextButtonStyle)

Aggregations

Label (com.badlogic.gdx.scenes.scene2d.ui.Label)43 Stage (com.badlogic.gdx.scenes.scene2d.Stage)25 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)24 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)23 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)20 Actor (com.badlogic.gdx.scenes.scene2d.Actor)18 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)16 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)16 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)10 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)10 Texture (com.badlogic.gdx.graphics.Texture)9 Image (com.badlogic.gdx.scenes.scene2d.ui.Image)9 ScrollPane (com.badlogic.gdx.scenes.scene2d.ui.ScrollPane)9 CheckBox (com.badlogic.gdx.scenes.scene2d.ui.CheckBox)8 ScreenViewport (com.badlogic.gdx.utils.viewport.ScreenViewport)8 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)7 Window (com.badlogic.gdx.scenes.scene2d.ui.Window)7 InputListener (com.badlogic.gdx.scenes.scene2d.InputListener)6 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)5 Dialog (com.badlogic.gdx.scenes.scene2d.ui.Dialog)5