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());
}
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;
}
}));
}
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();
}
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();
}
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);
}
Aggregations