Example usage for com.badlogic.gdx.scenes.scene2d Stage setKeyboardFocus

List of usage examples for com.badlogic.gdx.scenes.scene2d Stage setKeyboardFocus

Introduction

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

Prototype

public void setKeyboardFocus(Actor actor) 

Source Link

Document

Sets the actor that will receive key events.

Usage

From source file:com.aia.hichef.ui.n.MyDialog.java

License:Apache License

/** {@link #pack() Packs} the dialog and adds it to the stage, centered. */
public MyDialog show(Stage stage) {
    clearActions();/*  w w w .  j  a  va 2 s  .  co m*/
    removeCaptureListener(ignoreTouchDown);

    previousKeyboardFocus = null;
    Actor actor = stage.getKeyboardFocus();
    if (actor != null && !actor.isDescendantOf(this))
        previousKeyboardFocus = actor;

    previousScrollFocus = null;
    actor = stage.getScrollFocus();
    if (actor != null && !actor.isDescendantOf(this))
        previousScrollFocus = actor;

    pack();
    setPosition(Math.round((stage.getWidth() - getWidth()) / 2),
            Math.round((stage.getHeight() - getHeight()) / 2));
    stage.addActor(this);
    stage.setKeyboardFocus(this);
    stage.setScrollFocus(this);
    if (fadeDuration > 0) {
        getColor().a = 0;
        addAction(Actions.fadeIn(fadeDuration, Interpolation.fade));
    }
    return this;
}

From source file:com.aia.hichef.ui.n.MyDialog.java

License:Apache License

/**
 * Hides the dialog. Called automatically when a button is clicked. The
 * default implementation fades out the dialog over {@link #fadeDuration}
 * seconds and then removes it from the stage.
 *//*w  w w  . java  2 s  .  c om*/
public void hide() {
    Stage stage = getStage();
    if (stage != null) {
        if (previousKeyboardFocus != null && previousKeyboardFocus.getStage() == null)
            previousKeyboardFocus = null;
        Actor actor = stage.getKeyboardFocus();
        if (actor == null || actor.isDescendantOf(this))
            stage.setKeyboardFocus(previousKeyboardFocus);

        if (previousScrollFocus != null && previousScrollFocus.getStage() == null)
            previousScrollFocus = null;
        actor = stage.getScrollFocus();
        if (actor == null || actor.isDescendantOf(this))
            stage.setScrollFocus(previousScrollFocus);
    }
    if (fadeDuration > 0) {
        addCaptureListener(ignoreTouchDown);
        addAction(sequence(fadeOut(fadeDuration, Interpolation.fade),
                Actions.removeListener(ignoreTouchDown, true), Actions.removeActor()));
    } else
        remove();
}

From source file:com.calanti.androidnativekeyboardinputtest.libgdxModified_1_9_3.CalTextField.java

License:Apache License

/** Focuses the next  If none is found, the keyboard is hidden. Does nothing if the text field is not in a stage.
 * @param up If true, the TextField with the same or next smallest y coordinate is found, else the next highest. */
public void next(boolean up) {
    Stage stage = getStage();
    if (stage == null)
        return;/*  ww w . j a  v  a 2  s  . c  o m*/
    getParent().localToStageCoordinates(tmp1.set(getX(), getY()));
    CalTextField textField = findNextTextField(stage.getActors(), null, tmp2, tmp1, up);
    if (textField == null) { // Try to wrap around.
        if (up)
            tmp1.set(Float.MIN_VALUE, Float.MIN_VALUE);
        else
            tmp1.set(Float.MAX_VALUE, Float.MAX_VALUE);
        textField = findNextTextField(getStage().getActors(), null, tmp2, tmp1, up);
    }
    if (textField != null) {
        stage.setKeyboardFocus(textField);
        /** calanti addition - send EditText focus to next */
        if (androidTextInputInterface != null) {
            androidTextInputInterface.requestKeyboard(textField);
        }
    } else {
        /** calanti addition - also tell stage to unfocus */
        if (androidTextInputInterface != null) {
            androidTextInputInterface.forceHideKeyboard();
        } else {
            Gdx.input.setOnscreenKeyboardVisible(false);
        }
        stage.unfocusAll();
    }
}

From source file:com.github.ykrasik.jaci.cli.libgdx.LibGdxCli.java

License:Apache License

private void setKeyboardFocus(TextField commandLine) {
    final Stage stage = getStage();
    if (stage != null) {
        stage.setKeyboardFocus(commandLine);
    }/*from  w ww  .j a va2 s  . c om*/
}

From source file:com.github.ykrasik.jerminal.libgdx.ConsoleBuilder.java

License:Apache License

