Search in sources :

Example 6 with InputListener

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();
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Slider(com.badlogic.gdx.scenes.scene2d.ui.Slider) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) InputListener(com.badlogic.gdx.scenes.scene2d.InputListener) ScrollPane(com.badlogic.gdx.scenes.scene2d.ui.ScrollPane) Actor(com.badlogic.gdx.scenes.scene2d.Actor) Stage(com.badlogic.gdx.scenes.scene2d.Stage) TextButtonStyle(com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Example 7 with InputListener

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);
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) InputListener(com.badlogic.gdx.scenes.scene2d.InputListener) Actor(com.badlogic.gdx.scenes.scene2d.Actor) Stage(com.badlogic.gdx.scenes.scene2d.Stage) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont)

Example 8 with InputListener

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();
}
Also used : InputListener(com.badlogic.gdx.scenes.scene2d.InputListener) Actor(com.badlogic.gdx.scenes.scene2d.Actor) EventListener(com.badlogic.gdx.scenes.scene2d.EventListener)

Aggregations

InputListener (com.badlogic.gdx.scenes.scene2d.InputListener)8 Actor (com.badlogic.gdx.scenes.scene2d.Actor)7 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)7 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)6 Stage (com.badlogic.gdx.scenes.scene2d.Stage)5 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)5 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)4 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)4 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)4 Texture (com.badlogic.gdx.graphics.Texture)3 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)3 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)2 Dialog (com.badlogic.gdx.scenes.scene2d.ui.Dialog)2 Image (com.badlogic.gdx.scenes.scene2d.ui.Image)2 ScrollPane (com.badlogic.gdx.scenes.scene2d.ui.ScrollPane)2 TextButtonStyle (com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle)2 TextField (com.badlogic.gdx.scenes.scene2d.ui.TextField)2 Color (com.badlogic.gdx.graphics.Color)1 Batch (com.badlogic.gdx.graphics.g2d.Batch)1 ShapeRenderer (com.badlogic.gdx.graphics.glutils.ShapeRenderer)1