use of com.badlogic.gdx.scenes.scene2d.utils.ChangeListener in project gdx-skineditor by cobolfoo.
the class WelcomeScreen method show.
@Override
public void show() {
Table table = new Table(game.skin);
table.setFillParent(true);
table.setBackground(game.skin.getDrawable("dialogDim"));
stage.addActor(table);
Table tableContent = new Table(game.skin);
tableContent.left();
tableContent.add(new Label("Project List", game.skin, "title")).left().row();
listProjects = new List<String>(game.skin);
ScrollPane scrollPane = new ScrollPane(listProjects, game.skin);
tableContent.add(scrollPane).width(320).height(200).row();
Table tableButtons = new Table(game.skin);
TextButton buttonNewProject = new TextButton("New Project", game.skin);
final TextButton buttonOpen = new TextButton("Open", game.skin);
final TextButton buttonDelete = new TextButton("Delete", game.skin);
buttonOpen.setDisabled(true);
buttonDelete.setDisabled(true);
tableButtons.add(buttonNewProject).pad(5).expandX().fillX();
tableButtons.add(buttonOpen).pad(5).width(92);
tableButtons.add(buttonDelete).pad(5).width(92);
tableContent.add(tableButtons).expandX().fillX();
table.add(tableContent);
Gdx.input.setInputProcessor(stage);
listProjects.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
if (listProjects.getSelected() != null) {
buttonOpen.setDisabled(false);
buttonDelete.setDisabled(false);
} else {
buttonOpen.setDisabled(true);
buttonDelete.setDisabled(true);
}
}
});
buttonNewProject.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
showNewProjectDialog();
}
});
buttonOpen.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
game.screenMain.setCurrentProject((String) listProjects.getSelected());
game.setScreen(game.screenMain);
}
});
buttonDelete.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
showDeleteDialog();
}
});
refreshProjects();
// NinePatchEditorDialog dlg = new NinePatchEditorDialog(game);
// dlg.show(stage);
}
use of com.badlogic.gdx.scenes.scene2d.utils.ChangeListener in project libgdx by libgdx.
the class BaseG3dHudTest method createHUD.
protected void createHUD() {
hud = new Stage(new ScalingViewport(Scaling.fit, PREF_HUDWIDTH, PREF_HUDHEIGHT));
hudWidth = hud.getWidth();
hudHeight = hud.getHeight();
skin = new Skin(Gdx.files.internal("data/uiskin.json"));
final List<String> modelsList = new List(skin);
modelsList.setItems(models);
modelsList.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
if (!modelsWindow.isCollapsed() && getTapCount() == 2) {
onModelClicked(modelsList.getSelected());
modelsWindow.collapse();
}
}
});
modelsWindow = addListWindow("Models", modelsList, 0, -1);
fpsLabel = new Label("FPS: 999", skin);
hud.addActor(fpsLabel);
gridCheckBox = new CheckBox("Show grid", skin);
gridCheckBox.setChecked(showAxes);
gridCheckBox.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
showAxes = gridCheckBox.isChecked();
}
});
gridCheckBox.setPosition(hudWidth - gridCheckBox.getWidth(), 0);
hud.addActor(gridCheckBox);
rotateCheckBox = new CheckBox("Rotate", skin);
rotateCheckBox.setChecked(true);
rotateCheckBox.setPosition(hudWidth - rotateCheckBox.getWidth(), gridCheckBox.getHeight());
hud.addActor(rotateCheckBox);
moveCheckBox = new CheckBox("Move", skin);
moveCheckBox.setChecked(false);
moveCheckBox.setPosition(hudWidth - moveCheckBox.getWidth(), rotateCheckBox.getTop());
hud.addActor(moveCheckBox);
}
use of com.badlogic.gdx.scenes.scene2d.utils.ChangeListener in project libgdx by libgdx.
the class NoncontinuousRenderingTest method populateTable.
private void populateTable() {
Table root = new Table();
stage.addActor(root);
root.setFillParent(true);
root.pad(5);
root.defaults().left().space(5);
Button button0 = new TextButton("Toggle continuous rendering", skin, "toggle");
button0.addListener(new ChangeListener() {
public void changed(ChangeEvent event, Actor actor) {
boolean continuous = Gdx.graphics.isContinuousRendering();
Gdx.graphics.setContinuousRendering(!continuous);
}
});
root.add(button0).row();
final String str1 = "2s sleep -> Application.postRunnable()";
Button button1 = new TextButton(str1, skin);
button1.addListener(new ChangeListener() {
public void changed(ChangeEvent event, Actor actor) {
new Thread(new Runnable() {
public void run() {
try {
Thread.sleep(2000);
} catch (InterruptedException ignored) {
}
nextColor();
Gdx.app.postRunnable(new Runnable() {
public void run() {
Gdx.app.log(str1, "Posted runnable to Gdx.app");
}
});
}
}).start();
}
});
root.add(button1).row();
final String str2 = "2s sleep -> Graphics.requestRendering()";
Button button2 = new TextButton(str2, skin);
button2.addListener(new ChangeListener() {
public void changed(ChangeEvent event, Actor actor) {
// caching necessary to ensure call on this window
final Graphics graphics = Gdx.graphics;
new Thread(new Runnable() {
public void run() {
try {
Thread.sleep(2000);
} catch (InterruptedException ignored) {
}
nextColor();
graphics.requestRendering();
Gdx.app.log(str2, "Called Gdx.graphics.requestRendering()");
}
}).start();
}
});
root.add(button2).row();
final String str3 = "2s Timer -> Application.postRunnable()";
Button button3 = new TextButton(str3, skin);
button3.addListener(new ChangeListener() {
public void changed(ChangeEvent event, Actor actor) {
Timer.schedule(new Task() {
public void run() {
nextColor();
Gdx.app.postRunnable(new Runnable() {
public void run() {
Gdx.app.log(str3, "Posted runnable to Gdx.app");
}
});
}
}, 2f);
}
});
root.add(button3).row();
final String str4 = "2s DelayAction";
Button button4 = new TextButton(str4, skin);
button4.addListener(new ChangeListener() {
public void changed(ChangeEvent event, Actor actor) {
stage.addAction(Actions.sequence(Actions.delay(2), Actions.run(new Runnable() {
public void run() {
nextColor();
Gdx.app.log(str4, "RunnableAction executed");
}
})));
}
});
root.add(button4).row();
final String str5 = "(2s sleep -> toggle continuous) 2X";
Button button5 = new TextButton(str5, skin);
button5.addListener(new ChangeListener() {
public void changed(ChangeEvent event, Actor actor) {
// caching necessary to ensure call on this window
final Graphics graphics = Gdx.graphics;
new Thread(new Runnable() {
public void run() {
for (int i = 0; i < 2; i++) {
try {
Thread.sleep(2000);
} catch (InterruptedException ignored) {
}
nextColor();
boolean continuous = graphics.isContinuousRendering();
graphics.setContinuousRendering(!continuous);
Gdx.app.log(str5, "Toggled continuous");
}
}
}).start();
}
});
root.add(button5).row();
final CheckBox actionsRequestRendering = new CheckBox("ActionsRequestRendering", skin);
actionsRequestRendering.setChecked(true);
actionsRequestRendering.addListener(new ChangeListener() {
public void changed(ChangeEvent event, Actor actor) {
stage.setActionsRequestRendering(actionsRequestRendering.isChecked());
}
});
root.add(actionsRequestRendering).row();
Drawable knobDown = skin.newDrawable("default-slider-knob", Color.GRAY);
SliderStyle sliderStyle = skin.get("default-horizontal", SliderStyle.class);
sliderStyle.knobDown = knobDown;
Slider slider = new Slider(0, 100, 1, false, sliderStyle);
root.add(slider).row();
SelectBox<Pixmap.Format> selectBox = new SelectBox(skin);
selectBox.setItems(Pixmap.Format.values());
root.add(selectBox).row();
root.add();
root.add().grow();
}
use of com.badlogic.gdx.scenes.scene2d.utils.ChangeListener in project libgdx by libgdx.
the class ScrollPaneScrollBarsTest method create.
public void create() {
float width = Gdx.graphics.getWidth();
float height = Gdx.graphics.getHeight();
float btnWidth = 200;
float btnHeight = 40;
stage = new Stage();
Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));
Gdx.input.setInputProcessor(stage);
final TextButton fadeBtn = new TextButton("Fade: " + doFade, skin);
fadeBtn.setSize(btnWidth, btnHeight);
fadeBtn.setPosition(0, height - fadeBtn.getHeight());
stage.addActor(fadeBtn);
fadeBtn.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
doFade = !doFade;
fadeBtn.setText("Fade: " + doFade);
for (ScrollPane pane : scrollPanes) {
pane.setFadeScrollBars(doFade);
}
}
});
final TextButton onTopBtn = new TextButton("ScrollbarsOnTop: " + doOnTop, skin);
onTopBtn.setSize(btnWidth, btnHeight);
onTopBtn.setPosition(0 + fadeBtn.getWidth() + 20, height - onTopBtn.getHeight());
stage.addActor(onTopBtn);
onTopBtn.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
doOnTop = !doOnTop;
onTopBtn.setText("ScrollbarOnTop: " + doOnTop);
onTopBtn.invalidate();
for (ScrollPane pane : scrollPanes) {
pane.setScrollbarsOnTop(doOnTop);
}
}
});
// Gdx.graphics.setVSync(false);
float gap = 8;
float x = gap;
float y = gap;
float contWidth = width / 2 - gap * 1.5f;
float contHeight = height / 4.5f - gap * 1.25f;
bottomLeft = new Table();
bottomLeft.setPosition(x, y);
bottomLeft.setSize(contWidth, contHeight);
stage.addActor(bottomLeft);
bottomRight = new Table();
bottomRight.setSize(contWidth, contHeight);
x = bottomLeft.getX() + bottomLeft.getWidth() + gap;
bottomRight.setPosition(x, y);
stage.addActor(bottomRight);
topLeft = new Table();
topLeft.setSize(contWidth, contHeight);
x = bottomLeft.getX();
y = bottomLeft.getY() + bottomLeft.getHeight() + gap;
topLeft.setPosition(x, y);
stage.addActor(topLeft);
topRight = new Table();
topRight.setSize(contWidth, contHeight);
x = bottomRight.getX();
y = topLeft.getY();
topRight.setPosition(x, y);
stage.addActor(topRight);
horizOnlyTop = new Table();
horizOnlyTop.setSize(contWidth, contHeight);
x = topRight.getX();
y = topRight.getY() + topRight.getHeight() + gap;
horizOnlyTop.setPosition(x, y);
stage.addActor(horizOnlyTop);
horizOnlyBottom = new Table();
horizOnlyBottom.setSize(contWidth, contHeight);
x = topLeft.getX();
y = topLeft.getY() + topLeft.getHeight() + gap;
horizOnlyBottom.setPosition(x, y);
stage.addActor(horizOnlyBottom);
vertOnlyLeft = new Table();
vertOnlyLeft.setSize(contWidth, contHeight);
x = horizOnlyBottom.getX();
y = horizOnlyBottom.getY() + horizOnlyBottom.getHeight() + gap;
vertOnlyLeft.setPosition(x, y);
stage.addActor(vertOnlyLeft);
vertOnlyRight = new Table();
vertOnlyRight.setSize(contWidth, contHeight);
x = horizOnlyTop.getX();
y = horizOnlyTop.getY() + horizOnlyTop.getHeight() + gap;
vertOnlyRight.setPosition(x, y);
stage.addActor(vertOnlyRight);
Table bottomLeftTable = new Table();
Table bottomRightTable = new Table();
Table topLeftTable = new Table();
Table topRightTable = new Table();
Table horizOnlyTopTable = new Table();
Table horizOnlyBottomTable = new Table();
Table vertOnlyLeftTable = new Table();
Table vertOnlyRightTable = new Table();
final ScrollPane bottomLeftScroll = new ScrollPane(bottomLeftTable, skin);
bottomLeftScroll.setScrollBarPositions(true, false);
final ScrollPane bottomRightScroll = new ScrollPane(bottomRightTable, skin);
bottomRightScroll.setScrollBarPositions(true, true);
final ScrollPane topLeftScroll = new ScrollPane(topLeftTable, skin);
topLeftScroll.setScrollBarPositions(false, false);
final ScrollPane topRightScroll = new ScrollPane(topRightTable, skin);
topRightScroll.setScrollBarPositions(false, true);
final ScrollPane horizOnlyTopScroll = new ScrollPane(horizOnlyTopTable, skin);
horizOnlyTopScroll.setScrollBarPositions(false, true);
final ScrollPane horizOnlyBottomScroll = new ScrollPane(horizOnlyBottomTable, skin);
horizOnlyBottomScroll.setScrollBarPositions(true, true);
final ScrollPane vertOnlyLeftScroll = new ScrollPane(vertOnlyLeftTable, skin);
vertOnlyLeftScroll.setScrollBarPositions(true, false);
final ScrollPane vertOnlyRightScroll = new ScrollPane(vertOnlyRightTable, skin);
vertOnlyRightScroll.setScrollBarPositions(true, true);
ScrollPane[] panes = new ScrollPane[] { bottomLeftScroll, bottomRightScroll, topLeftScroll, topRightScroll, horizOnlyTopScroll, horizOnlyBottomScroll, vertOnlyLeftScroll, vertOnlyRightScroll };
for (ScrollPane pane : panes) {
scrollPanes.add(pane);
}
Table[] tables = new Table[] { bottomLeftTable, bottomRightTable, topLeftTable, topRightTable, horizOnlyTopTable, horizOnlyBottomTable, vertOnlyLeftTable, vertOnlyRightTable };
for (Table t : tables) t.defaults().expandX().fillX();
horizOnlyTopTable.add(new Label("HORIZONTAL-ONLY-TOP verify HORIZONTAL scroll bar is on the TOP and properly aligned", skin)).row();
horizOnlyTopTable.add(new Image(skin.getDrawable("default-rect"))).height(20).row();
horizOnlyBottomTable.add(new Label("HORIZONTAL-ONLY-BOTTOM verify HORIZONTAL scroll bar is on the BOTTOM and properly aligned", skin)).row();
horizOnlyBottomTable.add(new Image(skin.getDrawable("default-rect"))).height(20).row();
for (int i = 0; i < 12; i++) {
bottomLeftTable.add(new Label(i + " BOTTOM-LEFT verify scroll bars are on the BOTTOM and the LEFT, and are properly aligned", skin)).row();
bottomLeftTable.add(new Image(skin.getDrawable("default-rect"))).height(20).row();
bottomRightTable.add(new Label(i + " BOTTOM-RIGHT verify scroll bars are on the BOTTOM and the RIGHT, and are properly aligned", skin)).row();
bottomRightTable.add(new Image(skin.getDrawable("default-rect"))).height(20).row();
topLeftTable.add(new Label(i + " TOP-LEFT verify scroll bars are on the TOP and the LEFT, and are properly aligned", skin)).row();
topLeftTable.add(new Image(skin.getDrawable("default-rect"))).height(20).row();
topRightTable.add(new Label(i + " TOP-RIGHT verify scroll bars are on the TOP and the RIGHT, and are properly aligned", skin)).row();
topRightTable.add(new Image(skin.getDrawable("default-rect"))).height(20).row();
vertOnlyLeftTable.add(new Label("VERT-ONLY-LEFT", skin)).row();
vertOnlyLeftTable.add(new Image(skin.getDrawable("default-rect"))).height(20).row();
vertOnlyRightTable.add(new Label("VERT-ONLY-RIGHT", skin)).row();
vertOnlyRightTable.add(new Image(skin.getDrawable("default-rect"))).height(20).row();
}
bottomLeft.add(bottomLeftScroll).expand().fill().colspan(4);
bottomRight.add(bottomRightScroll).expand().fill().colspan(4);
topLeft.add(topLeftScroll).expand().fill().colspan(4);
topRight.add(topRightScroll).expand().fill().colspan(4);
horizOnlyTop.add(horizOnlyTopScroll).expand().fill().colspan(4);
horizOnlyBottom.add(horizOnlyBottomScroll).expand().fill().colspan(4);
vertOnlyLeft.add(vertOnlyLeftScroll).expand().fill().colspan(4);
vertOnlyRight.add(vertOnlyRightScroll).expand().fill().colspan(4);
for (ScrollPane pane : scrollPanes) {
pane.setFadeScrollBars(doFade);
pane.setScrollbarsOnTop(doOnTop);
}
}
use of com.badlogic.gdx.scenes.scene2d.utils.ChangeListener in project libgdx by libgdx.
the class ScrollPaneTest method create.
public void create() {
stage = new Stage();
Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));
Gdx.input.setInputProcessor(stage);
// Gdx.graphics.setVSync(false);
container = new Table();
stage.addActor(container);
container.setFillParent(true);
Table table = new Table();
// table.debug();
final ScrollPane scroll = new ScrollPane(table, skin);
InputListener stopTouchDown = new InputListener() {
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
event.stop();
return false;
}
};
table.pad(10).defaults().expandX().space(4);
for (int i = 0; i < 100; i++) {
table.row();
table.add(new Label(i + "uno", skin)).expandX().fillX();
TextButton button = new TextButton(i + "dos", skin);
table.add(button);
button.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
System.out.println("click " + x + ", " + y);
}
});
Slider slider = new Slider(0, 100, 1, false, skin);
// Stops touchDown events from propagating to the FlickScrollPane.
slider.addListener(stopTouchDown);
table.add(slider);
table.add(new Label(i + "tres long0 long1 long2 long3 long4 long5 long6 long7 long8 long9 long10 long11 long12", skin));
}
final TextButton flickButton = new TextButton("Flick Scroll", skin.get("toggle", TextButtonStyle.class));
flickButton.setChecked(true);
flickButton.addListener(new ChangeListener() {
public void changed(ChangeEvent event, Actor actor) {
scroll.setFlickScroll(flickButton.isChecked());
}
});
final TextButton fadeButton = new TextButton("Fade Scrollbars", skin.get("toggle", TextButtonStyle.class));
fadeButton.setChecked(true);
fadeButton.addListener(new ChangeListener() {
public void changed(ChangeEvent event, Actor actor) {
scroll.setFadeScrollBars(fadeButton.isChecked());
}
});
final TextButton smoothButton = new TextButton("Smooth Scrolling", skin.get("toggle", TextButtonStyle.class));
smoothButton.setChecked(true);
smoothButton.addListener(new ChangeListener() {
public void changed(ChangeEvent event, Actor actor) {
scroll.setSmoothScrolling(smoothButton.isChecked());
}
});
final TextButton onTopButton = new TextButton("Scrollbars On Top", skin.get("toggle", TextButtonStyle.class));
onTopButton.addListener(new ChangeListener() {
public void changed(ChangeEvent event, Actor actor) {
scroll.setScrollbarsOnTop(onTopButton.isChecked());
}
});
container.add(scroll).expand().fill().colspan(4);
container.row().space(10).padBottom(10);
container.add(flickButton).right().expandX();
container.add(onTopButton);
container.add(smoothButton);
container.add(fadeButton).left().expandX();
}
Aggregations