use of com.badlogic.gdx.scenes.scene2d.InputListener 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.InputListener in project libgdx by libgdx.
the class TableLayoutTest method create.
public void create() {
stage = new Stage();
Gdx.input.setInputProcessor(stage);
Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));
Label nameLabel = new Label("Name:", skin);
TextField nameText = new TextField("", skin);
Label addressLabel = new Label("Address:", skin);
TextField addressText = new TextField("", skin);
Table table = new Table();
stage.addActor(table);
table.setSize(260, 195);
table.setPosition(190, 142);
// table.align(Align.right | Align.bottom);
table.debug();
TextureRegion upRegion = skin.getRegion("default-slider-knob");
TextureRegion downRegion = skin.getRegion("default-slider-knob");
BitmapFont buttonFont = skin.getFont("default-font");
TextButton button = new TextButton("Button 1", skin);
button.addListener(new InputListener() {
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
System.out.println("touchDown 1");
return false;
}
});
table.add(button);
// table.setTouchable(Touchable.disabled);
Table table2 = new Table();
stage.addActor(table2);
table2.setFillParent(true);
table2.bottom();
TextButton button2 = new TextButton("Button 2", skin);
button2.addListener(new ChangeListener() {
public void changed(ChangeEvent event, Actor actor) {
System.out.println("2!");
}
});
button2.addListener(new InputListener() {
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
System.out.println("touchDown 2");
return false;
}
});
table2.add(button2);
}
use of com.badlogic.gdx.scenes.scene2d.InputListener in project Catacomb-Snatch by Catacomb-Snatch.
the class Scene method tick.
@Override
public void tick(float delta) {
// Draw background
if (drawBackground && background != null) {
getBatch().begin();
getBatch().setColor(backgroundColor);
getBatch().draw(background, 0, 0, Screen.getWidth(), Screen.getHeight());
getBatch().end();
}
// Updating mouse dependent stuff in render()
if (!Gdx.input.isTouched()) {
mousePos = screenToStageCoordinates(mousePos.set(Gdx.input.getX(), Gdx.input.getY()));
for (Actor a : getActors()) {
currentActorRect.set(a.getX(), a.getY(), a.getWidth(), a.getHeight());
for (EventListener el : a.getListeners()) {
if (!(el instanceof InputListener))
continue;
InputListener il = (InputListener) el;
if (currentActorRect.contains(mousePos.x, mousePos.y)) {
il.enter(null, mousePos.x, mousePos.y, -1, null);
} else {
il.exit(null, mousePos.x, mousePos.y, -1, null);
}
}
}
}
super.draw();
getBatch().begin();
}
Aggregations