use of com.badlogic.gdx.scenes.scene2d.ui.Button in project gdx-skineditor by cobolfoo.
the class PreviewPane method refresh.
/**
*
*/
public void refresh() {
Gdx.app.log("PreviewPane", "Refresh pane!");
clear();
ImageButton button = (ImageButton) game.screenMain.barWidgets.group.getChecked();
String widget = button.getUserObject().toString();
String widgetStyle = "com.badlogic.gdx.scenes.scene2d.ui." + widget + "$" + widget + "Style";
try {
Class<?> style = Class.forName(widgetStyle);
ObjectMap<String, ?> styles = game.skinProject.getAll(style);
if (styles == null) {
Label label = new Label("No styles defined for this widget type", game.skin, "error");
add(label).row().pad(10);
} else {
Keys<String> keys = styles.keys();
Array<String> sortedKeys = new Array<String>();
for (String key : keys) {
sortedKeys.add(key);
}
sortedKeys.sort();
for (String key : sortedKeys) {
// We render one per key
add(new Label(key, game.skin, "title")).left().pad(10).expandX().row();
try {
if (widget.equals("Label")) {
Label w = new Label("This is a Label widget", game.skinProject, key);
add(w).pad(10).padBottom(20).row();
} else if (widget.equals("Button")) {
// Button
Button w = new Button(game.skinProject, key);
add(w).width(120).height(32).pad(10).padBottom(20).row();
} else if (widget.equals("TextButton")) {
// TextButton
TextButton w = new TextButton("This is a TextButton widget", game.skinProject, key);
add(w).pad(10).padBottom(20).row();
} else if (widget.equals("ImageButton")) {
// ImageButton
ImageButton w = new ImageButton(game.skinProject, key);
add(w).pad(10).padBottom(20).row();
} else if (widget.equals("CheckBox")) {
// CheckBox
CheckBox w = new CheckBox("This is a CheckBox widget", game.skinProject, key);
w.setChecked(true);
add(w).pad(10).padBottom(20).row();
} else if (widget.equals("TextField")) {
// TextField
TextField w = new TextField("This is a TextField widget", game.skinProject, key);
if (w.getStyle().fontColor == null) {
throw new Exception("Textfield style requires a font color!");
}
w.addListener(stopTouchDown);
add(w).pad(10).width(220).padBottom(20).row();
} else if (widget.equals("List")) {
// List
List w = new List(game.skinProject, key);
Array<String> items = new Array<String>();
items.add("This is");
items.add("a");
items.add("List widget!");
w.setItems(items);
add(w).pad(10).width(220).height(120).padBottom(20).expandX().fillX().row();
} else if (widget.equals("SelectBox")) {
// SelectBox
SelectBox<String> w = new SelectBox<String>(game.skinProject, key);
Array<String> items = new Array<String>();
items.add("This is");
items.add("a");
items.add("SelectBox widget!");
w.setItems(items);
add(w).pad(10).width(220).padBottom(20).expandX().fillX().row();
} else if (widget.equals("ProgressBar")) {
// ProgressBar
ProgressBarStyle progressStyle = game.skinProject.get(key, ProgressBarStyle.class);
// Check for edge-case: fields knob and knobBefore are optional but at least one should be specified
if (progressStyle.knob == null && progressStyle.knobBefore == null) {
throw new IllegalArgumentException("Fields 'knob' and 'knobBefore' in ProgressBarStyle are both optional but at least one should be specified");
}
ProgressBar w = new ProgressBar(0, 100, 5, false, progressStyle);
w.setValue(50);
w.addListener(stopTouchDown);
add(w).pad(10).width(220).padBottom(20).expandX().fillX().row();
} else if (widget.equals("Slider")) {
// Slider
Slider w = new Slider(0, 100, 5, false, game.skinProject, key);
add(w).pad(10).width(220).padBottom(20).expandX().fillX().row();
w.addListener(stopTouchDown);
Slider w2 = new Slider(0, 100, 5, true, game.skinProject, key);
add(w2).pad(10).padBottom(20).expandX().fillX().row();
w2.addListener(stopTouchDown);
} else if (widget.equals("ScrollPane")) {
// ScrollPane
Table t = new Table(game.skin);
for (int i = 0; i < 20; i++) {
t.add("This is a ScrollPane Widget").padRight(10);
t.add("This is a ScrollPane Widget").padRight(10);
t.add("This is a ScrollPane Widget").row();
}
ScrollPane w = new ScrollPane(t, game.skinProject, key);
w.addListener(stopTouchDown);
w.setFlickScroll(true);
w.setScrollbarsOnTop(true);
w.setScrollBarPositions(true, true);
w.setFadeScrollBars(false);
add(w).pad(10).width(420).height(240).padBottom(20).expandX().fillX().row();
} else if (widget.equals("SplitPane")) {
for (int j = 0; j < 2; j++) {
Table t = new Table(game.skin);
t.setBackground(game.skin.getDrawable("default-rect"));
Table t2 = new Table(game.skin);
t2.setBackground(game.skin.getDrawable("default-rect"));
for (int i = 0; i < 20; i++) {
t.add("This is a SplitPane Widget").pad(10).row();
t2.add("This is a SplitPane Widget").pad(10).row();
}
SplitPane w = new SplitPane(t, t2, (j % 2 == 0), game.skinProject, key);
w.addListener(stopTouchDown);
add(w).pad(10).width(220).height(160).padBottom(20).expandX().fillX();
}
row();
} else if (widget.equals("Window")) {
// Window
Table t = new Table(game.skin);
for (int i = 0; i < 5; i++) {
t.add("This is a Window Widget").row();
}
Window w = new Window("This is a Window Widget", game.skinProject, key);
w.addListener(stopTouchDown);
w.add(t);
add(w).pad(10).width(420).height(240).padBottom(20).expandX().fillX().row();
} else if (widget.equals("Touchpad")) {
// Touchpad
Touchpad w = new Touchpad(0, game.skinProject, key);
w.addListener(stopTouchDown);
add(w).pad(10).width(200).height(200).padBottom(20).expandX().fillX().row();
} else if (widget.equals("Tree")) {
// Tree
Tree w = new Tree(game.skinProject, key);
Tree.Node node = new Tree.Node(new Label("This", game.skin));
Tree.Node node1 = new Tree.Node(new Label("is", game.skin));
Tree.Node node2 = new Tree.Node(new Label("a", game.skin));
Tree.Node node3 = new Tree.Node(new Label("Tree", game.skin));
Tree.Node node4 = new Tree.Node(new Label("Widget", game.skin));
node3.add(node4);
node2.add(node3);
node1.add(node2);
node.add(node1);
w.add(node);
w.expandAll();
add(w).pad(10).width(200).height(200).padBottom(20).expandX().fillX().row();
} else {
add(new Label("Unknown widget type!", game.skin, "error")).pad(10).padBottom(20).row();
}
} catch (Exception e) {
add(new Label("Please fill all required fields", game.skin, "error")).pad(10).padBottom(20).row();
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.badlogic.gdx.scenes.scene2d.ui.Button 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());
}
});
}
use of com.badlogic.gdx.scenes.scene2d.ui.Button 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.ui.Button in project gdx-skineditor by cobolfoo.
the class DrawablePickerDialog method updateTable.
/**
*
*/
public void updateTable() {
tableDrawables.clear();
Iterator<String> keys = items.keys().iterator();
int count = 0;
while (keys.hasNext()) {
final String key = keys.next();
if (key.startsWith("widgets/")) {
continue;
}
Button buttonItem = new Button(game.skin);
Image img = null;
if (items.get(key) instanceof Drawable) {
img = new Image((Drawable) items.get(key));
} else {
img = new Image((TextureRegion) items.get(key));
}
if (zoom == true) {
buttonItem.add(img).expand().fill().pad(5);
} else {
buttonItem.add(img).expand().pad(5);
}
buttonItem.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
if (field == null) {
return;
}
try {
// game.screenMain.paneOptions.refreshSelection();
if (items.get(key) instanceof Drawable) {
field.set(game.screenMain.paneOptions.currentStyle, items.get(key));
} else {
boolean ninepatch = false;
FileHandle test = new FileHandle("projects/" + game.screenMain.getcurrentProject() + "/assets/" + key + ".9.png");
if (test.exists() == true) {
ninepatch = true;
}
if (ninepatch == true) {
game.skinProject.add(key, new NinePatchDrawable(new NinePatch((TextureRegion) items.get(key))));
field.set(game.screenMain.paneOptions.currentStyle, game.skinProject.getDrawable(key));
} else {
game.skinProject.add(key, new SpriteDrawable(new Sprite((TextureRegion) items.get(key))));
field.set(game.screenMain.paneOptions.currentStyle, game.skinProject.getDrawable(key));
}
}
game.screenMain.saveToSkin();
hide();
game.screenMain.panePreview.refresh();
game.screenMain.paneOptions.updateSelectedTableFields();
} catch (Exception e) {
e.printStackTrace();
}
}
});
String objectType = items.get(key).getClass().getSimpleName();
objectType = objectType.replace("Drawable", "");
buttonItem.row();
buttonItem.add(new Label(key, game.skin));
buttonItem.row();
buttonItem.add(new Label(objectType, game.skin, "title"));
buttonItem.row();
buttonItem.setClip(true);
tableDrawables.add(buttonItem).width(160).height(184).pad(5);
if (count == 4) {
count = 0;
tableDrawables.row();
continue;
}
count++;
}
}
Aggregations