com.badlogic.gdx.scenes.scene2d.Stage.setKeyboardFocus()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(10.2k)|赞(0)|评价(0)|浏览(134)

本文整理了Java中com.badlogic.gdx.scenes.scene2d.Stage.setKeyboardFocus()方法的一些代码示例,展示了Stage.setKeyboardFocus()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Stage.setKeyboardFocus()方法的具体详情如下:
包路径:com.badlogic.gdx.scenes.scene2d.Stage
类名称:Stage
方法名:setKeyboardFocus

Stage.setKeyboardFocus介绍

[英]Sets the actor that will receive key events.
[中]设置将接收关键事件的参与者。

代码示例

代码示例来源:origin: libgdx/libgdx

/** Removes the touch, keyboard, and scroll focused actors. */
public void unfocusAll () {
  setScrollFocus(null);
  setKeyboardFocus(null);
  cancelTouchFocus();
}

代码示例来源:origin: libgdx/libgdx

/** Removes the touch, keyboard, and scroll focused actors. */
public void unfocusAll () {
  setScrollFocus(null);
  setKeyboardFocus(null);
  cancelTouchFocus();
}

代码示例来源:origin: libgdx/libgdx

public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
  if (!super.touchDown(event, x, y, pointer, button)) return false;
  if (pointer == 0 && button != 0) return false;
  if (disabled) return true;
  setCursorPosition(x, y);
  selectionStart = cursor;
  Stage stage = getStage();
  if (stage != null) stage.setKeyboardFocus(TextField.this);
  keyboard.show(true);
  hasSelection = true;
  return true;
}

代码示例来源:origin: libgdx/libgdx

/** 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)) setScrollFocus(null);
  if (keyboardFocus != null && keyboardFocus.isDescendantOf(actor)) setKeyboardFocus(null);
}

代码示例来源:origin: libgdx/libgdx

public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
  if (!super.touchDown(event, x, y, pointer, button)) return false;
  if (pointer == 0 && button != 0) return false;
  if (disabled) return true;
  setCursorPosition(x, y);
  selectionStart = cursor;
  Stage stage = getStage();
  if (stage != null) stage.setKeyboardFocus(TextField.this);
  keyboard.show(true);
  hasSelection = true;
  return true;
}

代码示例来源:origin: libgdx/libgdx

/** 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)) setScrollFocus(null);
  if (keyboardFocus != null && keyboardFocus.isDescendantOf(actor)) setKeyboardFocus(null);
}

代码示例来源:origin: libgdx/libgdx

public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
  if (pointer != 0 || button != 0) return true;
  if (selection.isDisabled()) return true;
  getStage().setKeyboardFocus(List.this);
  if (items.size == 0) return true;
  int index = getItemIndexAt(y);
  if (index == -1) return true;
  selection.choose(items.get(index));
  touchDown = index;
  return true;
}

代码示例来源:origin: libgdx/libgdx

public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
  if (pointer != 0 || button != 0) return true;
  if (selection.isDisabled()) return true;
  getStage().setKeyboardFocus(List.this);
  if (items.size == 0) return true;
  int index = getItemIndexAt(y);
  if (index == -1) return true;
  selection.choose(items.get(index));
  touchDown = index;
  return true;
}

代码示例来源:origin: libgdx/libgdx

/** {@link #pack() Packs} the dialog (but doesn't set the position), adds it to the stage, sets it as the keyboard and scroll
 * focus, clears any actions on the dialog, and adds the specified action to it. The previous keyboard and scroll focus are
 * remembered so they can be restored when the dialog is hidden.
 * @param action May be null. */
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.cancelTouchFocus();
  stage.setKeyboardFocus(this);
  stage.setScrollFocus(this);
  if (action != null) addAction(action);
  return this;
}

代码示例来源:origin: libgdx/libgdx

/** {@link #pack() Packs} the dialog (but doesn't set the position), adds it to the stage, sets it as the keyboard and scroll
 * focus, clears any actions on the dialog, and adds the specified action to it. The previous keyboard and scroll focus are
 * remembered so they can be restored when the dialog is hidden.
 * @param action May be null. */
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.cancelTouchFocus();
  stage.setKeyboardFocus(this);
  stage.setScrollFocus(this);
  if (action != null) addAction(action);
  return this;
}

代码示例来源:origin: libgdx/libgdx

