Example #1
0
  /**
   * {@link #pack() Packs} the dialog and adds it to the stage with custom action which can be null
   * for instant show
   */
  public Dialog show(Stage stage, Action action) {
    clearActions();
    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();
    stage.addActor(this);
    stage.setKeyboardFocus(this);
    stage.setScrollFocus(this);
    if (action != null) addAction(action);

    return this;
  }
Example #2
0
  /**
   * @return Returns a direct child of parent in the hierarchy of the given actor. Null if actor is
   *     not a descendant of parent
   */
  public static Actor getDirectChild(Group parent, Actor actor) {
    if (actor == null || !actor.isDescendantOf(parent)) {
      return null;
    }

    Actor firstChild = actor;
    while (firstChild != null && firstChild.getParent() != parent) {
      firstChild = firstChild.getParent();
    }
    return firstChild;
  }
Example #3
0
  /** Hides the dialog with the given action and then removes it from the stage. */
  public void hide(Action action) {
    Stage stage = getStage();
    if (stage != null) {
      removeListener(focusListener);
      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 (action != null) {
      addCaptureListener(ignoreTouchDown);
      addAction(
          sequence(action, Actions.removeListener(ignoreTouchDown, true), Actions.removeActor()));
    } else remove();
  }
Example #4
0
 /** Removes the touch, keyboard, and scroll focus for the specified actor and any descendants. */
 public void unfocus(Actor actor) {
   cancelTouchFocus(actor);
   if (scrollFocus != null && scrollFocus.isDescendantOf(actor)) scrollFocus = null;
   if (keyboardFocus != null && keyboardFocus.isDescendantOf(actor)) keyboardFocus = null;
 }