use of com.badlogic.gdx.graphics.g2d.GlyphLayout in project bladecoder-adventure-engine by bladecoder.
the class Message method add.
private static void add(Stage stage, String text) {
msg.clearActions();
msg.setText(text);
GlyphLayout textLayout = new GlyphLayout();
textLayout.setText(msg.getStyle().font, text, Color.BLACK, stage.getWidth() * .8f, Align.center, true);
msg.setSize(textLayout.width + textLayout.height, textLayout.height + textLayout.height * 2);
if (!stage.getActors().contains(msg, true))
stage.addActor(msg);
msg.setPosition(Math.round((stage.getWidth() - msg.getWidth()) / 2), Math.round((stage.getHeight() - msg.getHeight()) / 2));
msg.invalidate();
}
use of com.badlogic.gdx.graphics.g2d.GlyphLayout in project Mindustry by Anuken.
the class FileChooser method updateFiles.
private void updateFiles(boolean push) {
if (push)
stack.push(directory);
navigation.setText(directory.toString());
GlyphLayout layout = Pools.obtain(GlyphLayout.class);
layout.setText(Core.font, navigation.getText());
if (layout.width < navigation.getWidth()) {
navigation.setCursorPosition(0);
} else {
navigation.setCursorPosition(navigation.getText().length());
}
Pools.free(layout);
files.clearChildren();
FileHandle[] names = getFileNames();
Image upimage = new Image("icon-folder-parent");
TextButton upbutton = new TextButton(".." + directory.toString());
upbutton.clicked(() -> {
directory = directory.parent();
updateFiles(true);
});
upbutton.left().add(upimage).padRight(4f).size(14 * 2);
upbutton.getCells().reverse();
files.top().left().add(upbutton).align(Align.topLeft).fillX().expandX().height(50).pad(2).colspan(2);
upbutton.getLabel().setAlignment(Align.left);
files.row();
ButtonGroup<TextButton> group = new ButtonGroup<TextButton>();
group.setMinCheckCount(0);
for (FileHandle file : names) {
// skip non-filtered files
if (!file.isDirectory() && !filter.test(file))
continue;
String filename = file.name();
TextButton button = new TextButton(shorten(filename), "toggle");
group.add(button);
button.clicked(() -> {
if (!file.isDirectory()) {
filefield.setText(filename);
updateFileFieldStatus();
} else {
directory = directory.child(filename);
updateFiles(true);
}
});
filefield.changed(() -> {
button.setChecked(filename.equals(filefield.getText()));
});
Image image = new Image(file.isDirectory() ? "icon-folder" : "icon-file-text");
button.add(image).padRight(4f).size(14 * 2f);
button.getCells().reverse();
files.top().left().add(button).align(Align.topLeft).fillX().expandX().height(50).pad(2).padTop(0).padBottom(0).colspan(2);
button.getLabel().setAlignment(Align.left);
files.row();
}
pane.setScrollY(0f);
updateFileFieldStatus();
if (open)
filefield.clearText();
}
use of com.badlogic.gdx.graphics.g2d.GlyphLayout in project libgdx by libgdx.
the class List method layout.
public void layout() {
final BitmapFont font = style.font;
final Drawable selectedDrawable = style.selection;
itemHeight = font.getCapHeight() - font.getDescent() * 2;
itemHeight += selectedDrawable.getTopHeight() + selectedDrawable.getBottomHeight();
textOffsetX = selectedDrawable.getLeftWidth();
textOffsetY = selectedDrawable.getTopHeight() - font.getDescent();
prefWidth = 0;
Pool<GlyphLayout> layoutPool = Pools.get(GlyphLayout.class);
GlyphLayout layout = layoutPool.obtain();
for (int i = 0; i < items.size; i++) {
layout.setText(font, toString(items.get(i)));
prefWidth = Math.max(layout.width, prefWidth);
}
layoutPool.free(layout);
prefWidth += selectedDrawable.getLeftWidth() + selectedDrawable.getRightWidth();
prefHeight = items.size * itemHeight;
Drawable background = style.background;
if (background != null) {
prefWidth += background.getLeftWidth() + background.getRightWidth();
prefHeight += background.getTopHeight() + background.getBottomHeight();
}
}
use of com.badlogic.gdx.graphics.g2d.GlyphLayout in project libgdx by libgdx.
the class BitmapFontAlignmentTest method renderWrappedCached.
private void renderWrappedCached() {
String text = "Wrapped Cached Wrapped Cached";
float x = logoSprite.getX();
float y = logoSprite.getY();
float width = logoSprite.getWidth();
float height = logoSprite.getHeight();
// Obviously you wouldn't set the cache text every frame in real code.
GlyphLayout layout = cache.setText(text, 0, 0, width, Align.left, true);
// Note that wrapped text can be aligned:
// cache.setWrappedText(text, 0, 0, width, HAlignment.CENTER);
x += width / 2 - layout.width / 2;
y += height / 2 + layout.height / 2;
cache.setPosition(x, y);
cache.draw(spriteBatch);
}
use of com.badlogic.gdx.graphics.g2d.GlyphLayout in project libgdx by libgdx.
the class BitmapFontAlignmentTest method renderMultiLineCached.
private void renderMultiLineCached() {
String text = "Multi Line\nCached";
int lines = 2;
float x = logoSprite.getX();
float y = logoSprite.getY();
float width = logoSprite.getWidth();
float height = logoSprite.getHeight();
// Obviously you wouldn't set the cache text every frame in real code.
GlyphLayout layout = cache.setText(text, 0, 0);
// Note that multi line text can be aligned:
// cache.setText(text, 0, 0, width, Align.center, false);
x += width / 2 - layout.width / 2;
y += height / 2 + layout.height / 2;
cache.setPosition(x, y);
cache.draw(spriteBatch);
}
Aggregations