use of com.badlogic.gdx.scenes.scene2d.ui.TextButton in project gdx-skineditor by cobolfoo.
the class NinePatchEditorDialog method reviewTablePreview.
private void reviewTablePreview() {
tablePreview.clear();
//tablePreview.debug();
tablePreview.center().left();
TextButtonStyle stylePreview = new TextButton.TextButtonStyle();
stylePreview.font = game.skin.getFont("default-font");
buttonPreview1 = new TextButton("1x Button", stylePreview);
buttonPreview1.setSize(imgWidth, imgHeight);
cellPreview1 = tablePreview.add(buttonPreview1).width(buttonPreview1.getWidth()).height(buttonPreview1.getHeight()).padBottom(15);
tablePreview.row();
buttonPreview2 = new TextButton("2x Button", stylePreview);
buttonPreview2.setSize(imgWidth * 2.0f, imgHeight * 2.0f);
cellPreview2 = tablePreview.add(buttonPreview2).width(buttonPreview2.getWidth()).height(buttonPreview2.getHeight()).padBottom(15);
tablePreview.row();
buttonPreview3 = new TextButton("3x Button", stylePreview);
buttonPreview3.setSize(imgWidth * 3.0f, imgHeight * 3.0f);
cellPreview3 = tablePreview.add(buttonPreview3).width(buttonPreview3.getWidth()).height(buttonPreview3.getHeight()).padBottom(15);
tablePreview.row();
}
use of com.badlogic.gdx.scenes.scene2d.ui.TextButton in project gdx-skineditor by cobolfoo.
the class MenuBar method showExportDialog.
/*
* Show export dialog
*/
protected void showExportDialog() {
final Preferences prefs = Gdx.app.getPreferences("skin_editor_project_" + game.screenMain.getcurrentProject());
final TextField textDirectory = new TextField(prefs.getString("export_to_directory"), game.skin);
Dialog dlg = new Dialog("Export to Directory", game.skin) {
@Override
protected void result(Object object) {
if ((Boolean) object == true) {
if (textDirectory.getText().isEmpty() == true) {
game.showNotice("Warning", "Directory field is empty!", game.screenMain.stage);
return;
}
FileHandle targetDirectory = new FileHandle(textDirectory.getText());
if (targetDirectory.exists() == false) {
game.showNotice("Warning", "Directory not found!", game.screenMain.stage);
return;
}
// Copy uiskin.* and *.fnt
FileHandle projectFolder = Gdx.files.local("projects").child(game.screenMain.getcurrentProject());
for (FileHandle file : projectFolder.list()) {
if (file.name().startsWith("uiskin.") || (file.extension().equalsIgnoreCase("fnt"))) {
Gdx.app.log("MenuBar", "Copying file: " + file.name() + " ...");
FileHandle target = targetDirectory.child(file.name());
file.copyTo(target);
}
}
game.showNotice("Operation Completed", "Project successfully exported!", game.screenMain.stage);
}
}
};
dlg.pad(20);
Table table = dlg.getContentTable();
table.padTop(20);
table.add("Directory:");
table.add(textDirectory).width(320);
TextButton buttonChoose = new TextButton("...", game.skin);
buttonChoose.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
// Need to steal focus first with this hack (Thanks to Z-Man)
Frame frame = new Frame();
frame.setUndecorated(true);
frame.setOpacity(0);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
frame.toFront();
frame.setVisible(false);
frame.dispose();
JFileChooser chooser = new JFileChooser();
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int ret = chooser.showOpenDialog(null);
if (ret == JFileChooser.APPROVE_OPTION) {
File f = chooser.getSelectedFile();
textDirectory.setText(f.getAbsolutePath());
// Store to file
prefs.putString("export_to_directory", f.getAbsolutePath());
prefs.flush();
}
}
});
table.add(buttonChoose);
table.row();
table.padBottom(20);
dlg.button("Export", true);
dlg.button("Cancel", false);
dlg.key(com.badlogic.gdx.Input.Keys.ENTER, true);
dlg.key(com.badlogic.gdx.Input.Keys.ESCAPE, false);
dlg.show(getStage());
}
use of com.badlogic.gdx.scenes.scene2d.ui.TextButton in project commons-gdx by gemserk.
the class Actors method twoOptionsDialog.
public static Actor twoOptionsDialog(String[] texts, final DialogListener dialogListener, String titleText, String firstOption, String secondOption, Skin skin) {
Window window = new Window(titleText, skin);
window.setMovable(false);
TextButton firstOptionButton = new TextButton(firstOption, skin);
TextButton secondOptionButton = new TextButton(secondOption, skin);
firstOptionButton.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
dialogListener.optionSelected(0);
}
});
secondOptionButton.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
dialogListener.optionSelected(1);
}
});
window.defaults().spaceBottom(10);
window.row().fill().expandX();
for (int i = 0; i < texts.length; i++) {
window.row().padLeft(20);
Label label = new Label(texts[i], skin);
label.setWrap(true);
window.add(label).align(Align.left).colspan(2).fillX();
}
window.row().fill().expandX();
window.add(firstOptionButton).align(Align.center).padLeft(20).padRight(20).expandX();
window.add(secondOptionButton).align(Align.center).padLeft(20).padRight(20).expandX();
ScrollPane scrollPane = new ScrollPane(window);
scrollPane.setWidth(Gdx.graphics.getWidth() * 0.95f);
scrollPane.setHeight(Gdx.graphics.getHeight() * 0.95f);
scrollPane.setX(Gdx.graphics.getWidth() * 0.5f - scrollPane.getWidth() * 0.5f);
scrollPane.setY(Gdx.graphics.getHeight() * 0.5f - scrollPane.getHeight() * 0.5f);
return scrollPane;
}
use of com.badlogic.gdx.scenes.scene2d.ui.TextButton 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;
}
}
});
}
use of com.badlogic.gdx.scenes.scene2d.ui.TextButton 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();
}
Aggregations