Example usage for com.badlogic.gdx.scenes.scene2d Stage getRoot

List of usage examples for com.badlogic.gdx.scenes.scene2d Stage getRoot

Introduction

In this page you can find the example usage for com.badlogic.gdx.scenes.scene2d Stage getRoot.

Prototype

public Group getRoot() 

Source Link

Document

Returns the root group which holds all actors in the stage.

Usage

From source file:com.aia.hichef.ui.n.MyDialog.java

License:Apache License

private void initialize() {
    setModal(true);//from w  ww .  j a va 2 s  .c o  m

    defaults().space(6);
    add(contentTable = new Table(skin)).expand().fill();
    row();
    add(buttonTable = new Table(skin));

    contentTable.defaults().space(6);
    buttonTable.defaults().space(6);

    buttonTable.addListener(new ChangeListener() {
        public void changed(ChangeEvent event, Actor actor) {
            if (!values.containsKey(actor))
                return;
            while (actor.getParent() != buttonTable)
                actor = actor.getParent();
            result(values.get(actor));
            if (!cancelHide)
                hide();
            cancelHide = false;
        }
    });

    addListener(new FocusListener() {
        public void keyboardFocusChanged(FocusEvent event, Actor actor, boolean focused) {
            if (!focused)
                focusChanged(event);
        }

        public void scrollFocusChanged(FocusEvent event, Actor actor, boolean focused) {
            if (!focused)
                focusChanged(event);
        }

        private void focusChanged(FocusEvent event) {
            Stage stage = getStage();
            if (isModal() && stage != null && stage.getRoot().getChildren().size > 0
                    && stage.getRoot().getChildren().peek() == MyDialog.this) { // Dialog
                // is
                // top
                // most
                // actor.
                Actor newFocusedActor = event.getRelatedActor();
                if (newFocusedActor != null && !newFocusedActor.isDescendantOf(MyDialog.this))
                    event.cancel();
            }
        }
    });
}

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);/*w ww . j  ava2 s. c  o 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 ww  w .  j  a  v a 2s  . c o  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.coder5560.game.ui.MyDialog.java

License:Apache License

private void initialize() {
    setModal(true);//ww  w .  ja v a  2 s . co m
    back2 = new Image(new NinePatchDrawable(
            new NinePatch(new NinePatch(Assets.instance.getRegion("ninepatch2"), 4, 4, 4, 4),
                    new Color(240 / 255f, 240 / 255f, 240 / 255f, 1))));
    addActor(back2);

    defaults().space(6);
    add(contentTable = new Table(skin)).expand().fill();
    row();
    add(buttonTable = new Table(skin));

    contentTable.defaults().space(6);
    buttonTable.defaults().space(6);

    buttonTable.addListener(new ChangeListener() {
        public void changed(ChangeEvent event, Actor actor) {
            if (!values.containsKey(actor))
                return;
            while (actor.getParent() != buttonTable)
                actor = actor.getParent();
            result(values.get(actor));
            if (!cancelHide)
                hide();
            cancelHide = false;
        }
    });

    addListener(new FocusListener() {
        public void keyboardFocusChanged(FocusEvent event, Actor actor, boolean focused) {
            if (!focused)
                focusChanged(event);
        }

        public void scrollFocusChanged(FocusEvent event, Actor actor, boolean focused) {
            if (!focused)
                focusChanged(event);
        }

        private void focusChanged(FocusEvent event) {
            Stage stage = getStage();
            if (isModal() && stage != null && stage.getRoot().getChildren().size > 0
                    && stage.getRoot().getChildren().peek() == MyDialog.this) { // Dialog
                // is
                // top
                // most
                // actor.
                Actor newFocusedActor = event.getRelatedActor();
                if (newFocusedActor != null && !newFocusedActor.isDescendantOf(MyDialog.this))
                    event.cancel();
            }
        }
    });
}

From source file:com.gcq.fivesecond.sprite.PlayerRoundSprite.java

License:Apache License

@Override
public void onCallBack() {
    Stage stage = getStage();
    Actor actor = null;/*from   w ww.ja  va 2s .co m*/
    actor = RoundSceneHelper.roundIntersects(this.getX(), this.getY(), this.getWidth(), this.getHeight(),
            stage.getRoot(), TargetRoundSprite.class);
    if (actor != null) {
        actor.remove();
        synchronized (this) {
            this.director.sendEvent(AppEvents.EVENT_START_TARGET_ROUND_DISC, actor);
        }
    }
}

From source file:com.gcq.fivesecond.sprite.RedRoundSprite.java

License:Apache License

/**
 * Check for collision with another actor on the stage.
 * //from w w w. j av a2s . c om
 * @return Target object if collision or null if none.
 */
private Actor collisionCheck() {
    Actor actor = null;
    Stage stage = getStage();
    if (stage != null) {
        actor = RoundSceneHelper.roundIntersects(this.getX(), this.getY(), this.getWidth(), this.getHeight(),
                stage.getRoot(), PlayerRoundSprite.class);
    }
    return actor;
}

From source file:com.idp.engine.ui.graphics.base.IdpLogger.java

/**
 * Adds the logger to the game's current screen.
 * Screen is obtained via {@link IdpGame#getScreen()}.
 *//* w  w w  . j a  v  a 2s .c o  m*/
public void show() {
    IdpBaseScreen scr = Idp.game.getScreen();
    if (scr == null)
        throw new NullPointerException("Cannot show logger: screen is null");
    Stage stage = scr.getStage();
    stage.getRoot().getChildren().removeValue(this, true);
    stage.addActor(this);
}

From source file:com.jmolina.orb.stages.HUDStage.java

License:Open Source License

/**
 * Ejecuta la secuencia de primer arranque del nivel
 *
 * @param transitionAction Accion de transicion entre pantallas
 * @param backgroundStage Stage de fondo estatico
 * @param orbIntro Callback de ejecucion de la secuencia de introduccion del orbe
 * @param setAsProcessor Callback de activar la entrada
 * @param unlock Callback de desbloqueo de nivel
 *///  w w  w  . ja  v  a 2s  .com
public void init(Action transitionAction, Stage backgroundStage, Runnable orbIntro, Runnable setAsProcessor,
        Runnable unlock) {
    this.addAction(
            sequence(alpha(0), scaleTo(BaseScreen.SIZE_SMALL, BaseScreen.SIZE_SMALL), transitionAction,
                    Actions.addAction(sequence(alpha(1), fadeOut(BACKGROUND_FADE_TIME)),
                            backgroundStage.getRoot()),
                    delay(0.5f * BACKGROUND_FADE_TIME), run(orbIntro), delay(INTRO_SEQUENCE_TIME),
                    run(setAsProcessor), run(unlock)));
}

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  .  java  2s .c  o  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.mk.apps.superm.mtx.effects.EffectCreator.java

License:Apache License

private static void removeActor(Stage stage, Actor actor) {
    if (stage != null && actor != null) {
        actor.clearActions();/*from   www. java2  s.  c om*/
        String actorName = actor.getName();
        if (stage.getRoot().removeActor(actor)) {
            MtxLogger.log(logActive, true, logTag, "Actor removed! (Name: " + actorName + ")");
        } else {
            MtxLogger.log(logActive, true, logTag, "Actor not removed! (Name: " + actorName + ")");
        }
    }
}