/** * Converts coordinates for this actor to those of a parent actor. The ascendant does not need to * be a direct parent. */ public Vector2 localToAscendantCoordinates(Actor ascendant, Vector2 localCoords) { Actor actor = this; while (actor.getParent() != null) { actor.localToParentCoordinates(localCoords); actor = actor.getParent(); if (actor == ascendant) break; } return localCoords; }
/** * @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; }
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); } } } else if (actor instanceof Group) best = findNextTextField(((Group) actor).getChildren(), best, bestCoords, currentCoords, up); } return best; }
/** @return the nearest entity associated to the given actor */ public static EngineEntity getActorEntity(Actor actor) { if (actor == null) { return null; } Object o = actor.getUserObject(); return o instanceof EngineEntity ? (EngineEntity) o : getActorEntity(actor.getParent()); }
/** Returns true if this actor is the same as or is the ascendant of the specified actor. */ public boolean isAscendantOf(Actor actor) { if (actor == null) throw new IllegalArgumentException("actor cannot be null."); while (true) { if (actor == null) return false; if (actor == this) return true; actor = actor.getParent(); } }
/** * @param fromActor might be in a drag pane. * @return drag pane parent or null. */ protected DragPane getDragPane(Actor fromActor) { while (fromActor != null) { if (fromActor instanceof DragPane) { return (DragPane) fromActor; } fromActor = fromActor.getParent(); } return null; }
/** * @param actor if in the drag pane, but does not have to be added directly. * @param dragPane contains the actor. * @return passed actor or the parent of the actor added directly to the pane. */ protected Actor getActorInDragPane(Actor actor, final DragPane dragPane) { while (actor != dragPane && actor != null) { if (dragPane.contains(actor)) { return actor; } // Actor might not be added directly to the drag pane. Trying out the parent: actor = actor.getParent(); } return null; }
/** * Updates transformation of the represented actor to match the selection ghost transformation */ private void updateTransformation() { Actor parent = representedActor.getParent(); this.localToAscendantCoordinates(parent, tmp1.set(0, 0)); this.localToAscendantCoordinates(parent, tmp2.set(getWidth(), 0)); this.localToAscendantCoordinates(parent, tmp3.set(0, getHeight())); modifier.applyTransformation(representedActor, tmp1, tmp2, tmp3); representedActor.setRotation(startingRotation + getParent().getRotation()); }
/** Returns true if this actor is the same as or is the descendant of the specified actor. */ public boolean isDescendantOf(Actor actor) { if (actor == null) throw new IllegalArgumentException("actor cannot be null."); Actor parent = this; while (true) { if (parent == null) return false; if (parent == actor) return true; parent = parent.getParent(); } }
/** * Converts coordinates for this group to those of a descendant actor. The descendant does not * need to be a direct child. * * @throws IllegalArgumentException if the specified actor is not a descendant of this group. */ public void localToDescendantCoordinates(Actor descendant, Vector2 localPoint) { Group parent = descendant.getParent(); if (parent == null) throw new IllegalArgumentException("Child is not a descendant: " + descendant); // First convert to the actor's parent coordinates. if (parent != this) localToDescendantCoordinates(parent, localPoint); // Then from each parent down to the descendant. descendant.parentToLocalCoordinates(localPoint); }
public void drawDebug(SpriteBatch batch) { if (getDebug() == Debug.none || debugRects == null) return; if (debugRenderer == null) { if (Gdx.graphics.isGL20Available()) debugRenderer = new ImmediateModeRenderer20(64, false, true, 0); else debugRenderer = new ImmediateModeRenderer10(64); } float x = 0, y = 0; Actor parent = getTable(); while (parent != null) { if (parent instanceof Group) { x += parent.getX(); y += parent.getY(); } parent = parent.getParent(); } debugRenderer.begin(batch.getProjectionMatrix(), GL10.GL_LINES); for (int i = 0, n = debugRects.size; i < n; i++) { DebugRect rect = debugRects.get(i); float x1 = x + rect.x; float y1 = y + rect.y - rect.height; float x2 = x1 + rect.width; float y2 = y1 + rect.height; float r = rect.type == Debug.cell ? 1 : 0; float g = rect.type == Debug.widget ? 1 : 0; float b = rect.type == Debug.table ? 1 : 0; debugRenderer.color(r, g, b, 1); debugRenderer.vertex(x1, y1, 0); debugRenderer.color(r, g, b, 1); debugRenderer.vertex(x1, y2, 0); debugRenderer.color(r, g, b, 1); debugRenderer.vertex(x1, y2, 0); debugRenderer.color(r, g, b, 1); debugRenderer.vertex(x2, y2, 0); debugRenderer.color(r, g, b, 1); debugRenderer.vertex(x2, y2, 0); debugRenderer.color(r, g, b, 1); debugRenderer.vertex(x2, y1, 0); debugRenderer.color(r, g, b, 1); debugRenderer.vertex(x2, y1, 0); debugRenderer.color(r, g, b, 1); debugRenderer.vertex(x1, y1, 0); if (debugRenderer.getNumVertices() == 64) { debugRenderer.end(); debugRenderer.begin(batch.getProjectionMatrix(), GL10.GL_LINES); } } debugRenderer.end(); }
/** * Transforms the specified point in the actor's coordinates to be in the stage's coordinates. * Note this method will ONLY work for screen aligned, unrotated, unscaled actors! */ public Vector2 localToStageCoordinates(Vector2 localCoords) { Actor actor = this; while (actor != null) { if (actor.getRotation() != 0 || actor.getScaleX() != 1 || actor.getScaleY() != 1) throw new GdxRuntimeException("Only unrotated and unscaled actors may use this method."); localCoords.x += actor.getX(); localCoords.y += actor.getY(); actor = actor.getParent(); } return localCoords; }
/** * For a given actor computes and applies the transformation to keep the same screen * transformation in a new group * * @param actor * @param parent */ public static void computeTransformFor(Actor actor, Group parent) { Vector2 tmp1 = Pools.obtain(Vector2.class); Vector2 tmp2 = Pools.obtain(Vector2.class); Vector2 tmp3 = Pools.obtain(Vector2.class); Vector2 tmp4 = Pools.obtain(Vector2.class); Vector2 tmp5 = Pools.obtain(Vector2.class); calculateBounds(actor, tmp4, tmp5); Vector2 o = tmp1.set(tmp4.x, tmp4.y); Vector2 t = tmp2.set(tmp4.x + tmp5.x, tmp4.y); Vector2 n = tmp3.set(tmp4.x, tmp4.y + tmp5.y); actor.localToAscendantCoordinates(parent, o); actor.localToAscendantCoordinates(parent, t); actor.localToAscendantCoordinates(parent, n); actor.setRotation(actor.getRotation() + actor.getParent().getRotation()); applyTransformation(actor, o, t, n); Pools.free(tmp1); Pools.free(tmp2); Pools.free(tmp3); Pools.free(tmp4); Pools.free(tmp5); }
/** * @param actor might be in the drag pane. * @return true if actor is added to the pane's internal group. */ public boolean contains(final Actor actor) { return actor.getParent() == getActor(); }
/** Returns the tree this node is currently in, or null. */ public Tree getTree() { Group parent = actor.getParent(); if (!(parent instanceof Tree)) return null; return (Tree) parent; }
private void toStageCoordinates(Actor actor, Vector2 point) { point.x += actor.getX(); point.y += actor.getY(); toStageCoordinates(actor.getParent(), point); }