public void render () { Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); stage.draw(); // check how many actors are visible. Array<Actor> actors = stage.getActors(); int numVisible = 0; for (int i = 0; i < actors.size; i++) { numVisible += ((CullableActor)actors.get(i)).visible ? 1 : 0; } batch.begin(); font.draw(batch, "Visible: " + numVisible + ", fps: " + Gdx.graphics.getFramesPerSecond(), 20, 30); batch.end(); }
/** 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); } }
/** 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); } }
Array<Actor> actors = stage.getActors(); int len = actors.size; if (rotateSprites) {
/** * Removes every instance of {@link PopupMenu} form {@link Stage} actors. * <p> * Generally called from {@link ApplicationListener#resize(int, int)} to remove menus on resize event. */ public static void removeEveryMenu (Stage stage) { for (Actor actor : stage.getActors()) { if (actor instanceof PopupMenu) { PopupMenu menu = (PopupMenu) actor; menu.removeHierarchy(); } } }
/** * Removes every instance of {@link ContextMenu} form {@link Stage} actors. * <p> * Generally called from {@link ApplicationListener#resize(int, int)} to remove menus on resize event. */ public static void removeAll(Stage stage) { for (Actor actor : stage.getActors()) { if (actor instanceof ContextMenu) { ContextMenu menu = (ContextMenu) actor; menu.removeHierarchy(); } } }
public void display() { if (!stage.getActors().contains(me, true)) stage.addActor(me); }
public void display() { if (!stage.getActors().contains(me, true)) stage.addActor(me); }
@SuppressWarnings("rawtypes") public GdxQuery add(Object... a) { for (Object obj: a) if(obj instanceof TypedGdxQuery) list().add(((TypedGdxQuery)obj).get()); else if(obj instanceof Actor) list().add((Actor)obj); else if(obj instanceof Cell<?>) list().add(((Cell<?>)obj).getActor()); // else if(obj instanceof ButtonGroup) // for(Button button:((ButtonGroup)obj).getButtons()) // getItems().add(button); else if(obj instanceof Stage) for(Actor actor:((Stage)obj).getActors()) list().add(actor); else if(obj instanceof GdxQuery) list().addAll(((GdxQuery)obj).list()); else if(obj instanceof Collection) for(Object col:(Collection<?>)obj) add(col); else if(obj instanceof Array) for(Object col:(Array<?>)obj) add(col); return this; }
@Override public boolean keyDown (InputEvent event, int keycode) { if (keycode == Keys.F12) { debug = !debug; root.setDebug(debug, true); for (Actor actor : stage.getActors()) { if (actor instanceof Group) { Group group = (Group) actor; group.setDebug(debug, true); } } return true; } return false; } });
public void detach() { dialogWindow = createWindow(labelText, content, skin, stage, lastx, lasty); // Display if (!stage.getActors().contains(dialogWindow, true)) stage.addActor(dialogWindow); expandIcon.setChecked(false); expandIcon.setDisabled(true); detachIcon.setDisabled(true); }
public void display() { if (!gui.getGuiStage().getActors().contains(me, true)) gui.getGuiStage().addActor(this); gui.getGuiStage().setKeyboardFocus(searchInput); } }
public static void setConsole(Console console) { EditorLogger.console = console; EditorLogger.console.setDisplayKeyID(Keys.F1); console.setMaxEntries(1000); final Stage s = (Stage) console.getInputProcessor(); final Actor actor = s.getActors().items[0]; actor.addListener(new InputListener() { @Override public void exit(InputEvent event, float x, float y, int pointer, Actor toActor) { if (toActor == null) { s.setScrollFocus(null); } } }); console.setCommandExecutor(new EditorCommandExecutor()); } }
private static void add(Stage stage, String text) { msg.clearActions(); msg.setText(text); GlyphLayout textLayout = new GlyphLayout(); textLayout.setText(msg.getStyle().font, text, Color.BLACK, stage.getWidth() * .8f, Align.center, true); msg.setSize(textLayout.width + textLayout.height, textLayout.height + textLayout.height * 2); if (!stage.getActors().contains(msg, true)) stage.addActor(msg); msg.setPosition(Math.round((stage.getWidth() - msg.getWidth()) / 2), Math.round((stage.getHeight() - msg.getHeight()) / 2)); msg.invalidate(); }
/** * 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; getParent().localToStageCoordinates(tmp1.set(getX(), getY())); VisTextField 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) { textField.focusField(); textField.setCursorPosition(textField.getText().length()); } else Gdx.input.setOnscreenKeyboardVisible(false); }
/** 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; 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); }
/** 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); } }
@Override public void resize (int width, int height) { if (width == 0 && height == 0) return; //see https://github.com/libgdx/libgdx/issues/3673#issuecomment-177606278 stage.getViewport().update(width, height, true); PopupMenu.removeEveryMenu(stage); WindowResizeEvent resizeEvent = new WindowResizeEvent(); for (Actor actor : stage.getActors()) { actor.fire(resizeEvent); } }