Search in sources :

Example 16 with GlyphLayout

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();
}
Also used : GlyphLayout(com.badlogic.gdx.graphics.g2d.GlyphLayout)

Example 17 with GlyphLayout

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();
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle) GlyphLayout(com.badlogic.gdx.graphics.g2d.GlyphLayout)

Example 18 with GlyphLayout

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();
    }
}
Also used : Drawable(com.badlogic.gdx.scenes.scene2d.utils.Drawable) GlyphLayout(com.badlogic.gdx.graphics.g2d.GlyphLayout) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont)

Example 19 with GlyphLayout

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);
}
Also used : GlyphLayout(com.badlogic.gdx.graphics.g2d.GlyphLayout)

Example 20 with GlyphLayout

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);
}
Also used : GlyphLayout(com.badlogic.gdx.graphics.g2d.GlyphLayout)

Aggregations

GlyphLayout (com.badlogic.gdx.graphics.g2d.GlyphLayout)24 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)8 Drawable (com.badlogic.gdx.scenes.scene2d.utils.Drawable)5 Color (com.badlogic.gdx.graphics.Color)2 Sprite (com.badlogic.gdx.graphics.g2d.Sprite)2 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)2 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)2 ListStyle (com.badlogic.gdx.scenes.scene2d.ui.List.ListStyle)2 ScrollPaneStyle (com.badlogic.gdx.scenes.scene2d.ui.ScrollPane.ScrollPaneStyle)2 ReverseListIterator (org.apache.commons.collections.iterators.ReverseListIterator)2 InputAdapter (com.badlogic.gdx.InputAdapter)1 FileHandle (com.badlogic.gdx.files.FileHandle)1 Texture (com.badlogic.gdx.graphics.Texture)1 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)1 FreeTypeFontGenerator (com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator)1 FreeTypeFontParameter (com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter)1 ShapeRenderer (com.badlogic.gdx.graphics.glutils.ShapeRenderer)1 Stage (com.badlogic.gdx.scenes.scene2d.Stage)1 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)1 Window (com.badlogic.gdx.scenes.scene2d.ui.Window)1