@Override public void resize (int width, int height) { super.resize(width, height); hud.getViewport().update(width, height, true); hudWidth = hud.getWidth(); hudHeight = hud.getHeight(); }
/** Centers the dialog in the stage and calls {@link #show(Stage, Action)} with a {@link Actions#fadeIn(float, Interpolation)} * action. */ public Dialog show (Stage stage) { show(stage, sequence(Actions.alpha(0), Actions.fadeIn(0.4f, Interpolation.fade))); setPosition(Math.round((stage.getWidth() - getWidth()) / 2), Math.round((stage.getHeight() - getHeight()) / 2)); return this; }
/** Centers the dialog in the stage and calls {@link #show(Stage, Action)} with a {@link Actions#fadeIn(float, Interpolation)} * action. */ public Dialog show (Stage stage) { show(stage, sequence(Actions.alpha(0), Actions.fadeIn(0.4f, Interpolation.fade))); setPosition(Math.round((stage.getWidth() - getWidth()) / 2), Math.round((stage.getHeight() - getHeight()) / 2)); return this; }
public void validate () { if (!layoutEnabled) return; Group parent = getParent(); if (fillParent && parent != null) { float parentWidth, parentHeight; Stage stage = getStage(); if (stage != null && parent == stage.getRoot()) { parentWidth = stage.getWidth(); parentHeight = stage.getHeight(); } else { parentWidth = parent.getWidth(); parentHeight = parent.getHeight(); } setSize(parentWidth, parentHeight); } if (!needsLayout) return; needsLayout = false; layout(); }
public void validate () { if (!layoutEnabled) return; Group parent = getParent(); if (fillParent && parent != null) { float parentWidth, parentHeight; Stage stage = getStage(); if (stage != null && parent == stage.getRoot()) { parentWidth = stage.getWidth(); parentHeight = stage.getHeight(); } else { parentWidth = parent.getWidth(); parentHeight = parent.getHeight(); } setSize(parentWidth, parentHeight); } if (!needsLayout) return; needsLayout = false; layout(); }
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 void draw (Batch batch, float parentAlpha) { Stage stage = getStage(); if (stage.getKeyboardFocus() == null) stage.setKeyboardFocus(this); keepWithinStage(); if (style.stageBackground != null) { stageToLocalCoordinates(tmpPosition.set(0, 0)); stageToLocalCoordinates(tmpSize.set(stage.getWidth(), stage.getHeight())); drawStageBackground(batch, parentAlpha, getX() + tmpPosition.x, getY() + tmpPosition.y, getX() + tmpSize.x, getY() + tmpSize.y); } super.draw(batch, parentAlpha); }
public void draw (Batch batch, float parentAlpha) { Stage stage = getStage(); if (stage.getKeyboardFocus() == null) stage.setKeyboardFocus(this); keepWithinStage(); if (style.stageBackground != null) { stageToLocalCoordinates(tmpPosition.set(0, 0)); stageToLocalCoordinates(tmpSize.set(stage.getWidth(), stage.getHeight())); drawStageBackground(batch, parentAlpha, getX() + tmpPosition.x, getY() + tmpPosition.y, getX() + tmpSize.x, getY() + tmpSize.y); } super.draw(batch, parentAlpha); }
public void keepWithinStage () { if (!keepWithinStage) return; Stage stage = getStage(); if (stage == null) return; Camera camera = stage.getCamera(); if (camera instanceof OrthographicCamera) { OrthographicCamera orthographicCamera = (OrthographicCamera)camera; float parentWidth = stage.getWidth(); float parentHeight = stage.getHeight(); if (getX(Align.right) - camera.position.x > parentWidth / 2 / orthographicCamera.zoom) setPosition(camera.position.x + parentWidth / 2 / orthographicCamera.zoom, getY(Align.right), Align.right); if (getX(Align.left) - camera.position.x < -parentWidth / 2 / orthographicCamera.zoom) setPosition(camera.position.x - parentWidth / 2 / orthographicCamera.zoom, getY(Align.left), Align.left); if (getY(Align.top) - camera.position.y > parentHeight / 2 / orthographicCamera.zoom) setPosition(getX(Align.top), camera.position.y + parentHeight / 2 / orthographicCamera.zoom, Align.top); if (getY(Align.bottom) - camera.position.y < -parentHeight / 2 / orthographicCamera.zoom) setPosition(getX(Align.bottom), camera.position.y - parentHeight / 2 / orthographicCamera.zoom, Align.bottom); } else 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()); } }
public void keepWithinStage () { if (!keepWithinStage) return; Stage stage = getStage(); if (stage == null) return; Camera camera = stage.getCamera(); if (camera instanceof OrthographicCamera) { OrthographicCamera orthographicCamera = (OrthographicCamera)camera; float parentWidth = stage.getWidth(); float parentHeight = stage.getHeight(); if (getX(Align.right) - camera.position.x > parentWidth / 2 / orthographicCamera.zoom) setPosition(camera.position.x + parentWidth / 2 / orthographicCamera.zoom, getY(Align.right), Align.right); if (getX(Align.left) - camera.position.x < -parentWidth / 2 / orthographicCamera.zoom) setPosition(camera.position.x - parentWidth / 2 / orthographicCamera.zoom, getY(Align.left), Align.left); if (getY(Align.top) - camera.position.y > parentHeight / 2 / orthographicCamera.zoom) setPosition(getX(Align.top), camera.position.y + parentHeight / 2 / orthographicCamera.zoom, Align.top); if (getY(Align.bottom) - camera.position.y < -parentHeight / 2 / orthographicCamera.zoom) setPosition(getX(Align.bottom), camera.position.y - parentHeight / 2 / orthographicCamera.zoom, Align.bottom); } else 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()); } }
@Override public void create () { if (app == null) { app = Gdx.app; tests[testIndex].create(); } cameraController = new CameraInputController(tests[testIndex].camera); cameraController.activateKey = Keys.CONTROL_LEFT; cameraController.autoUpdate = false; cameraController.forwardTarget = false; cameraController.translateTarget = false; Gdx.input.setInputProcessor(new InputMultiplexer(cameraController, this, new GestureDetector(this))); font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false); hud = new Stage(); hud.addActor(fpsLabel = new Label(" ", new Label.LabelStyle(font, Color.WHITE))); fpsLabel.setPosition(0, 0); hud.addActor(titleLabel = new Label(tests[testIndex].getClass().getSimpleName(), new Label.LabelStyle(font, Color.WHITE))); titleLabel.setY(hud.getHeight() - titleLabel.getHeight()); hud.addActor(instructLabel = new Label("A\nB\nC\nD\nE\nF", new Label.LabelStyle(font, Color.WHITE))); instructLabel.setY(titleLabel.getY() - instructLabel.getHeight()); instructLabel.setAlignment(Align.top | Align.left); instructLabel.setText(tests[testIndex].instructions); }
private Group createActorGroup (TextureRegionDrawable bob) { Actor main = new DrawableActor(bob); main.setPosition(0, 0, Align.center); Actor hat = new DrawableActor(bob) { @Override public void act (float delta) { rotateBy(delta * -300); } }; hat.setOrigin(Align.center); hat.setScale(0.5f); hat.setPosition(0, 21, Align.center); Group group = new Group() { @Override public void act (float delta) { rotateBy(delta * 120); setScale(0.9f + 0.2f * MathUtils.cos(MathUtils.degreesToRadians * getRotation())); super.act(delta); } }; group.addActor(main); group.addActor(hat) ; // group.setTransform(false); float margin = 35; float x = MathUtils.random(margin, stage.getWidth() - margin); float y = MathUtils.random(margin, stage.getHeight() - margin); group.setPosition(x, y); group.setRotation(MathUtils.random(0, 360)); return group; }
if (stage != null && parent == stage.getRoot()) { parentWidth = stage.getWidth(); parentHeight = stage.getHeight(); } else { parentWidth = parent.getWidth();
if (stage != null && parent == stage.getRoot()) { parentWidth = stage.getWidth(); parentHeight = stage.getHeight(); } else { parentWidth = parent.getWidth();
private void createUI () { skin = new Skin(Gdx.files.internal("data/uiskin.json")); ui = new Stage(); String[] filters = new String[TextureFilter.values().length]; int idx = 0; for (TextureFilter filter : TextureFilter.values()) { filters[idx++] = filter.toString(); } hwMipMap = new CheckBox("Hardware Mips", skin); minFilter = new SelectBox(skin); minFilter.setItems(filters); magFilter = new SelectBox(skin.get(SelectBoxStyle.class)); magFilter.setItems("Nearest", "Linear"); Table table = new Table(); table.setSize(ui.getWidth(), 30); table.setY(ui.getHeight() - 30); table.add(hwMipMap).spaceRight(5); table.add(new Label("Min Filter", skin)).spaceRight(5); table.add(minFilter).spaceRight(5); table.add(new Label("Mag Filter", skin)).spaceRight(5); table.add(magFilter); ui.addActor(table); }
protected void createHUD () { hud = new Stage(new ScalingViewport(Scaling.fit, PREF_HUDWIDTH, PREF_HUDHEIGHT)); hudWidth = hud.getWidth(); hudHeight = hud.getHeight(); skin = new Skin(Gdx.files.internal("data/uiskin.json"));