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();
}
}
};
}
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();
}
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);
}
}
}
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);
}
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);
}
Aggregations