/** Converts coordinates for this actor to those of another actor, which can be anywhere in the stage. */ public Vector2 localToActorCoordinates (Actor actor, Vector2 localCoords) { localToStageCoordinates(localCoords); return actor.stageToLocalCoordinates(localCoords); }
/** Converts coordinates for this actor to those of another actor, which can be anywhere in the stage. */ public Vector2 localToActorCoordinates (Actor actor, Vector2 localCoords) { localToStageCoordinates(localCoords); return actor.stageToLocalCoordinates(localCoords); }
private void setContainerPosition (Actor actor, float x, float y) { this.targetActor = actor; Stage stage = actor.getStage(); if (stage == null) return; container.pack(); float offsetX = manager.offsetX, offsetY = manager.offsetY, dist = manager.edgeDistance; Vector2 point = actor.localToStageCoordinates(tmp.set(x + offsetX, y - offsetY - container.getHeight())); if (point.y < dist) point = actor.localToStageCoordinates(tmp.set(x + offsetX, y + offsetY)); if (point.x < dist) point.x = dist; if (point.x + container.getWidth() > stage.getWidth() - dist) point.x = stage.getWidth() - dist - container.getWidth(); if (point.y + container.getHeight() > stage.getHeight() - dist) point.y = stage.getHeight() - dist - container.getHeight(); container.setPosition(point.x, point.y); point = actor.localToStageCoordinates(tmp.set(actor.getWidth() / 2, actor.getHeight() / 2)); point.sub(container.getX(), container.getY()); container.setOrigin(point.x, point.y); }
private void setContainerPosition (Actor actor, float x, float y) { this.targetActor = actor; Stage stage = actor.getStage(); if (stage == null) return; container.pack(); float offsetX = manager.offsetX, offsetY = manager.offsetY, dist = manager.edgeDistance; Vector2 point = actor.localToStageCoordinates(tmp.set(x + offsetX, y - offsetY - container.getHeight())); if (point.y < dist) point = actor.localToStageCoordinates(tmp.set(x + offsetX, y + offsetY)); if (point.x < dist) point.x = dist; if (point.x + container.getWidth() > stage.getWidth() - dist) point.x = stage.getWidth() - dist - container.getWidth(); if (point.y + container.getHeight() > stage.getHeight() - dist) point.y = stage.getHeight() - dist - container.getHeight(); container.setPosition(point.x, point.y); point = actor.localToStageCoordinates(tmp.set(actor.getWidth() / 2, actor.getHeight() / 2)); point.sub(container.getX(), container.getY()); container.setOrigin(point.x, point.y); }
public static Vector2 getStageLocation(Actor actor) { return actor.localToStageCoordinates(new Vector2(0, 0)); }
/** Converts coordinates for this actor to those of another actor, which can be anywhere in the stage. */ public Vector2 localToActorCoordinates (Actor actor, Vector2 localCoords) { localToStageCoordinates(localCoords); return actor.stageToLocalCoordinates(localCoords); }
public static Vector2 getStageLocation(Actor actor) { return actor.localToStageCoordinates(new Vector2(0, 0)); }
/** @param actor the actor which position in stage coordinates to return * @return the position of the given actor in the stage coordinate system */ public static Vector2 positionInStageCoordinates(Actor actor) { if(actor.hasParent()) actor.localToStageCoordinates(tmp.set(0, 0)); else tmp.set(actor.getX(), actor.getY()); return tmp; }
/** * Shows menu below (or above if not enough space) given actor. * @param stage stage instance that this menu is being added to * @param actor used to get calculate menu position in stage, menu will be displayed above or below it */ public void showMenu(Stage stage, Actor actor) { Vector2 pos = actor.localToStageCoordinates(tmpVector.setZero()); float menuY; if (pos.y - getHeight() <= 0) { menuY = pos.y + actor.getHeight() + getHeight() - 5; } else { menuY = pos.y + 5; } showMenu(stage, pos.x, menuY); }
/** * Shows menu below (or above if not enough space) given actor. * @param stage stage instance that this menu is being added to * @param actor used to get calculate menu position in stage, menu will be displayed above or below it */ public void showMenu (Stage stage, Actor actor) { Vector2 pos = actor.localToStageCoordinates(tmpVector.setZero()); float menuY; if (pos.y - getHeight() <= 0) { menuY = pos.y + actor.getHeight() + getHeight() - sizes.borderSize; } else { menuY = pos.y + sizes.borderSize; } showMenu(stage, pos.x, menuY); }
private void setContainerPosition (Actor actor, float x, float y) { this.targetActor = actor; Stage stage = actor.getStage(); if (stage == null) return; container.pack(); float offsetX = manager.offsetX, offsetY = manager.offsetY, dist = manager.edgeDistance; Vector2 point = actor.localToStageCoordinates(tmp.set(x + offsetX, y - offsetY - container.getHeight())); if (point.y < dist) point = actor.localToStageCoordinates(tmp.set(x + offsetX, y + offsetY)); if (point.x < dist) point.x = dist; if (point.x + container.getWidth() > stage.getWidth() - dist) point.x = stage.getWidth() - dist - container.getWidth(); if (point.y + container.getHeight() > stage.getHeight() - dist) point.y = stage.getHeight() - dist - container.getHeight(); container.setPosition(point.x, point.y); point = actor.localToStageCoordinates(tmp.set(actor.getWidth() / 2, actor.getHeight() / 2)); point.sub(container.getX(), container.getY()); container.setOrigin(point.x, point.y); }
@Override public void enter (InputEvent event, float x, float y, int pointer, Actor fromActor) { if (pointer == -1) { Vector2 targetPos = target.localToStageCoordinates(new Vector2()); setX(targetPos.x + (target.getWidth() - getWidth()) / 2); float tooltipY = targetPos.y - getHeight() - 6; float stageHeight = target.getStage().getHeight(); //is there enough space to display above widget? if (stageHeight - tooltipY > stageHeight) setY(targetPos.y + target.getHeight() + 6); //display above widget else setY(tooltipY); //display below displayTask.cancel(); Timer.schedule(displayTask, appearDelayTime); } }
private void getStageCoordinatesWithinParent (final InputEvent event) { final Actor parent = mimic.getActor().getParent(); if (parent != null) { MIMIC_COORDINATES.set(Vector2.Zero); parent.localToStageCoordinates(MIMIC_COORDINATES); final float parentX = MIMIC_COORDINATES.x; final float parentY = MIMIC_COORDINATES.y; final float parentEndX = parentX + parent.getWidth(); final float parentEndY = parentY + parent.getHeight(); MIMIC_COORDINATES.set(event.getStageX() + offsetX, event.getStageY() + offsetY); if (MIMIC_COORDINATES.x < parentX) { MIMIC_COORDINATES.x = parentX; } else if (MIMIC_COORDINATES.x + mimic.getWidth() > parentEndX) { MIMIC_COORDINATES.x = parentEndX - mimic.getWidth(); } if (MIMIC_COORDINATES.y < parentY) { MIMIC_COORDINATES.y = parentY; } else if (MIMIC_COORDINATES.y + mimic.getHeight() > parentEndY) { MIMIC_COORDINATES.y = parentEndY - mimic.getHeight(); } STAGE_COORDINATES.set(MathUtils.clamp(event.getStageX(), parentX, parentEndX - 1f), MathUtils.clamp(event.getStageY(), parentY, parentEndY - 1f)); } else { getStageCoordinatesWithOffset(event); } }
if (parent != null) { MIMIC_COORDINATES.set(Vector2.Zero); parent.localToStageCoordinates(MIMIC_COORDINATES); final float parentX = MIMIC_COORDINATES.x; final float parentY = MIMIC_COORDINATES.y;