Search in sources :

Example 36 with Skin

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

the class TreeTest method create.

public void create() {
    stage = new Stage();
    Gdx.input.setInputProcessor(stage);
    Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    Table table = new Table();
    table.setFillParent(true);
    stage.addActor(table);
    final Tree tree = new Tree(skin);
    final Node moo1 = new Node(new TextButton("moo1", skin));
    final Node moo2 = new Node(new TextButton("moo2", skin));
    final Node moo3 = new Node(new TextButton("moo3", skin));
    final Node moo4 = new Node(new TextButton("moo4", skin));
    final Node moo5 = new Node(new TextButton("moo5", skin));
    tree.add(moo1);
    tree.add(moo2);
    moo2.add(moo3);
    moo3.add(moo4);
    tree.add(moo5);
    moo5.getActor().addListener(new ClickListener() {

        public void clicked(InputEvent event, float x, float y) {
            tree.remove(moo4);
        }
    });
    table.add(tree).fill().expand();
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Node(com.badlogic.gdx.scenes.scene2d.ui.Tree.Node) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Tree(com.badlogic.gdx.scenes.scene2d.ui.Tree) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Example 37 with Skin

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

the class UISimpleTest method create.

@Override
public void create() {
    batch = new SpriteBatch();
    stage = new Stage();
    Gdx.input.setInputProcessor(stage);
    // A skin can be loaded via JSON or defined programmatically, either is fine. Using a skin is optional but strongly
    // recommended solely for the convenience of getting a texture, region, etc as a drawable, tinted drawable, etc.
    skin = new Skin();
    // Generate a 1x1 white texture and store it in the skin named "white".
    Pixmap pixmap = new Pixmap(1, 1, Format.RGBA8888);
    pixmap.setColor(Color.WHITE);
    pixmap.fill();
    skin.add("white", new Texture(pixmap));
    // Store the default libgdx font under the name "default".
    skin.add("default", new BitmapFont());
    // Configure a TextButtonStyle and name it "default". Skin resources are stored by type, so this doesn't overwrite the font.
    TextButtonStyle textButtonStyle = new TextButtonStyle();
    textButtonStyle.up = skin.newDrawable("white", Color.DARK_GRAY);
    textButtonStyle.down = skin.newDrawable("white", Color.DARK_GRAY);
    textButtonStyle.checked = skin.newDrawable("white", Color.BLUE);
    textButtonStyle.over = skin.newDrawable("white", Color.LIGHT_GRAY);
    textButtonStyle.font = skin.getFont("default");
    skin.add("default", textButtonStyle);
    // Create a table that fills the screen. Everything else will go inside this table.
    Table table = new Table();
    table.setFillParent(true);
    stage.addActor(table);
    // Create a button with the "default" TextButtonStyle. A 3rd parameter can be used to specify a name other than "default".
    final TextButton button = new TextButton("Click me!", skin);
    table.add(button);
    // Add a listener to the button. ChangeListener is fired when the button's checked state changes, eg when clicked,
    // Button#setChecked() is called, via a key press, etc. If the event.cancel() is called, the checked state will be reverted.
    // ClickListener could have been used, but would only fire when clicked. Also, canceling a ClickListener event won't
    // revert the checked state.
    button.addListener(new ChangeListener() {

        public void changed(ChangeEvent event, Actor actor) {
            System.out.println("Clicked! Is checked: " + button.isChecked());
            button.setText("Good job!");
        }
    });
    // Add an image actor. Have to set the size, else it would be the size of the drawable (which is the 1x1 texture).
    table.add(new Image(skin.newDrawable("white", Color.RED))).size(64);
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Image(com.badlogic.gdx.scenes.scene2d.ui.Image) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Texture(com.badlogic.gdx.graphics.Texture) Actor(com.badlogic.gdx.scenes.scene2d.Actor) Stage(com.badlogic.gdx.scenes.scene2d.Stage) TextButtonStyle(com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) Pixmap(com.badlogic.gdx.graphics.Pixmap)

Example 38 with Skin

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

the class UITest method create.

@Override
public void create() {
    skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    texture1 = new Texture(Gdx.files.internal("data/badlogicsmall.jpg"));
    texture2 = new Texture(Gdx.files.internal("data/badlogic.jpg"));
    TextureRegion image = new TextureRegion(texture1);
    TextureRegion imageFlipped = new TextureRegion(image);
    imageFlipped.flip(true, true);
    TextureRegion image2 = new TextureRegion(texture2);
    // stage = new Stage(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false, new PolygonSpriteBatch());
    stage = new Stage(new ScreenViewport());
    Gdx.input.setInputProcessor(stage);
    // Group.debug = true;
    ImageButtonStyle style = new ImageButtonStyle(skin.get(ButtonStyle.class));
    style.imageUp = new TextureRegionDrawable(image);
    style.imageDown = new TextureRegionDrawable(imageFlipped);
    ImageButton iconButton = new ImageButton(style);
    Button buttonMulti = new TextButton("Multi\nLine\nToggle", skin, "toggle");
    Button imgButton = new Button(new Image(image), skin);
    Button imgToggleButton = new Button(new Image(image), skin, "toggle");
    Label myLabel = new Label("this is some text.", skin);
    myLabel.setWrap(true);
    Table t = new Table();
    t.row();
    t.add(myLabel);
    t.layout();
    final CheckBox checkBox = new CheckBox(" Continuous rendering", skin);
    checkBox.setChecked(true);
    final Slider slider = new Slider(0, 10, 1, false, skin);
    slider.setAnimateDuration(0.3f);
    TextField textfield = new TextField("", skin);
    textfield.setMessageText("Click here!");
    textfield.setAlignment(Align.center);
    final SelectBox selectBox = new SelectBox(skin);
    selectBox.addListener(new ChangeListener() {

        public void changed(ChangeEvent event, Actor actor) {
            System.out.println(selectBox.getSelected());
        }
    });
    selectBox.setItems("Android1", "Windows1 long text in item", "Linux1", "OSX1", "Android2", "Windows2", "Linux2", "OSX2", "Android3", "Windows3", "Linux3", "OSX3", "Android4", "Windows4", "Linux4", "OSX4", "Android5", "Windows5", "Linux5", "OSX5", "Android6", "Windows6", "Linux6", "OSX6", "Android7", "Windows7", "Linux7", "OSX7");
    selectBox.setSelected("Linux6");
    Image imageActor = new Image(image2);
    ScrollPane scrollPane = new ScrollPane(imageActor);
    List list = new List(skin);
    list.setItems(listEntries);
    list.getSelection().setMultiple(true);
    list.getSelection().setRequired(false);
    // list.getSelection().setToggle(true);
    ScrollPane scrollPane2 = new ScrollPane(list, skin);
    scrollPane2.setFlickScroll(false);
    SplitPane splitPane = new SplitPane(scrollPane, scrollPane2, false, skin, "default-horizontal");
    fpsLabel = new Label("fps:", skin);
    // configures an example of a TextField in password mode.
    final Label passwordLabel = new Label("Textfield in password mode: ", skin);
    final TextField passwordTextField = new TextField("", skin);
    passwordTextField.setMessageText("password");
    passwordTextField.setPasswordCharacter('*');
    passwordTextField.setPasswordMode(true);
    buttonMulti.addListener(new TextTooltip("This is a tooltip! This is a tooltip! This is a tooltip! This is a tooltip! This is a tooltip! This is a tooltip!", skin));
    Table tooltipTable = new Table(skin);
    tooltipTable.pad(10).background("default-round");
    tooltipTable.add(new TextButton("Fancy tooltip!", skin));
    imgButton.addListener(new Tooltip(tooltipTable));
    // window.debug();
    Window window = new Window("Dialog", skin);
    window.getTitleTable().add(new TextButton("X", skin)).height(window.getPadTop());
    window.setPosition(0, 0);
    window.defaults().spaceBottom(10);
    window.row().fill().expandX();
    window.add(iconButton);
    window.add(buttonMulti);
    window.add(imgButton);
    window.add(imgToggleButton);
    window.row();
    window.add(checkBox);
    window.add(slider).minWidth(100).fillX().colspan(3);
    window.row();
    window.add(selectBox).maxWidth(100);
    window.add(textfield).minWidth(100).expandX().fillX().colspan(3);
    window.row();
    window.add(splitPane).fill().expand().colspan(4).maxHeight(200);
    window.row();
    window.add(passwordLabel).colspan(2);
    window.add(passwordTextField).minWidth(100).expandX().fillX().colspan(2);
    window.row();
    window.add(fpsLabel).colspan(4);
    window.pack();
    // stage.addActor(new Button("Behind Window", skin));
    stage.addActor(window);
    textfield.setTextFieldListener(new TextFieldListener() {

        public void keyTyped(TextField textField, char key) {
            if (key == '\n')
                textField.getOnscreenKeyboard().show(false);
        }
    });
    slider.addListener(new ChangeListener() {

        public void changed(ChangeEvent event, Actor actor) {
            Gdx.app.log("UITest", "slider: " + slider.getValue());
        }
    });
    iconButton.addListener(new ChangeListener() {

        public void changed(ChangeEvent event, Actor actor) {
            new Dialog("Some Dialog", skin, "dialog") {

                protected void result(Object object) {
                    System.out.println("Chosen: " + object);
                }
            }.text("Are you enjoying this demo?").button("Yes", true).button("No", false).key(Keys.ENTER, true).key(Keys.ESCAPE, false).show(stage);
        }
    });
    checkBox.addListener(new ChangeListener() {

        public void changed(ChangeEvent event, Actor actor) {
            Gdx.graphics.setContinuousRendering(checkBox.isChecked());
        }
    });
}
Also used : Slider(com.badlogic.gdx.scenes.scene2d.ui.Slider) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) TextureRegionDrawable(com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable) SplitPane(com.badlogic.gdx.scenes.scene2d.ui.SplitPane) Image(com.badlogic.gdx.scenes.scene2d.ui.Image) Texture(com.badlogic.gdx.graphics.Texture) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) ImageButton(com.badlogic.gdx.scenes.scene2d.ui.ImageButton) TextTooltip(com.badlogic.gdx.scenes.scene2d.ui.TextTooltip) TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Button(com.badlogic.gdx.scenes.scene2d.ui.Button) ImageButton(com.badlogic.gdx.scenes.scene2d.ui.ImageButton) Dialog(com.badlogic.gdx.scenes.scene2d.ui.Dialog) Actor(com.badlogic.gdx.scenes.scene2d.Actor) Stage(com.badlogic.gdx.scenes.scene2d.Stage) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) ImageButtonStyle(com.badlogic.gdx.scenes.scene2d.ui.ImageButton.ImageButtonStyle) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) List(com.badlogic.gdx.scenes.scene2d.ui.List) TextFieldListener(com.badlogic.gdx.scenes.scene2d.ui.TextField.TextFieldListener) ImageButtonStyle(com.badlogic.gdx.scenes.scene2d.ui.ImageButton.ImageButtonStyle) ButtonStyle(com.badlogic.gdx.scenes.scene2d.ui.Button.ButtonStyle) TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Window(com.badlogic.gdx.scenes.scene2d.ui.Window) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) SelectBox(com.badlogic.gdx.scenes.scene2d.ui.SelectBox) TextTooltip(com.badlogic.gdx.scenes.scene2d.ui.TextTooltip) Tooltip(com.badlogic.gdx.scenes.scene2d.ui.Tooltip) ScreenViewport(com.badlogic.gdx.utils.viewport.ScreenViewport) CheckBox(com.badlogic.gdx.scenes.scene2d.ui.CheckBox) ScrollPane(com.badlogic.gdx.scenes.scene2d.ui.ScrollPane) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin)

