List of usage examples for com.badlogic.gdx.scenes.scene2d Actor getParent
public Group getParent()
From source file:com.agateau.ui.anchor.AnchorGroup.java
License:Apache License
public void addRule(AnchorRule rule) { mRules.add(rule);//from ww w. j a v a2 s . c om Actor target = rule.getTarget(); if (target.getParent() == null) { addActor(target); } }
From source file:com.agateau.ui.menu.MenuItemGroup.java
License:Apache License
private MenuItem getItemAt(float x, float y) { for (MenuItem item : mItems) { if (!isItemVisible(item)) { continue; }//from www .j a va 2 s . co m Actor actor = item.getActor(); // We do not use the item focus rect because it might only represent a part of the item // For example the focus rect of a GridMenuItem is the currently selected cell of the grid mActorRectangle.set(0, 0, actor.getWidth(), actor.getHeight()); for (; actor != mGroup && actor != null; actor = actor.getParent()) { mActorRectangle.x += actor.getX(); mActorRectangle.y += actor.getY(); } if (mActorRectangle.contains(x, y)) { return item; } } return null; }
From source file:com.ahsgaming.valleyofbones.screens.AbstractScreen.java
License:Apache License
public static Vector2 localToGlobal(Vector2 local, Actor actor) { Vector2 coords = new Vector2(local); Actor cur = actor; while (cur.getParent() != null) { coords.add(cur.getX(), cur.getY()); cur = cur.getParent();//w ww . jav a 2s. c o m } return coords; }
From source file:com.aia.hichef.ui.n.MyDialog.java
License:Apache License
private void initialize() { setModal(true);/* ww w .ja v a 2s .com*/ defaults().space(6); add(contentTable = new Table(skin)).expand().fill(); row(); add(buttonTable = new Table(skin)); contentTable.defaults().space(6); buttonTable.defaults().space(6); buttonTable.addListener(new ChangeListener() { public void changed(ChangeEvent event, Actor actor) { if (!values.containsKey(actor)) return; while (actor.getParent() != buttonTable) actor = actor.getParent(); result(values.get(actor)); if (!cancelHide) hide(); cancelHide = false; } }); addListener(new FocusListener() { public void keyboardFocusChanged(FocusEvent event, Actor actor, boolean focused) { if (!focused) focusChanged(event); } public void scrollFocusChanged(FocusEvent event, Actor actor, boolean focused) { if (!focused) focusChanged(event); } private void focusChanged(FocusEvent event) { Stage stage = getStage(); if (isModal() && stage != null && stage.getRoot().getChildren().size > 0 && stage.getRoot().getChildren().peek() == MyDialog.this) { // Dialog // is // top // most // actor. Actor newFocusedActor = event.getRelatedActor(); if (newFocusedActor != null && !newFocusedActor.isDescendantOf(MyDialog.this)) event.cancel(); } } }); }
From source file:com.blastedstudios.gdxworld.util.ui.Scene2DUtils.java
License:Apache License
/** @return the highest parent in the hierarchy tree of the given actor */ public static Group lastParent(Actor actor) { if (!actor.hasParent()) return null; Group parent = actor.getParent(); while (parent.hasParent()) parent = parent.getParent();//w w w .ja v a 2 s .c o m assert !parent.hasParent(); return parent; }
From source file:com.calanti.androidnativekeyboardinputtest.libgdxModified_1_9_3.CalTextField.java
License:Apache License
private CalTextField findNextTextField(Array<Actor> actors, CalTextField best, Vector2 bestCoords, Vector2 currentCoords, boolean up) { for (int i = 0, n = actors.size; i < n; i++) { Actor actor = actors.get(i); if (actor == this) continue; if (actor instanceof CalTextField) { CalTextField textField = (CalTextField) actor; if (textField.isDisabled() || !textField.focusTraversal) continue; Vector2 actorCoords = actor.getParent() .localToStageCoordinates(tmp3.set(actor.getX(), actor.getY())); if ((actorCoords.y < currentCoords.y || (actorCoords.y == currentCoords.y && actorCoords.x > currentCoords.x)) ^ up) { if (best == null || (actorCoords.y > bestCoords.y || (actorCoords.y == bestCoords.y && actorCoords.x < bestCoords.x)) ^ up) { best = (CalTextField) actor; bestCoords.set(actorCoords); }/*from ww w . ja v a2s . c om*/ } } else if (actor instanceof Group) best = findNextTextField(((Group) actor).getChildren(), best, bestCoords, currentCoords, up); } return best; }
From source file:com.coder5560.game.ui.MyDialog.java
License:Apache License
private void initialize() { setModal(true);// www . j a va 2 s . co m back2 = new Image(new NinePatchDrawable( new NinePatch(new NinePatch(Assets.instance.getRegion("ninepatch2"), 4, 4, 4, 4), new Color(240 / 255f, 240 / 255f, 240 / 255f, 1)))); addActor(back2); defaults().space(6); add(contentTable = new Table(skin)).expand().fill(); row(); add(buttonTable = new Table(skin)); contentTable.defaults().space(6); buttonTable.defaults().space(6); buttonTable.addListener(new ChangeListener() { public void changed(ChangeEvent event, Actor actor) { if (!values.containsKey(actor)) return; while (actor.getParent() != buttonTable) actor = actor.getParent(); result(values.get(actor)); if (!cancelHide) hide(); cancelHide = false; } }); addListener(new FocusListener() { public void keyboardFocusChanged(FocusEvent event, Actor actor, boolean focused) { if (!focused) focusChanged(event); } public void scrollFocusChanged(FocusEvent event, Actor actor, boolean focused) { if (!focused) focusChanged(event); } private void focusChanged(FocusEvent event) { Stage stage = getStage(); if (isModal() && stage != null && stage.getRoot().getChildren().size > 0 && stage.getRoot().getChildren().peek() == MyDialog.this) { // Dialog // is // top // most // actor. Actor newFocusedActor = event.getRelatedActor(); if (newFocusedActor != null && !newFocusedActor.isDescendantOf(MyDialog.this)) event.cancel(); } } }); }
From source file:com.gdx.extension.ui.menu.MenuBar.java
License:Apache License
/** * Add a {@link ContextMenu context menu}. * //from www . j av a 2 s . c o m * @param actor the button that will open the {@link ContextMenu context menu} * @param menu the {@link ContextMenu context menu} to add * @param stage the stage where to display the {@link ContextMenu context menu} * * @return the {@link Cell cell} where the button opening the {@link ContextMenu context menu} was added */ public Cell<?> addContextMenu(final Button actor, final ContextMenu menu, final Stage stage) { stage.addActor(menu); menuBind.put(actor, menu); if (!isInitialized) { isInitialized = true; stage.addListener(new InputListener() { @Override public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { Actor _target = event.getTarget(); if (_target instanceof ContextMenu || _target instanceof SubMenuItem) return false; else if (_target instanceof Label) { Actor _parent = _target.getParent(); if (_parent instanceof TextButton) { if (menuBind.containsKey(_parent)) return true; } else if (_parent instanceof SubMenuItem) return true; } closeMenu(); isOpen = false; return true; } }); } actor.addListener(new InputListener() { @Override public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { if (button != Buttons.LEFT) return false; closeMenu(); lastOpened = menu; isOpen = !isOpen; return true; } @Override public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) { if (!isOpen) return; closeMenu(); lastOpened = menu; menu.setVisible(true); actor.localToStageCoordinates(temp); menu.setPosition(temp.x, temp.y); temp.set(0f, 0f); } }); return super.add(actor).minWidth(actor.getWidth()); }
From source file:com.kotcrab.vis.ui.util.ActorUtils.java
License:Apache License
/** * Makes sures that actor will be fully visible in stage. If it's necessary actor position will be changed to fit it * on screen./*from ww w .j ava 2 s . c o m*/ */ public static void keepWithinStage(Stage stage, Actor actor) { //taken from scene2d.ui Window Camera camera = stage.getCamera(); if (camera instanceof OrthographicCamera) { OrthographicCamera orthographicCamera = (OrthographicCamera) camera; float parentWidth = stage.getWidth(); float parentHeight = stage.getHeight(); if (actor.getX(Align.right) - camera.position.x > parentWidth / 2 / orthographicCamera.zoom) actor.setPosition(camera.position.x + parentWidth / 2 / orthographicCamera.zoom, actor.getY(Align.right), Align.right); if (actor.getX(Align.left) - camera.position.x < -parentWidth / 2 / orthographicCamera.zoom) actor.setPosition(camera.position.x - parentWidth / 2 / orthographicCamera.zoom, actor.getY(Align.left), Align.left); if (actor.getY(Align.top) - camera.position.y > parentHeight / 2 / orthographicCamera.zoom) actor.setPosition(actor.getX(Align.top), camera.position.y + parentHeight / 2 / orthographicCamera.zoom, Align.top); if (actor.getY(Align.bottom) - camera.position.y < -parentHeight / 2 / orthographicCamera.zoom) actor.setPosition(actor.getX(Align.bottom), camera.position.y - parentHeight / 2 / orthographicCamera.zoom, Align.bottom); } else if (actor.getParent() == stage.getRoot()) { float parentWidth = stage.getWidth(); float parentHeight = stage.getHeight(); if (actor.getX() < 0) actor.setX(0); if (actor.getRight() > parentWidth) actor.setX(parentWidth - actor.getWidth()); if (actor.getY() < 0) actor.setY(0); if (actor.getTop() > parentHeight) actor.setY(parentHeight - actor.getHeight()); } }
From source file:com.minikara.ttfinput.TextField.java
License:Apache License
private TextField findNextTextField(Array<Actor> actors, TextField best, Vector2 bestCoords, Vector2 currentCoords, boolean up) { for (int i = 0, n = actors.size; i < n; i++) { Actor actor = actors.get(i); if (actor == this) continue; if (actor instanceof TextField) { TextField textField = (TextField) actor; if (textField.isDisabled() || !textField.focusTraversal) continue; Vector2 actorCoords = actor.getParent() .localToStageCoordinates(tmp3.set(actor.getX(), actor.getY())); if ((actorCoords.y < currentCoords.y || (actorCoords.y == currentCoords.y && actorCoords.x > currentCoords.x)) ^ up) { if (best == null || (actorCoords.y > bestCoords.y || (actorCoords.y == bestCoords.y && actorCoords.x < bestCoords.x)) ^ up) { best = (TextField) actor; bestCoords.set(actorCoords); }/*from w ww . j a v a2 s. c om*/ } } else if (actor instanceof Group) best = findNextTextField(((Group) actor).getChildren(), best, bestCoords, currentCoords, up); } return best; }