Example usage for com.badlogic.gdx.scenes.scene2d InputEvent InputEvent

List of usage examples for com.badlogic.gdx.scenes.scene2d InputEvent InputEvent

Introduction

In this page you can find the example usage for com.badlogic.gdx.scenes.scene2d InputEvent InputEvent.

Prototype

InputEvent

Source Link

Usage

From source file:com.gmail.bleedobsidian.logicbuilder.utils.InvisibleButton.java

License:Open Source License

@Override
public void update(float delta) {
    if (Gdx.app.getInput().isTouched() && this.isVisible) {
        Vector3 touchLocation = this.camera
                .unproject(new Vector3(Gdx.app.getInput().getX(), Gdx.app.getInput().getY(), 0));

        if (touchLocation.x >= this.locationX && touchLocation.x <= this.locationX + this.sizeX) {
            if (touchLocation.y >= this.locationY && touchLocation.y <= this.locationY + this.sizeY) {
                if (!this.isTouched & this.clickListener != null) {
                    this.clickListener.clicked(new InputEvent(), touchLocation.x, touchLocation.y);
                    this.isTouched = true;
                }//from   www  .  ja  v a2 s .  com
            } else {
                if (this.isTouched == true) {
                    this.isTouched = false;
                }
            }
        } else {
            if (this.isTouched == true) {
                this.isTouched = false;
            }
        }
    } else {
        this.isTouched = false;
    }
}

From source file:headmade.arttag.screens.MenuScreen.java

License:Apache License

public MenuScreen(DirectedGame game) {
    super(game);// w  ww  .j  av  a  2 s.  c  o m

    // FlickrService.instance.getPhotos(1, 1);
    Player.instance.init();

    jiggleAction = ActionFactory.wiggleRepeat(1f, 0.8f);

    final Table rootTable = new Table();
    rootTable.setFillParent(true);

    howTo = new HowToActor(game);
    credits = new CreditsActor();
    final Actor artTreachery = new Image(Assets.instance.skin.getRegion(AssetTextures.artTreachery));

    credits.getColor().a = 0f;

    final Stack mainContainer = new Stack();
    mainContainer.add(howTo);
    mainContainer.add(credits);

    rootTable.add(artTreachery).colspan(2).padTop(20f).row();
    rootTable.add(mainContainer).expand();// .fill(1f, 1f);
    rootTable.add(buildMenu()).expandY().center().padRight(20f);
    rootTable.row();
    // rootTable.setDebug(true);

    this.stage.addActor(rootTable);

    stage.addListener(new InputListener() {

        @Override
        public boolean keyDown(InputEvent event, int keycode) {
            if (keycode == Keys.ESCAPE) {
                Gdx.app.exit();
                return true;
            } else if (keycode == Keys.LEFT || keycode == Keys.A) {
                activatePrevButton();
                return true;
            } else if (keycode == Keys.RIGHT || keycode == Keys.D) {
                activateNextButton();
                return true;
            } else if (keycode == Keys.UP || keycode == Keys.W) {
                activatePrevButton();
                return true;
            } else if (keycode == Keys.DOWN || keycode == Keys.S) {
                activateNextButton();
                return true;
            } else if (keycode == Keys.ALT_LEFT || keycode == Keys.ALT_RIGHT || keycode == Keys.Z
                    || keycode == Keys.SPACE) {
                // action button 1
                useActiveButton();
                return true;
            } else if (keycode == Keys.CONTROL_LEFT || keycode == Keys.CONTROL_RIGHT || keycode == Keys.X
                    || keycode == Keys.SHIFT_LEFT || keycode == Keys.SHIFT_RIGHT) {
                // action button 2
                useActiveButton();
                return true;
            }
            return super.keyDown(event, keycode);
        }

        private void useActiveButton() {
            final InputEvent event = new InputEvent();
            event.setPointer(0);
            event.setType(Type.touchDown);
            buttons.get(activeButtonIndex).fire(event);
        }

        private void activatePrevButton() {
            InputEvent event = new InputEvent();
            event.setPointer(-1);
            event.setType(Type.exit);
            buttons.get(activeButtonIndex).fire(event);

            buttons.get(activeButtonIndex).removeAction(jiggleAction);
            if (activeButtonIndex == 0) {
                activeButtonIndex = buttons.size - 1;
            } else {
                activeButtonIndex--;
            }
            jiggleAction = ActionFactory.wiggleRepeat(1f, 0.8f);
            buttons.get(activeButtonIndex).addAction(jiggleAction);

            event = new InputEvent();
            event.setPointer(-1);
            event.setType(Type.enter);
            buttons.get(activeButtonIndex).fire(event);
        }

        private void activateNextButton() {
            InputEvent event = new InputEvent();
            event.setPointer(-1);
            event.setType(Type.exit);
            buttons.get(activeButtonIndex).fire(event);

            buttons.get(activeButtonIndex).removeAction(jiggleAction);
            if (activeButtonIndex == buttons.size - 1) {
                activeButtonIndex = 0;
            } else {
                activeButtonIndex++;
            }
            jiggleAction = ActionFactory.wiggleRepeat(1f, 0.8f);
            buttons.get(activeButtonIndex).addAction(jiggleAction);

            event = new InputEvent();
            event.setPointer(-1);
            event.setType(Type.enter);
            buttons.get(activeButtonIndex).fire(event);
        }

    });

    // ((OrthographicCamera) stage.getCamera()).zoom = 0.5f;
}