public void draw (Batch batch, float parentAlpha) {
  Stage stage = getStage();
  if (stage.getKeyboardFocus() == null) stage.setKeyboardFocus(this);
  keepWithinStage();
  if (style.stageBackground != null) {
    stageToLocalCoordinates(tmpPosition.set(0, 0));
    stageToLocalCoordinates(tmpSize.set(stage.getWidth(), stage.getHeight()));
    drawStageBackground(batch, parentAlpha, getX() + tmpPosition.x, getY() + tmpPosition.y, getX() + tmpSize.x,
      getY() + tmpSize.y);
  }
  super.draw(batch, parentAlpha);
}

代码示例来源:origin: libgdx/libgdx

public void draw (Batch batch, float parentAlpha) {
  Stage stage = getStage();
  if (stage.getKeyboardFocus() == null) stage.setKeyboardFocus(this);
  keepWithinStage();
  if (style.stageBackground != null) {
    stageToLocalCoordinates(tmpPosition.set(0, 0));
    stageToLocalCoordinates(tmpSize.set(stage.getWidth(), stage.getHeight()));
    drawStageBackground(batch, parentAlpha, getX() + tmpPosition.x, getY() + tmpPosition.y, getX() + tmpSize.x,
      getY() + tmpSize.y);
  }
  super.draw(batch, parentAlpha);
}

代码示例来源:origin: libgdx/libgdx

/** Removes the dialog from the stage, restoring the previous keyboard and scroll focus, and adds the specified action to the
 * dialog.
 * @param action If null, the dialog is removed immediately. Otherwise, the dialog is removed when the action completes. The
 *           dialog will not respond to touch down events during the action. */
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();
}

代码示例来源:origin: libgdx/libgdx

/** Removes the dialog from the stage, restoring the previous keyboard and scroll focus, and adds the specified action to the
 * dialog.
 * @param action If null, the dialog is removed immediately. Otherwise, the dialog is removed when the action completes. The
 *           dialog will not respond to touch down events during the action. */
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();
}

代码示例来源:origin: libgdx/libgdx

return true;
case Keys.ESCAPE:
  getStage().setKeyboardFocus(null);
  return true;

代码示例来源:origin: libgdx/libgdx

/** 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;
  TextField current = this;
  Vector2 currentCoords = current.getParent().localToStageCoordinates(tmp2.set(current.getX(), current.getY()));
  Vector2 bestCoords = tmp1;
  while (true) {
    TextField textField = current.findNextTextField(stage.getActors(), null, bestCoords, currentCoords, up);
    if (textField == null) { // Try to wrap around.
      if (up)
        currentCoords.set(Float.MIN_VALUE, Float.MIN_VALUE);
      else
        currentCoords.set(Float.MAX_VALUE, Float.MAX_VALUE);
      textField = current.findNextTextField(stage.getActors(), null, bestCoords, currentCoords, up);
    }
    if (textField == null) {
      Gdx.input.setOnscreenKeyboardVisible(false);
      break;
    }
    if (stage.setKeyboardFocus(textField)) {
      textField.selectAll();
      break;
    }
    current = textField;
    currentCoords.set(bestCoords);
  }
}

代码示例来源:origin: libgdx/libgdx

/** 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;
  TextField current = this;
  Vector2 currentCoords = current.getParent().localToStageCoordinates(tmp2.set(current.getX(), current.getY()));
  Vector2 bestCoords = tmp1;
  while (true) {
    TextField textField = current.findNextTextField(stage.getActors(), null, bestCoords, currentCoords, up);
    if (textField == null) { // Try to wrap around.
      if (up)
        currentCoords.set(Float.MIN_VALUE, Float.MIN_VALUE);
      else
        currentCoords.set(Float.MAX_VALUE, Float.MAX_VALUE);
      textField = current.findNextTextField(stage.getActors(), null, bestCoords, currentCoords, up);
    }
    if (textField == null) {
      Gdx.input.setOnscreenKeyboardVisible(false);
      break;
    }
    if (stage.setKeyboardFocus(textField)) {
      textField.selectAll();
      break;
    }
    current = textField;
    currentCoords.set(bestCoords);
  }
}

代码示例来源:origin: libgdx/libgdx

return true;
case Keys.ESCAPE:
  getStage().setKeyboardFocus(null);
  return true;

代码示例来源:origin: kotcrab/vis-ui

@Override
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
  FocusManager.switchFocus(getChooserStage(), FileItem.this);
  getChooserStage().setKeyboardFocus(FileItem.this);
  return true;
}

代码示例来源:origin: kotcrab/vis-ui

@Override
protected void setStage (Stage stage) {
  super.setStage(stage);
  if (stage != null) {
    stage.setKeyboardFocus(this); //issue #10, newly created window does not acquire keyboard focus
    if (centerOnAdd) {
      centerOnAdd = false;
      moveToCenter();
    }
  }
}

相关文章