List of usage examples for com.badlogic.gdx.scenes.scene2d Stage getHeight
public float getHeight()
From source file:com.aia.hichef.ui.n.MyDialog.java
License:Apache License
/** {@link #pack() Packs} the dialog and adds it to the stage, centered. */ public MyDialog show(Stage stage) { clearActions();// w w w. j a v a 2 s.co m removeCaptureListener(ignoreTouchDown); previousKeyboardFocus = null; Actor actor = stage.getKeyboardFocus(); if (actor != null && !actor.isDescendantOf(this)) previousKeyboardFocus = actor; previousScrollFocus = null; actor = stage.getScrollFocus(); if (actor != null && !actor.isDescendantOf(this)) previousScrollFocus = actor; pack(); setPosition(Math.round((stage.getWidth() - getWidth()) / 2), Math.round((stage.getHeight() - getHeight()) / 2)); stage.addActor(this); stage.setKeyboardFocus(this); stage.setScrollFocus(this); if (fadeDuration > 0) { getColor().a = 0; addAction(Actions.fadeIn(fadeDuration, Interpolation.fade)); } return this; }
From source file:com.aia.hichef.ui.n.MyWindow.java
License:Apache License
public MyWindow(String title, WindowStyle style) { if (title == null) throw new IllegalArgumentException("title cannot be null."); this.title = title; setTouchable(Touchable.enabled);//from w ww . j av a 2s .co m setClip(true); setStyle(style); setWidth(150); setHeight(150); setTitle(title); setHeight(100); buttonTable = new Table(); addActor(buttonTable); addCaptureListener(new InputListener() { public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { toFront(); return false; } }); addListener(new InputListener() { int edge; float startX, startY, lastX, lastY; public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { if (button == 0) { int border = resizeBorder; float width = getWidth(), height = getHeight(); edge = 0; if (isResizable) { if (x < border) edge |= Align.left; if (x > width - border) edge |= Align.right; if (y < border) edge |= Align.bottom; if (y > height - border) edge |= Align.top; if (edge != 0) border += 25; if (x < border) edge |= Align.left; if (x > width - border) edge |= Align.right; if (y < border) edge |= Align.bottom; if (y > height - border) edge |= Align.top; } if (isMovable && edge == 0 && y <= height && y >= height - getPadTop() && x >= 0 && x <= width) edge = MOVE; dragging = edge != 0; startX = x; startY = y; lastX = x; lastY = y; } return edge != 0 || isModal; } public void touchUp(InputEvent event, float x, float y, int pointer, int button) { dragging = false; } public void touchDragged(InputEvent event, float x, float y, int pointer) { if (!dragging) return; float width = getWidth(), height = getHeight(); float windowX = getX(), windowY = getY(); float minWidth = getMinWidth(), maxWidth = getMaxWidth(); float minHeight = getMinHeight(), maxHeight = getMaxHeight(); Stage stage = getStage(); boolean clampPosition = keepWithinStage && getParent() == stage.getRoot(); if ((edge & MOVE) != 0) { float amountX = x - startX, amountY = y - startY; windowX += amountX; windowY += amountY; } if ((edge & Align.left) != 0) { float amountX = x - startX; if (width - amountX < minWidth) amountX = -(minWidth - width); if (clampPosition && windowX + amountX < 0) amountX = -windowX; width -= amountX; windowX += amountX; } if ((edge & Align.bottom) != 0) { float amountY = y - startY; if (height - amountY < minHeight) amountY = -(minHeight - height); if (clampPosition && windowY + amountY < 0) amountY = -windowY; height -= amountY; windowY += amountY; } if ((edge & Align.right) != 0) { float amountX = x - lastX; if (width + amountX < minWidth) amountX = minWidth - width; if (clampPosition && windowX + width + amountX > stage.getWidth()) amountX = stage.getWidth() - windowX - width; width += amountX; } if ((edge & Align.top) != 0) { float amountY = y - lastY; if (height + amountY < minHeight) amountY = minHeight - height; if (clampPosition && windowY + height + amountY > stage.getHeight()) amountY = stage.getHeight() - windowY - height; height += amountY; } lastX = x; lastY = y; setBounds(Math.round(windowX), Math.round(windowY), Math.round(width), Math.round(height)); } public boolean mouseMoved(InputEvent event, float x, float y) { return isModal; } public boolean scrolled(InputEvent event, float x, float y, int amount) { return isModal; } public boolean keyDown(InputEvent event, int keycode) { return isModal; } public boolean keyUp(InputEvent event, int keycode) { return isModal; } public boolean keyTyped(InputEvent event, char character) { return isModal; } }); }
From source file:com.aia.hichef.ui.n.MyWindow.java
License:Apache License
void keepWithinStage() { if (!keepWithinStage) return;/*from w w w . j a va2s . co m*/ Stage stage = getStage(); if (getParent() == stage.getRoot()) { float parentWidth = stage.getWidth(); float parentHeight = stage.getHeight(); if (getX() < 0) setX(0); if (getRight() > parentWidth) setX(parentWidth - getWidth()); if (getY() < 0) setY(0); if (getTop() > parentHeight) setY(parentHeight - getHeight()); } }
From source file:com.aia.hichef.ui.n.MyWindow.java
License:Apache License
public void draw(Batch batch, float parentAlpha) { keepWithinStage();/*from w w w . j ava2s . com*/ if (style.stageBackground != null) { Color color = getColor(); batch.setColor(color.r, color.g, color.b, color.a * parentAlpha); Stage stage = getStage(); stageToLocalCoordinates(/* in/out */tmpPosition.set(0, 0)); stageToLocalCoordinates(/* in/out */tmpSize.set(stage.getWidth(), stage.getHeight())); style.stageBackground.draw(batch, getX() + tmpPosition.x, getY() + tmpPosition.y, getX() + tmpSize.x, getY() + tmpSize.y); } super.draw(batch, parentAlpha); }
From source file:com.bladecoder.engineeditor.utils.Message.java
License:Apache License
private static void add(Stage stage, String text) { msg.clearActions();//from ww w . ja v a 2s . c o m msg.setText(text); GlyphLayout textLayout = new GlyphLayout(); textLayout.setText(msg.getStyle().font, text, Color.BLACK, stage.getWidth() * .8f, Align.center, true); msg.setSize(textLayout.width + textLayout.height, textLayout.height + textLayout.height * 2); if (!stage.getActors().contains(msg, true)) stage.addActor(msg); msg.setPosition(Math.round((stage.getWidth() - msg.getWidth()) / 2), Math.round((stage.getHeight() - msg.getHeight()) / 2)); msg.invalidate(); }
From source file:com.kotcrab.vis.editor.util.scene2d.VisDragAndDrop.java
License:Apache License
public void addSource(final Source source) { DragListener listener = new DragListener() { public void dragStart(InputEvent event, float x, float y, int pointer) { if (activePointer != -1) { event.stop();/* w w w . j a va2s. c o m*/ return; } activePointer = pointer; dragStartTime = System.currentTimeMillis(); payload = source.dragStart(event, getTouchDownX(), getTouchDownY(), pointer); event.stop(); if (cancelTouchFocus && payload != null) source.getActor().getStage().cancelTouchFocusExcept(this, source.getActor()); } public void drag(InputEvent event, float x, float y, int pointer) { if (payload == null) return; if (pointer != activePointer) return; Stage stage = event.getStage(); Touchable dragActorTouchable = null; if (dragActor != null) { dragActorTouchable = dragActor.getTouchable(); dragActor.setTouchable(Touchable.disabled); } // Find target. Target newTarget = null; isValidTarget = false; float stageX = event.getStageX() + touchOffsetX, stageY = event.getStageY() + touchOffsetY; Actor hit = event.getStage().hit(stageX, stageY, true); // Prefer touchable actors. if (hit == null) hit = event.getStage().hit(stageX, stageY, false); if (hit != null) { for (int i = 0, n = targets.size; i < n; i++) { Target target = targets.get(i); if (!target.getActor().isAscendantOf(hit)) continue; newTarget = target; target.getActor().stageToLocalCoordinates(tmpVector.set(stageX, stageY)); break; } } //if over a new target, notify the former target that it's being left behind. if (newTarget != target) { if (target != null) target.reset(source, payload); target = newTarget; } //with any reset out of the way, notify new targets of drag. if (newTarget != null) { isValidTarget = newTarget.drag(source, payload, tmpVector.x, tmpVector.y, pointer); } if (dragActor != null) dragActor.setTouchable(dragActorTouchable); // Add/remove and position the drag actor. Actor actor = null; if (target != null) actor = isValidTarget ? payload.getValidDragActor() : payload.getInvalidDragActor(); if (actor == null) actor = payload.getDragActor(); if (actor == null) return; if (dragActor != actor) { if (dragActor != null) dragActor.remove(); dragActor = actor; stage.addActor(actor); } float actorX = event.getStageX() + dragActorX; float actorY = event.getStageY() + dragActorY - actor.getHeight(); if (keepWithinStage) { if (actorX < 0) actorX = 0; if (actorY < 0) actorY = 0; if (actorX + actor.getWidth() > stage.getWidth()) actorX = stage.getWidth() - actor.getWidth(); if (actorY + actor.getHeight() > stage.getHeight()) actorY = stage.getHeight() - actor.getHeight(); } actor.setPosition(actorX, actorY); if (currentSceneCamera != null && editingSettings.isSnapEnabledOrKeyPressed()) { float gridSize = gridSettings.config.gridSize; actor.setPosition(MathUtils.floor(currentSceneCamera.getInputX() / gridSize) * gridSize, MathUtils.floor(currentSceneCamera.getInputY() / gridSize) * gridSize); Vector3 v = currentSceneCamera.project(tmpVector3.set(actor.getX(), actor.getY(), 0)); actor.setPosition(v.x, v.y); } } public void dragStop(InputEvent event, float x, float y, int pointer) { if (pointer != activePointer) return; activePointer = -1; if (payload == null) return; if (System.currentTimeMillis() - dragStartTime < dragTime) isValidTarget = false; if (dragActor != null) dragActor.remove(); if (isValidTarget) { float stageX = event.getStageX() + touchOffsetX, stageY = event.getStageY() + touchOffsetY; target.getActor().stageToLocalCoordinates(tmpVector.set(stageX, stageY)); target.drop(source, payload, tmpVector.x, tmpVector.y, pointer); } source.dragStop(event, x, y, pointer, payload, isValidTarget ? target : null); if (target != null) target.reset(source, payload); payload = null; target = null; isValidTarget = false; dragActor = null; } }; listener.setTapSquareSize(tapSquareSize); listener.setButton(button); source.getActor().addCaptureListener(listener); sourceListeners.put(source, listener); }
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 w w w . j a va2 s . co 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.strategames.catchdastars.game.CatchDaStars.java
License:Open Source License
private void setupLeaveScreenSensor(Stage stage) { //We must make sure balloon is out of screen when //sensor is hit float margin = Wall.WIDTH * 2f; RectangularSensor sensor = new RectangularSensor(null); sensor.setStart(new Vector2(-margin, -margin)); sensor.setEnd(new Vector2(stage.getWidth(), stage.getHeight()).add(margin, margin)); addGameObject(sensor, stage);//from w ww .jav a 2 s . co m }
From source file:com.uwsoft.editor.gdx.ui.dialogs.SimpleDialog.java
License:Apache License
public void initDragDrop() { addListener(new InputListener() { int edge; float startX, startY, lastX, lastY; public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { if (button == 0) { float width = getWidth(), height = getHeight(); edge = 0;//from ww w .j a va 2 s . c om if (isMovable && edge == 0 && y <= height && y >= height - topImg.getY() && x >= 0 && x <= width) edge = MOVE; dragging = edge != 0; startX = x; startY = y; lastX = x; lastY = y; } return (edge != 0 || isModal) && y > topImg.getY(); } public void touchUp(InputEvent event, float x, float y, int pointer, int button) { dragging = false; } public void touchDragged(InputEvent event, float x, float y, int pointer) { if (!dragging) return; float width = getWidth(), height = getHeight(); float windowX = getX(), windowY = getY(); float minWidth = getWidth(); float minHeight = getHeight(); Stage stage = getStage(); boolean clampPosition = keepWithinStage && getParent() == stage.getRoot(); if ((edge & MOVE) != 0) { float amountX = x - startX, amountY = y - startY; windowX += amountX; windowY += amountY; } if ((edge & Align.left) != 0) { float amountX = x - startX; if (width - amountX < minWidth) amountX = -(minWidth - width); if (clampPosition && windowX + amountX < 0) amountX = -windowX; width -= amountX; windowX += amountX; } if ((edge & Align.bottom) != 0) { float amountY = y - startY; if (height - amountY < minHeight) amountY = -(minHeight - height); if (clampPosition && windowY + amountY < 0) amountY = -windowY; height -= amountY; windowY += amountY; } if ((edge & Align.right) != 0) { float amountX = x - lastX; if (width + amountX < minWidth) amountX = minWidth - width; if (clampPosition && windowX + width + amountX > stage.getWidth()) amountX = stage.getWidth() - windowX - width; width += amountX; } if ((edge & Align.top) != 0) { float amountY = y - lastY; if (height + amountY < minHeight) amountY = minHeight - height; if (clampPosition && windowY + height + amountY > stage.getHeight()) amountY = stage.getHeight() - windowY - height; height += amountY; } lastX = x; lastY = y; setBounds(Math.round(windowX), Math.round(windowY), Math.round(width), Math.round(height)); } }); }
From source file:com.vlaaad.common.tutorial.tasks.ArrowForceClick.java
License:Open Source License
@Override public void start(final Callback callback) { init();//from w ww . ja v a2 s . c o m 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); } }