Example 39 with Skin

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

the class StageDebugTest method create.

@Override
public void create() {
    textureRegion = new TextureRegion(new Texture("data/badlogic.jpg"));
    Gdx.input.setInputProcessor(this);
    stage1 = new Stage();
    stage1.getCamera().position.set(100, 100, 0);
    Group group = new Group();
    // group.setBounds(0, 0, 10, 10);
    // group.setOrigin(25, 50);
    group.setRotation(10);
    group.setScale(1.2f);
    stage1.addActor(group);
    DebugActor actor = new DebugActor();
    actor.setBounds(300, 140, 50, 100);
    actor.setOrigin(25, 50);
    actor.setRotation(-45);
    actor.setScale(2f);
    actor.addAction(forever(rotateBy(360, 8f)));
    group.addActor(actor);
    group.debugAll();
    stage2 = new Stage();
    Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    TextButton shortButton = new TextButton("Button short", skin);
    shortButton.debug();
    TextButton longButton = new TextButton("Button loooooooooong", skin);
    longButton.debug();
    Table root = new Table(skin);
    root.setFillParent(true);
    root.setBackground(skin.getDrawable("default-pane"));
    root.defaults().space(6);
    root.setTransform(true);
    root.rotateBy(10);
    root.setScale(1.3f, 1);
    root.debug();
    stage2.addActor(root);
    root.add(shortButton).pad(5);
    root.add(longButton).row();
    root.add("Colspan").colspan(2).row();
    switchStage();
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) Group(com.badlogic.gdx.scenes.scene2d.Group) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) Texture(com.badlogic.gdx.graphics.Texture)

