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

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

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

Stage.getKeyboardFocus介绍

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

代码示例

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

/** Returns true if this actor is the {@link Stage#getKeyboardFocus() keyboard focus} actor. */
public boolean hasKeyboardFocus () {
  Stage stage = getStage();
  return stage != null && stage.getKeyboardFocus() == this;
}

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

/** Returns true if this actor is the {@link Stage#getKeyboardFocus() keyboard focus} actor. */
public boolean hasKeyboardFocus () {
  Stage stage = getStage();
  return stage != null && stage.getKeyboardFocus() == 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

/** {@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: kotcrab/vis-ui

@Override
public boolean keyDown (InputEvent event, int keycode) {
  if (keycode == Keys.A && UIUtils.ctrl() && getChooserStage().getKeyboardFocus() instanceof VisTextField == false) {
    selectAll();
    return true;
  }
  return false;
}

代码示例来源:origin: com.badlogicgames.gdx/gdx

private Drawable getBackgroundDrawable () {
  Stage stage = getStage();
  boolean focused = stage != null && stage.getKeyboardFocus() == this;
  return (disabled && style.disabledBackground != null) ? style.disabledBackground
    : ((focused && style.focusedBackground != null) ? style.focusedBackground : style.background);
}

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

@Override
  public boolean keyTyped (InputEvent event, char character) {
    if (getChooserStage().getKeyboardFocus() instanceof VisTextField) return false;
    if (Character.isLetterOrDigit(character) == false) return false;
    String name = String.valueOf(character);
    for (FileHandle file : currentFiles) {
      if (file.name().toLowerCase().startsWith(name)) {
        deselectAll();
        highlightFiles(file);
        return true;
      }
    }
    return false;
  }
});

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

/**
 * 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
 */
public static void resetFocus (Stage stage, Actor caller) {
  if (focusedWidget != null) focusedWidget.focusLost();
  if (stage != null && stage.getKeyboardFocus() == caller) stage.setKeyboardFocus(null);
  focusedWidget = null;
}

代码示例来源:origin: langurmonkey/gaiasky

@Override
public boolean cancelTouchFocus() {
  if (ui.getKeyboardFocus() != null || ui.getScrollFocus() != null) {
    ui.setScrollFocus(null);
    ui.setKeyboardFocus(null);
    return true;
  }
  return false;
}

代码示例来源:origin: langurmonkey/gaiasky

@Override
public boolean cancelTouchFocus() {
  if (ui.getKeyboardFocus() != null || ui.getScrollFocus() != null) {
    ui.setScrollFocus(null);
    ui.setKeyboardFocus(null);
    return true;
  }
  return false;
}

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

private void updateSelectedFileFieldText (boolean ignoreKeyboardFocus) {
  if (ignoreKeyboardFocus == false && getChooserStage() != null) {
    if (getChooserStage().getKeyboardFocus() == selectedFileTextField) return;
  }
  if (selectedItems.size == 0) {
    selectedFileTextField.setText("");
  } else if (selectedItems.size == 1) {
    selectedFileTextField.setText(selectedItems.get(0).getFile().name());
  } else {
    StringBuilder builder = new StringBuilder();
    for (FileItem item : selectedItems) {
      builder.append('"');
      builder.append(item.file.name());
      builder.append("\" ");
    }
    selectedFileTextField.setText(builder.toString());
  }
  selectedFileTextField.setCursorAtTextEnd();
}

代码示例来源:origin: manuelbua/uracer-kotd

/** {@link #pack() Packs} the dialog and adds it to the stage, centered. */
public Dialog show (Stage stage) {
  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();
  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;
}

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

/** {@link #pack() Packs} the dialog and adds it to the stage with custom action which can be null for instant show */
public VisDialog 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;
}

代码示例来源:origin: com.badlogicgames.gdx/gdx

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: com.github.xaguzman/gamedevlib-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: kotcrab/vis-ui

/** 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();
}

相关文章