Search in sources :

Example 6 with Table

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

the class ImageTest method create.

@Override
public void create() {
    skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    image2 = new TextureRegion(new Texture(Gdx.files.internal("data/badlogic.jpg")));
    ui = new Stage();
    Gdx.input.setInputProcessor(ui);
    root = new Table();
    root.setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    ui.addActor(root);
    root.debug();
    Image image = new Image(image2);
    image.setScaling(Scaling.fill);
    root.add(image).width(image2.getRegionWidth()).height(image2.getRegionHeight());
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) Image(com.badlogic.gdx.scenes.scene2d.ui.Image) Texture(com.badlogic.gdx.graphics.Texture)

Example 7 with Table

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

the class InterpolationTest method create.

@Override
public void create() {
    Gdx.gl.glClearColor(.3f, .3f, .3f, 1);
    renderer = new ShapeRenderer();
    skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    stage = new Stage(new ScreenViewport());
    resetPositions();
    Field[] interpolationFields = ClassReflection.getFields(Interpolation.class);
    // see how many fields are actually interpolations (for safety; other fields may be added with future)
    int interpolationMembers = 0;
    for (int i = 0; i < interpolationFields.length; i++) if (ClassReflection.isAssignableFrom(Interpolation.class, interpolationFields[i].getDeclaringClass()))
        interpolationMembers++;
    // get interpolation names
    interpolationNames = new String[interpolationMembers];
    for (int i = 0; i < interpolationFields.length; i++) if (ClassReflection.isAssignableFrom(Interpolation.class, interpolationFields[i].getDeclaringClass()))
        interpolationNames[i] = interpolationFields[i].getName();
    selectedInterpolation = interpolationNames[0];
    list = new List(skin);
    list.setItems(interpolationNames);
    list.addListener(new ChangeListener() {

        public void changed(ChangeEvent event, Actor actor) {
            selectedInterpolation = list.getSelected();
            time = 0;
            resetPositions();
        }
    });
    ScrollPane scroll = new ScrollPane(list, skin);
    scroll.setFadeScrollBars(false);
    scroll.setScrollingDisabled(true, false);
    table = new Table();
    table.setFillParent(true);
    table.add(scroll).expandX().left().width(100);
    stage.addActor(table);
    Gdx.input.setInputProcessor(new InputMultiplexer(new InputAdapter() {

        public boolean scrolled(int amount) {
            if (!Gdx.input.isKeyPressed(Keys.CONTROL_LEFT))
                return false;
            duration -= amount / 15f;
            duration = MathUtils.clamp(duration, 0, Float.POSITIVE_INFINITY);
            return true;
        }
    }, stage, new InputAdapter() {

        public boolean touchDown(int screenX, int screenY, int pointer, int button) {
            if (// if "walking" was interrupted by this touch down event
            !Float.isNaN(time))
                // set startPosition to the current position
                startPosition.set(getPosition(time));
            targetPosition.set(stage.screenToStageCoordinates(targetPosition.set(screenX, screenY)));
            time = 0;
            return true;
        }
    }));
}
Also used : Table(com.badlogic.gdx.scenes.scene2d.ui.Table) InputAdapter(com.badlogic.gdx.InputAdapter) ScreenViewport(com.badlogic.gdx.utils.viewport.ScreenViewport) ShapeRenderer(com.badlogic.gdx.graphics.glutils.ShapeRenderer) Field(com.badlogic.gdx.utils.reflect.Field) Interpolation(com.badlogic.gdx.math.Interpolation) InputMultiplexer(com.badlogic.gdx.InputMultiplexer) ScrollPane(com.badlogic.gdx.scenes.scene2d.ui.ScrollPane) 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)

Example 8 with Table

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

the class LabelScaleTest method create.

@Override
public void create() {
    batch = new SpriteBatch();
    skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    stage = new Stage();
    Gdx.input.setInputProcessor(stage);
    Table table = new Table();
    stage.addActor(table);
    table.setPosition(200, 65);
    Label label1 = new Label("This text is scaled 2x.", skin);
    label1.setFontScale(2);
    Label label2 = new Label("This text is scaled. This text is scaled. This text is scaled. This text is scaled. This text is scaled. ", skin);
    label2.setWrap(true);
    label2.setFontScale(0.75f, 0.75f);
    table.debug();
    table.add(label1);
    table.row();
    table.add(label2).fill();
    table.pack();
}
Also used : Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch)

Example 9 with Table

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

the class TextAreaScrollTest method create.