Example 40 with Skin

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

the class TableLayoutTest method create.

public void create() {
    stage = new Stage();
    Gdx.input.setInputProcessor(stage);
    Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    Label nameLabel = new Label("Name:", skin);
    TextField nameText = new TextField("", skin);
    Label addressLabel = new Label("Address:", skin);
    TextField addressText = new TextField("", skin);
    Table table = new Table();
    stage.addActor(table);
    table.setSize(260, 195);
    table.setPosition(190, 142);
    // table.align(Align.right | Align.bottom);
    table.debug();
    TextureRegion upRegion = skin.getRegion("default-slider-knob");
    TextureRegion downRegion = skin.getRegion("default-slider-knob");
    BitmapFont buttonFont = skin.getFont("default-font");
    TextButton button = new TextButton("Button 1", skin);
    button.addListener(new InputListener() {

        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            System.out.println("touchDown 1");
            return false;
        }
    });
    table.add(button);
    // table.setTouchable(Touchable.disabled);
    Table table2 = new Table();
    stage.addActor(table2);
    table2.setFillParent(true);
    table2.bottom();
    TextButton button2 = new TextButton("Button 2", skin);
    button2.addListener(new ChangeListener() {

        public void changed(ChangeEvent event, Actor actor) {
            System.out.println("2!");
        }
    });
    button2.addListener(new InputListener() {

        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            System.out.println("touchDown 2");
            return false;
        }
    });
    table2.add(button2);
}
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) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) InputListener(com.badlogic.gdx.scenes.scene2d.InputListener) Actor(com.badlogic.gdx.scenes.scene2d.Actor) Stage(com.badlogic.gdx.scenes.scene2d.Stage) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont)

Aggregations

Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)41 Stage (com.badlogic.gdx.scenes.scene2d.Stage)36 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)27 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)20 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)17 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)13 Texture (com.badlogic.gdx.graphics.Texture)11 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)10 Actor (com.badlogic.gdx.scenes.scene2d.Actor)10 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)9 ScrollPane (com.badlogic.gdx.scenes.scene2d.ui.ScrollPane)9 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)9 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)9 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)8 ScreenViewport (com.badlogic.gdx.utils.viewport.ScreenViewport)8 CheckBox (com.badlogic.gdx.scenes.scene2d.ui.CheckBox)6 Image (com.badlogic.gdx.scenes.scene2d.ui.Image)6 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)4 InputListener (com.badlogic.gdx.scenes.scene2d.InputListener)4 List (com.badlogic.gdx.scenes.scene2d.ui.List)4