List of usage examples for com.badlogic.gdx.scenes.scene2d Actor stageToLocalCoordinates
public Vector2 stageToLocalCoordinates(Vector2 stageCoords)
From source file:com.agateau.ui.anchor.PositionRule.java
License:Apache License
@Override public void apply() { // Compute reference position Vector2 referencePos = new Vector2(reference.getWidth() * referenceAnchor.hPercent, reference.getHeight() * referenceAnchor.vPercent); Vector2 stagePos = reference.localToStageCoordinates(referencePos); // Apply space stagePos.add(hSpace, vSpace);/*from w ww . ja va 2 s . c o m*/ // Position target (use target parent because setPosition() works in parent coordinates) Actor targetParent = target.getParent(); if (targetParent == null) { return; } Vector2 targetPos = targetParent.stageToLocalCoordinates(stagePos); // Apply target offset (If right-aligned, hPercent is 100% => -width * scale. // If centered, hPercent is 50% => -width * scale / 2) targetPos.add(-target.getWidth() * target.getScaleX() * targetAnchor.hPercent, -target.getHeight() * target.getScaleY() * targetAnchor.vPercent); //noinspection SuspiciousNameCombination target.setPosition(MathUtils.floor(targetPos.x), MathUtils.floor(targetPos.y)); }
From source file:com.ridiculousRPG.ui.ActorFocusUtil.java
License:Apache License
private static boolean tryFocusPrevChild(Actor focused, boolean up, boolean left, Stage stage, Array<Actor> allActors) { Vector2 tmpPoint = ActorFocusUtil.tmpPoint; focused.stageToLocalCoordinates(tmpPoint.set(focused.getX(), focused.getY())); float fX1 = focused.getX() - tmpPoint.x; float fY1 = focused.getY() - tmpPoint.y; float fX2 = fX1 + focused.getWidth() * .5f; float fY2 = fY1 + focused.getHeight() * .5f; for (int i = allActors.size - 1; i > -1; i--) { Actor a = allActors.get(i);/*w ww. ja v a2 s.co m*/ if (a == focused) continue; a.stageToLocalCoordinates(tmpPoint.set(a.getX(), a.getY())); float aX1 = a.getX() - tmpPoint.x; float aY1 = a.getY() - tmpPoint.y; float aX2 = aX1 + a.getWidth() * .5f; float aY2 = aY1 + a.getHeight() * .5f; if (isFocusable(a)) { if (up) { if (aY1 >= fY2 && aX2 > fX1 && aX1 < fX2) return focus(a, true, stage); } else if (left) { if (aX2 <= fX1 && aY1 < fY2 && aY2 > fY1) return focus(a, true, stage); } else if (aY1 >= fY2 || (aX2 <= fX1 && aY1 < fY2 && aY2 > fY1)) return focus(a, true, stage); } else if (a instanceof Group) { if (tryFocusPrevChild(focused, up, left, stage, ((Group) a).getChildren())) { return true; } } } return false; }
From source file:com.ridiculousRPG.ui.ActorFocusUtil.java
License:Apache License
private static boolean tryFocusNextChild(Actor focused, boolean down, boolean right, Stage stage, Array<Actor> allActors) { Vector2 tmpPoint = ActorFocusUtil.tmpPoint; focused.stageToLocalCoordinates(tmpPoint.set(focused.getX(), focused.getY())); float fX1 = focused.getX() - tmpPoint.x; float fY1 = focused.getY() - tmpPoint.y; float fX2 = fX1 + focused.getWidth() * .5f; float fY2 = fY1 + focused.getHeight() * .5f; for (int i = 0, len = allActors.size; i < len; i++) { Actor a = allActors.get(i);/*from w w w . j av a 2 s .c o m*/ if (a == focused) continue; a.stageToLocalCoordinates(tmpPoint.set(a.getX(), a.getY())); float aX1 = a.getX() - tmpPoint.x; float aY1 = a.getY() - tmpPoint.y; float aX2 = aX1 + a.getWidth() * .5f; float aY2 = aY1 + a.getHeight() * .5f; if (isFocusable(a)) { if (down) { if (aY2 <= fY1 && aX2 > fX1 && aX1 < fX2) return focus(a, false, stage); } else if (right) { if (aX1 >= fX2 && aY1 < fY2 && aY2 > fY1) return focus(a, false, stage); } else if (aY2 <= fY1 || (aX1 >= fX2 && aY1 < fY2 && aY2 > fY1)) return focus(a, false, stage); } else if (a instanceof Group) { if (tryFocusNextChild(focused, down, right, stage, ((Group) a).getChildren())) { return true; } } } return false; }
From source file:es.eucm.ead.editor.ui.listeners.ContextListener.java
License:Open Source License
public void clicked(InputEvent event, float x, float y) { Actor target = event.getTarget(); DisplayableContextMenu menu = null;/*from w w w .j a v a2 s . com*/ while (target != null) { menu = menus.get(target.getClass()); if (menu != null) { break; } target = target.getParent(); } if (menu != null) { target.stageToLocalCoordinates(TEMP.set(event.getStageX(), event.getStageY())); menu.displayContext(target, TEMP.x, TEMP.y); } }