@Override
public void create() {
    stage = new Stage(new ScreenViewport());
    skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    Gdx.input.setInputProcessor(stage);
    Table container = new Table();
    stage.addActor(container);
    container.setFillParent(true);
    container.pad(10).defaults().expandX().fillX().space(4);
    textArea = new TextArea(">>> FIRST LINE <<<\n" + "Scrolling to the bottom of the area you should see the last line.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Scrolling to the top of the area you should see the first line.\n" + ">>> LAST LINE <<<", skin) {

        public float getPrefHeight() {
            return getLines() * getStyle().font.getLineHeight();
        }
    };
    scrollPane = new ScrollPane(textArea, skin);
    scrollPane.setFadeScrollBars(false);
    scrollPane.setFlickScroll(false);
    container.row().height(350);
    container.add(scrollPane);
    container.debugAll();
}
Also used : Table(com.badlogic.gdx.scenes.scene2d.ui.Table) TextArea(com.badlogic.gdx.scenes.scene2d.ui.TextArea) ScrollPane(com.badlogic.gdx.scenes.scene2d.ui.ScrollPane) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) ScreenViewport(com.badlogic.gdx.utils.viewport.ScreenViewport)

Example 10 with Table

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

the class SoundTest method create.

@Override
public void create() {
    sound = Gdx.audio.newSound(Gdx.files.getFileHandle("data/shotgun.ogg", FileType.Internal));
    skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    ui = new Stage();
    TextButton play = new TextButton("Play", skin);
    TextButton stop = new TextButton("Stop", skin);
    final Slider pitch = new Slider(0.1f, 4, 0.1f, false, skin);
    pitch.setValue(1);
    final Label pitchValue = new Label("1.0", skin);
    final Slider volume = new Slider(0.1f, 1, 0.1f, false, skin);
    volume.setValue(1);
    final Label volumeValue = new Label("1.0", skin);
    Table table = new Table();
    final Slider pan = new Slider(-1f, 1f, 0.1f, false, skin);
    pan.setValue(0);
    final Label panValue = new Label("0.0", skin);
    table.setFillParent(true);
    table.align(Align.center | Align.top);
    table.columnDefaults(0).expandX().right().uniformX();
    table.columnDefaults(2).expandX().left().uniformX();
    table.add(play);
    table.add(stop).left();
    table.row();
    table.add(new Label("Pitch", skin));
    table.add(pitch);
    table.add(pitchValue);
    table.row();
    table.add(new Label("Volume", skin));
    table.add(volume);
    table.add(volumeValue);
    table.row();
    table.add(new Label("Pan", skin));
    table.add(pan);
    table.add(panValue);
    ui.addActor(table);
    play.addListener(new ClickListener() {

        public void clicked(InputEvent event, float x, float y) {
            soundId = sound.play(volume.getValue());
            sound.setPitch(soundId, pitch.getValue());
            sound.setPan(soundId, pan.getValue(), volume.getValue());
        }
    });
    stop.addListener(new ClickListener() {

        public void clicked(InputEvent event, float x, float y) {
            sound.stop(soundId);
        }
    });
    pitch.addListener(new ChangeListener() {

        public void changed(ChangeEvent event, Actor actor) {
            sound.setPitch(soundId, pitch.getValue());
            pitchValue.setText("" + pitch.getValue());
        }
    });
    volume.addListener(new ChangeListener() {

        public void changed(ChangeEvent event, Actor actor) {
            sound.setVolume(soundId, volume.getValue());
            volumeValue.setText("" + volume.getValue());
        }
    });
    pan.addListener(new ChangeListener() {

        public void changed(ChangeEvent event, Actor actor) {
            sound.setPan(soundId, pan.getValue(), volume.getValue());
            panValue.setText("" + pan.getValue());
        }
    });
    Gdx.input.setInputProcessor(ui);
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Slider(com.badlogic.gdx.scenes.scene2d.ui.Slider) Actor(com.badlogic.gdx.scenes.scene2d.Actor) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Aggregations

Table (com.badlogic.gdx.scenes.scene2d.ui.Table)93 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)56 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)50 Stage (com.badlogic.gdx.scenes.scene2d.Stage)48 Actor (com.badlogic.gdx.scenes.scene2d.Actor)43 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)38 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)34 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)32 ScrollPane (com.badlogic.gdx.scenes.scene2d.ui.ScrollPane)25 TextField (com.badlogic.gdx.scenes.scene2d.ui.TextField)23 InputListener (com.badlogic.gdx.scenes.scene2d.InputListener)18 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)18 Texture (com.badlogic.gdx.graphics.Texture)17 Dialog (com.badlogic.gdx.scenes.scene2d.ui.Dialog)14 ScreenViewport (com.badlogic.gdx.utils.viewport.ScreenViewport)14 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)13 Image (com.badlogic.gdx.scenes.scene2d.ui.Image)13 SelectBox (com.badlogic.gdx.scenes.scene2d.ui.SelectBox)13 Button (com.badlogic.gdx.scenes.scene2d.ui.Button)12 CheckBox (com.badlogic.gdx.scenes.scene2d.ui.CheckBox)12