private LibGdxConsole createConsoleTable(LibGdxTerminal terminal, Label currentPath,
        final TextField commandLine) {
    final LibGdxConsole consoleTable = new LibGdxConsole(skin);
    consoleTable.setName("consoleTable");
    consoleTable.setBackground("consoleBackground");
    consoleTable.addVisibleListener(new VisibleListener() {
        @Override//  www  .j a  v  a  2 s  .c o m
        public void onVisibleChange(boolean wasVisible, boolean isVisible) {
            if (!wasVisible && isVisible) {
                final Stage stage = consoleTable.getStage();
                if (stage != null) {
                    stage.setKeyboardFocus(commandLine);
                }
            }
        }
    });

    // A close console button.
    // TODO: This should be a button, not a text button.
    final Button closeButton = new TextButton("X", skin, "closeConsoleButton");
    closeButton.padRight(15).padLeft(15);
    closeButton.setName("closeButton");
    closeButton.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            consoleTable.setVisible(false);
        }
    });

    // Some layout.

    final Table currentPathTable = new Table(skin);
    currentPathTable.setName("currentPathTable");
    currentPathTable.setBackground("currentPathBackground");
    currentPathTable.add(currentPath).fill().padLeft(3).padRight(5);

    // The bottom row contains the current path, command line and a close button.
    final Table bottomRow = new Table(skin);
    bottomRow.setName("bottomRow");
    bottomRow.setBackground("bottomRowBackground");
    bottomRow.add(currentPathTable).fill();
    bottomRow.add(commandLine).fill().expandX();
    bottomRow.add(closeButton).fill();

    consoleTable.pad(0);
    consoleTable.add(terminal).fill().expand();
    consoleTable.row();
    consoleTable.add(bottomRow).fill();
    consoleTable.top().left();

    return consoleTable;
}

From source file:com.kotcrab.vis.editor.util.scene2d.FocusUtils.java

License:Apache License

public static void focus(Stage stage, Actor target) {
    stage.setKeyboardFocus(target);
    stage.setScrollFocus(target);
}

From source file:com.kotcrab.vis.ui.FocusManager.java

License:Apache License

/**
 * Takes focus from current focused widget (if any), and sets focus to provided widget
 * @param stage if passed stage is not null then stage keyboard focus will be set to null
 * @param widget that will acquire focus
 *//*from   w w w . java  2 s .co m*/
public static void switchFocus(Stage stage, Focusable widget) {
    if (focusedWidget == widget)
        return;
    if (focusedWidget != null)
        focusedWidget.focusLost();
    focusedWidget = widget;
    if (stage != null)
        stage.setKeyboardFocus(null);
    focusedWidget.focusGained();
}

From source file:com.kotcrab.vis.ui.FocusManager.java

License:Apache License

/**
 * Takes focus from current focused widget (if any), and sets current focused widget to null. If widgets owns
 * keyboard focus {@link #resetFocus(Stage, Actor)} should be always preferred.
 * @param stage if passed stage is not null then stage keyboard focus will be set to null
 *//*from w w  w.j a  v a 2  s . c  o m*/
public static void resetFocus(Stage stage) {
    if (focusedWidget != null)
        focusedWidget.focusLost();
    if (stage != null)
        stage.setKeyboardFocus(null);
    focusedWidget = null;
}

From source file:com.kotcrab.vis.ui.FocusManager.java

License:Apache License

/**
 * Takes focus from current focused widget (if any), and sets current focused widget to null
 * @param stage if passed stage is not null then stage keyboard focus will be set to null only if current
 * focus owner is passed actor//  w w w .  j  a  v a2  s.c  o  m
 */
public static void resetFocus(Stage stage, Actor caller) {
    if (focusedWidget != null)
        focusedWidget.focusLost();
    if (stage != null && stage.getKeyboardFocus() == caller)
        stage.setKeyboardFocus(null);
    focusedWidget = null;
}

From source file:com.minikara.ttfinput.TextField.java

License:Apache License

/** Focuses the next TextField. If none is found, the keyboard is hidden. Does nothing if the text field is not in a stage.
 * @param up If true, the TextField with the same or next smallest y coordinate is found, else the next highest. */
public void next(boolean up) {
    Stage stage = getStage();
    if (stage == null)
        return;//from w  ww.  j a  va2 s. c o m
    getParent().localToStageCoordinates(tmp1.set(getX(), getY()));
    TextField textField = findNextTextField(stage.getActors(), null, tmp2, tmp1, up);
    if (textField == null) { // Try to wrap around.
        if (up)
            tmp1.set(Float.MIN_VALUE, Float.MIN_VALUE);
        else
            tmp1.set(Float.MAX_VALUE, Float.MAX_VALUE);
        textField = findNextTextField(getStage().getActors(), null, tmp2, tmp1, up);
    }
    if (textField != null)
        stage.setKeyboardFocus(textField);
    else
        Gdx.input.setOnscreenKeyboardVisible(false);
}