List of usage examples for com.badlogic.gdx.scenes.scene2d Actor localToStageCoordinates
public Vector2 localToStageCoordinates(Vector2 localCoords)
From source file:com.blastedstudios.gdxworld.util.ui.Scene2DUtils.java
License:Apache License
/** @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// w w w . ja va2 s . c om tmp.set(actor.getX(), actor.getY()); return tmp; }
From source file:com.mobidevelop.maps.editor.ui.utils.Tooltips.java
License:Apache License
public void showTooltip(Actor actor) { Vector2 v = new Vector2(); actor.localToStageCoordinates(v); if (tooltip == null) { LabelStyle style = new LabelStyle(); style.font = tooltipStyle.font;// w w w . ja v a 2 s .c om style.background = tooltipStyle.background; style.fontColor = tooltipStyle.fontColor; tooltip = new Label(tooltips.get(actor), style); tooltip.setStyle(style); tooltip.pack(); tooltip.setPosition(v.x + 7.5f, v.y - tooltip.getPrefHeight() - 15); tooltip.setOriginY(tooltip.getPrefHeight()); tooltip.setColor(1, 1, 1, 0); tooltip.setScale(1, 0); tooltip.addAction(parallel(fadeIn(0.15f), scaleTo(1, 1, 0.15f))); } else { tooltip.setText(tooltips.get(actor)); tooltip.pack(); tooltip.setPosition(v.x + 7.5f, v.y - tooltip.getPrefHeight() - 15); } stage.addActor(tooltip); }
From source file:com.ridiculousRPG.ui.ActorsOnStageService.java
License:Apache License
private void computeTouchPoint(Actor a, Vector2 point) { point.set(a.getWidth() * .5f, a.getHeight() * .5f); a.localToStageCoordinates(point); point.set(point.x * Gdx.graphics.getWidth() / getWidth(), (getHeight() - point.y) * Gdx.graphics.getHeight() / getHeight()); }
From source file:com.vlaaad.common.tutorial.tasks.ArrowForceClick.java
License:Open Source License
@Override public void start(final Callback callback) { init();/* ww w. j ava 2 s . com*/ final Actor target = getTargetActor(); final Image arrow = new Image(getArrowDrawable()); final Table message = getMessageTable(); final Stage stage = target.getStage(); ArrowDirection direction = getDirection(); if (stage == null) throw new IllegalStateException("target is not on stage"); addListener(stage, target, arrow, message, callback); stage.addActor(arrow); stage.addActor(message); Vector2 screenPosition = target.localToStageCoordinates(new Vector2()); switch (direction) { case left: arrow.setPosition(screenPosition.x - arrow.getPrefWidth() - getArrowOffset(), screenPosition.y + target.getHeight() / 2f - arrow.getPrefHeight() / 2f); message.setSize(arrow.getX() - getArrowOffset(), stage.getHeight()); break; case right: arrow.setPosition(screenPosition.x + target.getWidth() + getArrowOffset(), screenPosition.y + target.getHeight() / 2f - arrow.getPrefHeight() / 2f); message.setSize(stage.getWidth() - arrow.getX() - arrow.getPrefWidth() - getArrowOffset(), stage.getHeight()); message.setX(arrow.getX() + arrow.getPrefWidth() + getArrowOffset()); break; case top: arrow.setPosition(screenPosition.x + target.getWidth() / 2f - arrow.getPrefWidth() / 2f, screenPosition.y + target.getHeight() + getArrowOffset()); message.setSize(stage.getWidth(), stage.getHeight() - arrow.getX() - arrow.getPrefHeight() - getArrowOffset()); message.setY(arrow.getY() + arrow.getPrefHeight() + getArrowOffset()); break; case bottom: arrow.setPosition(screenPosition.x + target.getWidth() / 2f - arrow.getPrefWidth() / 2f, screenPosition.y - arrow.getPrefHeight() - getArrowOffset()); message.setSize(stage.getWidth(), arrow.getY() - getArrowOffset()); break; default: throw new IllegalStateException("unknown direction: " + direction); } }
From source file:com.vlaaad.dice.game.tutorial.tasks.ShowTutorialArrow.java
License:Open Source License
@Override public final void start(Callback callback) { final Actor target = getTarget(); final Stage stage = target.getStage(); if (stage == null) throw new IllegalStateException("target is not on stage"); Image arrow = resources.getIfExists("tutorialArrow"); if (arrow == null) { arrow = new Image(Config.skin.getRegion("ui-tutorial-arrow")); arrow.setOrigin(arrow.getWidth() / 2, arrow.getHeight() / 2); stage.addActor(arrow);/* www .j a v a 2s .c o m*/ resources.put("tutorialArrow", arrow); } else { arrow.toFront(); } arrow.clearActions(); Vector2 screenPosition = target.localToStageCoordinates(tmp.set(0, 0)); ArrowDirection direction = getDirection(); switch (direction) { case fromLeft: arrow.setPosition(screenPosition.x - arrow.getPrefWidth() - getArrowOffset(), screenPosition.y + target.getHeight() / 2f - arrow.getPrefHeight() / 2f); arrow.setRotation(-90); break; case fromRight: arrow.setPosition(screenPosition.x + target.getWidth() + getArrowOffset() - arrow.getPrefWidth() / 2, screenPosition.y + target.getHeight() / 2f - arrow.getPrefHeight() / 2f); arrow.setRotation(90); break; case fromTop: arrow.setPosition(screenPosition.x + target.getWidth() / 2f - arrow.getPrefWidth() / 2f, screenPosition.y + target.getHeight() + getArrowOffset()); arrow.setRotation(180); break; case fromBottom: arrow.setPosition(screenPosition.x + target.getWidth() / 2f - arrow.getPrefWidth() / 2f, screenPosition.y - arrow.getPrefHeight() - getArrowOffset()); arrow.setRotation(0); break; default: throw new IllegalStateException("unknown direction: " + direction); } blink(arrow, direction); callback.taskEnded(); }
From source file:com.vlaaad.dice.ui.components.Hint.java
License:Open Source License
public static Hint make(final Actor actor, String locKey, ObjectMap<String, String> params) { final Hint result = new Hint(locKey, params); actor.addCaptureListener(new ActorGestureListener(20, 0.4f, 0.3f, 0.15f) { @Override/* w w w. j a v a 2 s .c om*/ public boolean longPress(Actor actor, float x, float y) { if (actor.getStage() == null) return false; actor.localToStageCoordinates(tmp.set(x, y)); result.show(actor.getStage(), tmp.x, tmp.y); return false; } @Override public void pan(InputEvent event, float x, float y, float deltaX, float deltaY) { if (result.hide()) event.cancel(); } @Override public void touchUp(InputEvent event, float x, float y, int pointer, int button) { if (result.hide()) { event.cancel(); if (actor.getStage() != null) actor.getStage().cancelTouchFocus(); } } }); return result; }
From source file:de.longri.cachebox3.gui.help.HelpWindow.java
License:Open Source License
public static CB_RectF getHelpEllipseFromActor(Actor actor) { Vector2 stagePos = actor.localToStageCoordinates(new Vector2(0, 0)); return new CB_RectF(stagePos.x - CB.scaledSizes.MARGIN, stagePos.y - CB.scaledSizes.MARGIN, actor.getWidth() + CB.scaledSizes.MARGINx2, actor.getHeight() + CB.scaledSizes.MARGINx2); }
From source file:es.eucm.ead.editor.control.actions.editor.ShowContextMenu.java
License:Open Source License
@Override public void perform(Object... args) { Actor actor = (Actor) args[0]; Actor contextMenu = (Actor) args[1]; float offsetX = 0, offsetY = 0; if (args.length == 4) { offsetX = (Float) args[2]; offsetY = (Float) args[3]; }/* w w w. ja v a2 s. c o m*/ boolean overlay = args.length == 3 && (Boolean) args[2]; origin.set(offsetX, offsetY); if (overlay) { origin.add(0, actor.getHeight()); } actor.localToStageCoordinates(origin); controller.getViews().showModal(contextMenu, origin.x, origin.y); }
From source file:es.eucm.ead.editor.control.actions.editor.ShowTooltip.java
License:Open Source License
@Override public void perform(Object... args) { tooltip.setText((String) args[0]); tooltip.pack();/*w w w . jav a 2s .c om*/ Actor actor = (Actor) args[1]; position.set(0, 0); actor.localToStageCoordinates(position); float positionX = position.x + (actor.getWidth() - tooltip.getWidth()) / 2; if (positionX < 0) { positionX = 0; } else if (positionX > Gdx.graphics.getWidth() - tooltip.getWidth()) { positionX = Gdx.graphics.getWidth() - tooltip.getWidth(); } float positionY = position.y - tooltip.getHeight(); if (positionY < 0) { positionY = 0; } else if (positionY > Gdx.graphics.getHeight() - tooltip.getHeight()) { positionY = Gdx.graphics.getHeight() - tooltip.getHeight(); } tooltip.setPosition(positionX, positionY); tooltip.clearActions(); tooltip.addAction(Actions.sequence(Actions.alpha(0.0f), Actions.alpha(1.0f, TOOLTIP_TIME, Interpolation.exp5Out), Actions.delay(TOOLTIP_TIME), Actions.alpha(0.0f, TOOLTIP_TIME, Interpolation.exp5Out), Actions.removeActor())); controller.getViews().addToModalsContainer(tooltip); }
From source file:es.eucm.ead.editor.control.transitions.parallel.TransitionInfo.java
License:Open Source License
public static TransitionInfo init(Transition transition, Actor actor) { TransitionInfo actorInfo = Pools.obtain(TransitionInfo.class); actorInfo.transition = transition;//from w w w. j a v a2 s . co m actor.localToStageCoordinates(TEMP.set(0f, 0f)); actorInfo.currentScreenRegion = new Region(TEMP.x, TEMP.y, actor.getWidth(), actor.getHeight()); actorInfo.nextScreenRegion = actorInfo.currentScreenRegion; return actorInfo; }