use of com.badlogic.gdx.scenes.scene2d.Actor in project libgdx by libgdx.
the class HorizontalGroup method layoutWrapped.
private void layoutWrapped() {
float prefHeight = getPrefHeight();
if (prefHeight != lastPrefHeight) {
lastPrefHeight = prefHeight;
invalidateHierarchy();
}
int align = this.align;
boolean round = this.round;
float space = this.space, padBottom = this.padBottom, fill = this.fill, wrapSpace = this.wrapSpace;
float maxWidth = prefWidth - padLeft - padRight;
float rowY = prefHeight - padTop, groupWidth = getWidth(), xStart = padLeft, x = 0, rowHeight = 0;
if ((align & Align.top) != 0)
rowY += getHeight() - prefHeight;
else if (// center
(align & Align.bottom) == 0)
rowY += (getHeight() - prefHeight) / 2;
if ((align & Align.right) != 0)
xStart += groupWidth - prefWidth;
else if (// center
(align & Align.left) == 0)
xStart += (groupWidth - prefWidth) / 2;
groupWidth -= padRight;
align = this.rowAlign;
FloatArray rowSizes = this.rowSizes;
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 (x + width > groupWidth || r == 0) {
x = xStart;
if ((align & Align.right) != 0)
x += maxWidth - rowSizes.get(r);
else if (// center
(align & Align.left) == 0)
x += (maxWidth - rowSizes.get(r)) / 2;
rowHeight = rowSizes.get(r + 1);
if (r > 0)
rowY -= wrapSpace;
rowY -= rowHeight;
r += 2;
}
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 = rowY;
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 TextField method findNextTextField.
private TextField findNextTextField(Array<Actor> actors, TextField best, Vector2 bestCoords, Vector2 currentCoords, boolean up) {
for (int i = 0, n = actors.size; i < n; i++) {
Actor actor = actors.get(i);
if (actor == this)
continue;
if (actor instanceof TextField) {
TextField textField = (TextField) actor;
if (textField.isDisabled() || !textField.focusTraversal)
continue;
Vector2 actorCoords = actor.getParent().localToStageCoordinates(tmp3.set(actor.getX(), actor.getY()));
if ((actorCoords.y < currentCoords.y || (actorCoords.y == currentCoords.y && actorCoords.x > currentCoords.x)) ^ up) {
if (best == null || (actorCoords.y > bestCoords.y || (actorCoords.y == bestCoords.y && actorCoords.x < bestCoords.x)) ^ up) {
best = (TextField) actor;
bestCoords.set(actorCoords);
}
}
} else if (actor instanceof Group)
best = findNextTextField(((Group) actor).getChildren(), best, bestCoords, currentCoords, up);
}
return best;
}
use of com.badlogic.gdx.scenes.scene2d.Actor in project libgdx by libgdx.
the class InterpolationTest method create.
@Override
public void create() {
Gdx.gl.glClearColor(.3f, .3f, .3f, 1);
renderer = new ShapeRenderer();
skin = new Skin(Gdx.files.internal("data/uiskin.json"));
stage = new Stage(new ScreenViewport());
resetPositions();
Field[] interpolationFields = ClassReflection.getFields(Interpolation.class);
// see how many fields are actually interpolations (for safety; other fields may be added with future)
int interpolationMembers = 0;
for (int i = 0; i < interpolationFields.length; i++) if (ClassReflection.isAssignableFrom(Interpolation.class, interpolationFields[i].getDeclaringClass()))
interpolationMembers++;
// get interpolation names
interpolationNames = new String[interpolationMembers];
for (int i = 0; i < interpolationFields.length; i++) if (ClassReflection.isAssignableFrom(Interpolation.class, interpolationFields[i].getDeclaringClass()))
interpolationNames[i] = interpolationFields[i].getName();
selectedInterpolation = interpolationNames[0];
list = new List(skin);
list.setItems(interpolationNames);
list.addListener(new ChangeListener() {
public void changed(ChangeEvent event, Actor actor) {
selectedInterpolation = list.getSelected();
time = 0;
resetPositions();
}
});
ScrollPane scroll = new ScrollPane(list, skin);
scroll.setFadeScrollBars(false);
scroll.setScrollingDisabled(true, false);
table = new Table();
table.setFillParent(true);
table.add(scroll).expandX().left().width(100);
stage.addActor(table);
Gdx.input.setInputProcessor(new InputMultiplexer(new InputAdapter() {
public boolean scrolled(int amount) {
if (!Gdx.input.isKeyPressed(Keys.CONTROL_LEFT))
return false;
duration -= amount / 15f;
duration = MathUtils.clamp(duration, 0, Float.POSITIVE_INFINITY);
return true;
}
}, stage, new InputAdapter() {
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
if (// if "walking" was interrupted by this touch down event
!Float.isNaN(time))
// set startPosition to the current position
startPosition.set(getPosition(time));
targetPosition.set(stage.screenToStageCoordinates(targetPosition.set(screenX, screenY)));
time = 0;
return true;
}
}));
}
use of com.badlogic.gdx.scenes.scene2d.Actor in project libgdx by libgdx.
the class StageTest method create.
@Override
public void create() {
texture = new Texture(Gdx.files.internal("data/badlogicsmall.jpg"));
texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false);
stage = new Stage(new ScreenViewport());
float loc = (NUM_SPRITES * (32 + SPACING) - SPACING) / 2;
for (int i = 0; i < NUM_GROUPS; i++) {
Group group = new Group();
group.setX((float) Math.random() * (stage.getWidth() - NUM_SPRITES * (32 + SPACING)));
group.setY((float) Math.random() * (stage.getHeight() - NUM_SPRITES * (32 + SPACING)));
group.setOrigin(loc, loc);
fillGroup(group, texture);
stage.addActor(group);
}
uiTexture = new Texture(Gdx.files.internal("data/ui.png"));
uiTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
ui = new Stage(new ScreenViewport());
Image blend = new Image(new TextureRegion(uiTexture, 0, 0, 64, 32));
blend.setAlign(Align.center);
blend.setScaling(Scaling.none);
blend.addListener(new InputListener() {
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
if (stage.getBatch().isBlendingEnabled())
stage.getBatch().disableBlending();
else
stage.getBatch().enableBlending();
return true;
}
});
blend.setY(ui.getHeight() - 64);
Image rotate = new Image(new TextureRegion(uiTexture, 64, 0, 64, 32));
rotate.setAlign(Align.center);
rotate.setScaling(Scaling.none);
rotate.addListener(new InputListener() {
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
rotateSprites = !rotateSprites;
return true;
}
});
rotate.setPosition(64, blend.getY());
Image scale = new Image(new TextureRegion(uiTexture, 64, 32, 64, 32));
scale.setAlign(Align.center);
scale.setScaling(Scaling.none);
scale.addListener(new InputListener() {
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
scaleSprites = !scaleSprites;
return true;
}
});
scale.setPosition(128, blend.getY());
{
Actor shapeActor = new Actor() {
public void drawDebug(ShapeRenderer shapes) {
shapes.set(ShapeType.Filled);
shapes.setColor(getColor());
shapes.rect(getX(), getY(), getOriginX(), getOriginY(), getWidth(), getHeight(), getScaleX(), getScaleY(), getRotation());
}
};
shapeActor.setBounds(0, 0, 100, 150);
shapeActor.setOrigin(50, 75);
shapeActor.debug();
sprites.add(shapeActor);
Group shapeGroup = new Group();
shapeGroup.setBounds(300, 300, 300, 300);
shapeGroup.setOrigin(50, 75);
shapeGroup.setTouchable(Touchable.childrenOnly);
shapeGroup.addActor(shapeActor);
stage.addActor(shapeGroup);
}
ui.addActor(blend);
ui.addActor(rotate);
ui.addActor(scale);
fps = new Label("fps: 0", new Label.LabelStyle(font, Color.WHITE));
fps.setPosition(10, 30);
fps.setColor(0, 1, 0, 1);
ui.addActor(fps);
renderer = new ShapeRenderer();
Gdx.input.setInputProcessor(this);
}
use of com.badlogic.gdx.scenes.scene2d.Actor in project libgdx by libgdx.
the class MusicTest method create.
@Override
public void create() {
music = Gdx.audio.newMusic(Gdx.files.internal("data/8.12.mp3"));
music.play();
buttons = new TextureRegion(new Texture(Gdx.files.internal("data/playback.png")));
batch = new SpriteBatch();
font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false);
stage = new Stage();
Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));
slider = new Slider(0, 100, 0.1f, false, skin);
slider.setPosition(200, 20);
slider.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
if (!sliderUpdating && slider.isDragging())
music.setPosition((slider.getValue() / 100f) * songDuration);
}
});
stage.addActor(slider);
Gdx.input.setInputProcessor(stage);
}
Aggregations