use of com.badlogic.gdx.scenes.scene2d.utils.ClickListener in project libgdx by libgdx.
the class GwtTestWrapper method create.
@Override
public void create() {
Gdx.app.setLogLevel(Application.LOG_DEBUG);
Gdx.app.log("GdxTestGwt", "Setting up for " + tests.length + " tests.");
ui = new Stage();
skin = new Skin(Gdx.files.internal("data/uiskin.json"));
font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false);
container = new Table();
ui.addActor(container);
container.debug();
Table table = new Table();
ScrollPane scroll = new ScrollPane(table);
container.add(scroll).expand().fill();
table.pad(10).defaults().expandX().space(4);
Arrays.sort(tests, new Comparator<Instancer>() {
@Override
public int compare(Instancer o1, Instancer o2) {
return o1.instance().getClass().getName().compareTo(o2.instance().getClass().getName());
}
});
for (final Instancer instancer : tests) {
table.row();
TextButton button = new TextButton(instancer.instance().getClass().getName(), skin);
button.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
((InputWrapper) Gdx.input).multiplexer.removeProcessor(ui);
test = instancer.instance();
Gdx.app.log("GdxTestGwt", "Clicked on " + test.getClass().getName());
test.create();
test.resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
}
});
table.add(button).expandX().fillX();
}
container.row();
container.add(new Label("Click on a test to start it, press ESC to close it.", new LabelStyle(font, Color.WHITE))).pad(5, 5, 5, 5);
Gdx.input = new InputWrapper(Gdx.input) {
@Override
public boolean keyUp(int keycode) {
if (keycode == Keys.ESCAPE) {
if (test != null) {
Gdx.app.log("GdxTestGwt", "Exiting current test.");
dispose = true;
}
}
return false;
}
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
if (screenX < Gdx.graphics.getWidth() / 10.0 && screenY < Gdx.graphics.getHeight() / 10.0) {
if (test != null) {
dispose = true;
}
}
return false;
}
};
((InputWrapper) Gdx.input).multiplexer.addProcessor(ui);
Gdx.app.log("GdxTestGwt", "Test picker UI setup complete.");
}
use of com.badlogic.gdx.scenes.scene2d.utils.ClickListener in project libgdx by libgdx.
the class NetAPITest method create.
@Override
public void create() {
batch = new SpriteBatch();
skin = new Skin(Gdx.files.internal("data/uiskin.json"));
font = new BitmapFont();
stage = new Stage();
Gdx.input.setInputProcessor(stage);
{
statusLabel = new Label("", skin);
statusLabel.setWrap(true);
statusLabel.setWidth(Gdx.graphics.getWidth() * 0.96f);
statusLabel.setAlignment(Align.center);
statusLabel.setPosition(Gdx.graphics.getWidth() * 0.5f - statusLabel.getWidth() * 0.5f, 30f);
statusLabel.setColor(Color.CYAN);
stage.addActor(statusLabel);
}
{
ClickListener clickListener = new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
super.clicked(event, x, y);
clickedButton = event.getListenerActor();
setButtonDisabled(true);
if (texture != null)
texture.dispose();
texture = null;
text = null;
String url;
String httpMethod = Net.HttpMethods.GET;
String requestContent = null;
if (clickedButton == btnDownloadImage)
url = "http://i.imgur.com/vxomF.jpg";
else if (clickedButton == btnDownloadText)
url = "http://www.apache.org/licenses/LICENSE-2.0.txt";
else if (clickedButton == btnDownloadLarge)
url = "http://libgdx.badlogicgames.com/releases/libgdx-1.2.0.zip";
else if (clickedButton == btnDownloadError)
url = "http://www.badlogicgames.com/doesnotexist";
else if (clickedButton == btnOpenUri) {
Gdx.net.openURI("http://libgdx.badlogicgames.com/");
return;
} else {
url = "http://posttestserver.com/post.php?dump";
httpMethod = Net.HttpMethods.POST;
requestContent = "name1=value1&name2=value2";
}
httpRequest = new HttpRequest(httpMethod);
httpRequest.setUrl(url);
httpRequest.setContent(requestContent);
Gdx.net.sendHttpRequest(httpRequest, NetAPITest.this);
statusLabel.setText("Downloading data from " + httpRequest.getUrl());
}
};
ClickListener cancelListener = new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
super.clicked(event, x, y);
if (httpRequest != null) {
Gdx.net.cancelHttpRequest(httpRequest);
Gdx.app.log("NetAPITest", "Cancelling request " + httpRequest.getUrl());
statusLabel.setText("Cancelling request " + httpRequest.getUrl());
}
}
};
btnCancel = new TextButton("Cancel", skin);
btnCancel.setPosition(Gdx.graphics.getWidth() * 0.10f, 60f);
btnCancel.addListener(cancelListener);
stage.addActor(btnCancel);
btnDownloadImage = new TextButton("GET Image", skin);
btnDownloadImage.setPosition(btnCancel.getX() + btnCancel.getWidth() + 10, 60f);
btnDownloadImage.addListener(clickListener);
stage.addActor(btnDownloadImage);
btnDownloadText = new TextButton("GET Text", skin);
btnDownloadText.setPosition(btnDownloadImage.getX() + btnDownloadImage.getWidth() + 10, 60f);
btnDownloadText.addListener(clickListener);
stage.addActor(btnDownloadText);
btnDownloadLarge = new TextButton("GET Large", skin);
btnDownloadLarge.setPosition(btnDownloadText.getX() + btnDownloadText.getWidth() + 10, 60f);
btnDownloadLarge.addListener(clickListener);
stage.addActor(btnDownloadLarge);
btnDownloadError = new TextButton("GET Error", skin);
btnDownloadError.setPosition(btnDownloadLarge.getX() + btnDownloadLarge.getWidth() + 10, 60f);
btnDownloadError.addListener(clickListener);
stage.addActor(btnDownloadError);
btnPost = new TextButton("POST", skin);
btnPost.setPosition(btnDownloadError.getX() + btnDownloadError.getWidth() + 10, 60f);
btnPost.addListener(clickListener);
stage.addActor(btnPost);
btnOpenUri = new TextButton("Open URI", skin);
btnOpenUri.setPosition(btnPost.getX() + btnPost.getWidth() + 10, 60f);
btnOpenUri.addListener(clickListener);
stage.addActor(btnOpenUri);
}
}
use of com.badlogic.gdx.scenes.scene2d.utils.ClickListener 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.utils.ClickListener 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();
}
use of com.badlogic.gdx.scenes.scene2d.utils.ClickListener in project libgdx by libgdx.
the class TreeTest method create.
public void create() {
stage = new Stage();
Gdx.input.setInputProcessor(stage);
Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));
Table table = new Table();
table.setFillParent(true);
stage.addActor(table);
final Tree tree = new Tree(skin);
final Node moo1 = new Node(new TextButton("moo1", skin));
final Node moo2 = new Node(new TextButton("moo2", skin));
final Node moo3 = new Node(new TextButton("moo3", skin));
final Node moo4 = new Node(new TextButton("moo4", skin));
final Node moo5 = new Node(new TextButton("moo5", skin));
tree.add(moo1);
tree.add(moo2);
moo2.add(moo3);
moo3.add(moo4);
tree.add(moo5);
moo5.getActor().addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
tree.remove(moo4);
}
});
table.add(tree).fill().expand();
}
Aggregations