Search in sources :

Example 16 with Stage

use of com.badlogic.gdx.scenes.scene2d.Stage in project libgdx by libgdx.

the class Dialog method initialize.

private void initialize() {
    setModal(true);
    defaults().space(6);
    add(contentTable = new Table(skin)).expand().fill();
    row();
    add(buttonTable = new Table(skin)).fillX();
    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;
        }
    });
    focusListener = 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() == Dialog.this) {
                // Dialog is top most actor.
                Actor newFocusedActor = event.getRelatedActor();
                if (newFocusedActor != null && !newFocusedActor.isDescendantOf(Dialog.this) && !(newFocusedActor.equals(previousKeyboardFocus) || newFocusedActor.equals(previousScrollFocus)))
                    event.cancel();
            }
        }
    };
}
Also used : Actor(com.badlogic.gdx.scenes.scene2d.Actor) Stage(com.badlogic.gdx.scenes.scene2d.Stage) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) FocusListener(com.badlogic.gdx.scenes.scene2d.utils.FocusListener)

Example 17 with Stage

use of com.badlogic.gdx.scenes.scene2d.Stage in project libgdx by libgdx.

the class Dialog method hide.

/** Hides the dialog with the given action and then removes it from the stage. */
public void hide(Action action) {
    Stage stage = getStage();
    if (stage != null) {
        removeListener(focusListener);
        if (previousKeyboardFocus != null && previousKeyboardFocus.getStage() == null)
            previousKeyboardFocus = null;
        Actor actor = stage.getKeyboardFocus();
        if (actor == null || actor.isDescendantOf(this))
            stage.setKeyboardFocus(previousKeyboardFocus);
        if (previousScrollFocus != null && previousScrollFocus.getStage() == null)
            previousScrollFocus = null;
        actor = stage.getScrollFocus();
        if (actor == null || actor.isDescendantOf(this))
            stage.setScrollFocus(previousScrollFocus);
    }
    if (action != null) {
        addCaptureListener(ignoreTouchDown);
        addAction(sequence(action, Actions.removeListener(ignoreTouchDown, true), Actions.removeActor()));
    } else
        remove();
}
Also used : Actor(com.badlogic.gdx.scenes.scene2d.Actor) Stage(com.badlogic.gdx.scenes.scene2d.Stage)

Example 18 with Stage

use of com.badlogic.gdx.scenes.scene2d.Stage in project libgdx by libgdx.

the class TextField method draw.

@Override
public void draw(Batch batch, float parentAlpha) {
    Stage stage = getStage();
    boolean focused = stage != null && stage.getKeyboardFocus() == this;
    if (!focused)
        keyRepeatTask.cancel();
    final BitmapFont font = style.font;
    final Color fontColor = (disabled && style.disabledFontColor != null) ? style.disabledFontColor : ((focused && style.focusedFontColor != null) ? style.focusedFontColor : style.fontColor);
    final Drawable selection = style.selection;
    final Drawable cursorPatch = style.cursor;
    final Drawable background = getBackgroundDrawable();
    Color color = getColor();
    float x = getX();
    float y = getY();
    float width = getWidth();
    float height = getHeight();
    batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);
    float bgLeftWidth = 0, bgRightWidth = 0;
    if (background != null) {
        background.draw(batch, x, y, width, height);
        bgLeftWidth = background.getLeftWidth();
        bgRightWidth = background.getRightWidth();
    }
    float textY = getTextY(font, background);
    calculateOffsets();
    if (focused && hasSelection && selection != null) {
        drawSelection(selection, batch, font, x + bgLeftWidth, y + textY);
    }
    float yOffset = font.isFlipped() ? -textHeight : 0;
    if (displayText.length() == 0) {
        if (!focused && messageText != null) {
            if (style.messageFontColor != null) {
                font.setColor(style.messageFontColor.r, style.messageFontColor.g, style.messageFontColor.b, style.messageFontColor.a * color.a * parentAlpha);
            } else
                font.setColor(0.7f, 0.7f, 0.7f, color.a * parentAlpha);
            BitmapFont messageFont = style.messageFont != null ? style.messageFont : font;
            messageFont.draw(batch, messageText, x + bgLeftWidth, y + textY + yOffset, 0, messageText.length(), width - bgLeftWidth - bgRightWidth, textHAlign, false, "...");
        }
    } else {
        font.setColor(fontColor.r, fontColor.g, fontColor.b, fontColor.a * color.a * parentAlpha);
        drawText(batch, font, x + bgLeftWidth, y + textY + yOffset);
    }
    if (focused && !disabled) {
        blink();
        if (cursorOn && cursorPatch != null) {
            drawCursor(cursorPatch, batch, font, x + bgLeftWidth, y + textY);
        }
    }
}
Also used : Color(com.badlogic.gdx.graphics.Color) Drawable(com.badlogic.gdx.scenes.scene2d.utils.Drawable) Stage(com.badlogic.gdx.scenes.scene2d.Stage) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont)

Example 19 with Stage

use of com.badlogic.gdx.scenes.scene2d.Stage in project libgdx by libgdx.

the class TextField method getBackgroundDrawable.

private Drawable getBackgroundDrawable() {
    Stage stage = getStage();
    boolean focused = stage != null && stage.getKeyboardFocus() == this;
    return (disabled && style.disabledBackground != null) ? style.disabledBackground : ((focused && style.focusedBackground != null) ? style.focusedBackground : style.background);
}
Also used : Stage(com.badlogic.gdx.scenes.scene2d.Stage)

Example 20 with Stage

use of com.badlogic.gdx.scenes.scene2d.Stage in project libgdx by libgdx.

the class Tooltip method setContainerPosition.

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);
}
Also used : Vector2(com.badlogic.gdx.math.Vector2) Stage(com.badlogic.gdx.scenes.scene2d.Stage)

Aggregations

Stage (com.badlogic.gdx.scenes.scene2d.Stage)72 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)36 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)32 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)25 Texture (com.badlogic.gdx.graphics.Texture)24 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)20 Actor (com.badlogic.gdx.scenes.scene2d.Actor)19 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)18 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)16 Image (com.badlogic.gdx.scenes.scene2d.ui.Image)16 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)15 ScreenViewport (com.badlogic.gdx.utils.viewport.ScreenViewport)14 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)13 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)13 ScrollPane (com.badlogic.gdx.scenes.scene2d.ui.ScrollPane)9 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)8 CheckBox (com.badlogic.gdx.scenes.scene2d.ui.CheckBox)6 ShapeRenderer (com.badlogic.gdx.graphics.glutils.ShapeRenderer)5 Group (com.badlogic.gdx.scenes.scene2d.Group)5 InputMultiplexer (com.badlogic.gdx.InputMultiplexer)4