use of com.badlogic.gdx.scenes.scene2d.Actor in project libgdx by libgdx.
the class BaseG3dHudTest method createHUD.
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"));
final List<String> modelsList = new List(skin);
modelsList.setItems(models);
modelsList.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
if (!modelsWindow.isCollapsed() && getTapCount() == 2) {
onModelClicked(modelsList.getSelected());
modelsWindow.collapse();
}
}
});
modelsWindow = addListWindow("Models", modelsList, 0, -1);
fpsLabel = new Label("FPS: 999", skin);
hud.addActor(fpsLabel);
gridCheckBox = new CheckBox("Show grid", skin);
gridCheckBox.setChecked(showAxes);
gridCheckBox.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
showAxes = gridCheckBox.isChecked();
}
});
gridCheckBox.setPosition(hudWidth - gridCheckBox.getWidth(), 0);
hud.addActor(gridCheckBox);
rotateCheckBox = new CheckBox("Rotate", skin);
rotateCheckBox.setChecked(true);
rotateCheckBox.setPosition(hudWidth - rotateCheckBox.getWidth(), gridCheckBox.getHeight());
hud.addActor(rotateCheckBox);
moveCheckBox = new CheckBox("Move", skin);
moveCheckBox.setChecked(false);
moveCheckBox.setPosition(hudWidth - moveCheckBox.getWidth(), rotateCheckBox.getTop());
hud.addActor(moveCheckBox);
}
use of com.badlogic.gdx.scenes.scene2d.Actor in project libgdx by libgdx.
the class Dialog method show.
/** {@link #pack() Packs} the dialog and adds it to the stage with custom action which can be null for instant show */
public Dialog show(Stage stage, Action action) {
clearActions();
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();
stage.addActor(this);
stage.setKeyboardFocus(this);
stage.setScrollFocus(this);
if (action != null)
addAction(action);
return this;
}
use of com.badlogic.gdx.scenes.scene2d.Actor in project libgdx by libgdx.
the class HorizontalGroup method layout.
public void layout() {
if (sizeInvalid)
computeSize();
if (wrap) {
layoutWrapped();
return;
}
boolean round = this.round;
int align = this.align;
float space = this.space, padBottom = this.padBottom, fill = this.fill;
float rowHeight = (expand ? getHeight() : prefHeight) - padTop - padBottom, x = padLeft;
if ((align & Align.right) != 0)
x += getWidth() - prefWidth;
else if (// center
(align & Align.left) == 0)
x += (getWidth() - prefWidth) / 2;
float startY;
if ((align & Align.bottom) != 0)
startY = padBottom;
else if ((align & Align.top) != 0)
startY = getHeight() - padTop - rowHeight;
else
startY = padBottom + (getHeight() - padBottom - padTop - rowHeight) / 2;
align = rowAlign;
SnapshotArray<Actor> children = getChildren();
int i = 0, n = children.size, incr = 1;
if (reverse) {
i = n - 1;
n = -1;
incr = -1;
}
for (int r = 0; i != n; i += incr) {
Actor child = children.get(i);
float width, height;
Layout layout = null;
if (child instanceof Layout) {
layout = (Layout) child;
width = layout.getPrefWidth();
height = layout.getPrefHeight();
} else {
width = child.getWidth();
height = child.getHeight();
}
if (fill > 0)
height = rowHeight * fill;
if (layout != null) {
height = Math.max(height, layout.getMinHeight());
float maxHeight = layout.getMaxHeight();
if (maxHeight > 0 && height > maxHeight)
height = maxHeight;
}
float y = startY;
if ((align & Align.top) != 0)
y += rowHeight - height;
else if (// center
(align & Align.bottom) == 0)
y += (rowHeight - height) / 2;
if (round)
child.setBounds(Math.round(x), Math.round(y), Math.round(width), Math.round(height));
else
child.setBounds(x, y, width, height);
x += width + space;
if (layout != null)
layout.validate();
}
}
use of com.badlogic.gdx.scenes.scene2d.Actor in project libgdx by libgdx.
the class Tooltip method enter.
public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {
if (pointer != -1)
return;
if (Gdx.input.isTouched())
return;
Actor actor = event.getListenerActor();
if (fromActor != null && fromActor.isDescendantOf(actor))
return;
setContainerPosition(actor, x, y);
manager.enter(this);
}
use of com.badlogic.gdx.scenes.scene2d.Actor in project libgdx by libgdx.
the class Tree method computeSize.
private void computeSize(Array<Node> nodes, float indent) {
float ySpacing = this.ySpacing;
float spacing = iconSpacingLeft + iconSpacingRight;
for (int i = 0, n = nodes.size; i < n; i++) {
Node node = nodes.get(i);
float rowWidth = indent + iconSpacingRight;
Actor actor = node.actor;
if (actor instanceof Layout) {
Layout layout = (Layout) actor;
rowWidth += layout.getPrefWidth();
node.height = layout.getPrefHeight();
layout.pack();
} else {
rowWidth += actor.getWidth();
node.height = actor.getHeight();
}
if (node.icon != null) {
rowWidth += spacing + node.icon.getMinWidth();
node.height = Math.max(node.height, node.icon.getMinHeight());
}
prefWidth = Math.max(prefWidth, rowWidth);
prefHeight -= node.height + ySpacing;
if (node.expanded)
computeSize(node.children, indent + indentSpacing);
}
}
Aggregations