Search in sources :

Example 11 with GlyphLayout

use of com.badlogic.gdx.graphics.g2d.GlyphLayout in project ultimate-java by pantinor.

the class BookScreen method addPages.

private void addPages(BitmapFont font, int pageStart, String fn, Label.LabelStyle labs) {
    try {
        List<String> lines = FileUtils.readLines(Gdx.files.internal(fn).file());
        int page = pageStart;
        GlyphLayout gl = new GlyphLayout(font, "");
        StringBuilder sb = new StringBuilder();
        for (String line : lines) {
            sb.append(line).append("\n");
            gl.setText(font, sb.toString().trim(), Color.WHITE, 450, Align.left, true);
            if (gl.height > 600) {
                labels.add(new Label(sb.toString().trim(), labs));
                sb = new StringBuilder();
                page++;
            }
        }
        labels.add(new Label(sb.toString().trim(), labs));
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : Label(com.badlogic.gdx.scenes.scene2d.ui.Label) GlyphLayout(com.badlogic.gdx.graphics.g2d.GlyphLayout) IOException(java.io.IOException)

Example 12 with GlyphLayout

use of com.badlogic.gdx.graphics.g2d.GlyphLayout in project ultimate-java by pantinor.

the class DeathScreen method render.

@Override
public void render(float delta) {
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    long diff = System.currentTimeMillis() - initTime;
    long secs = diff / 1000;
    int index = (int) (secs / 4);
    if (index >= deathMsgs.length) {
        mainGame.setScreen(returnScreen);
    } else {
        String s = deathMsgs[index];
        batch.begin();
        float x = Ultima4.SCREEN_WIDTH / 2 - 320;
        float y = 300;
        float width = 640;
        float height = 50;
        GlyphLayout layout = new GlyphLayout(font, s, Color.WHITE, width, Align.left, true);
        x += width / 2 - layout.width / 2;
        y += height / 2 + layout.height / 2;
        font.draw(batch, layout, x, y);
        batch.end();
    }
}
Also used : GlyphLayout(com.badlogic.gdx.graphics.g2d.GlyphLayout)

Example 13 with GlyphLayout

use of com.badlogic.gdx.graphics.g2d.GlyphLayout in project ultimate-java by pantinor.

the class CodexLogDisplay method render.

public void render(Batch batch) {
    batch.draw(logbkgrnd, 200, 500);
    int h = 20;
    float y = 500 + 10;
    synchronized (logs) {
        ReverseListIterator iter = new ReverseListIterator(logs);
        while (iter.hasNext()) {
            String next = (String) iter.next();
            GlyphLayout layout = new GlyphLayout(font, next, Color.WHITE, width - 20, Align.left, true);
            y = y + layout.height + 4;
            h += layout.height + 4;
            if (h > height + 20) {
                break;
            }
            font.draw(batch, layout, 220, y);
        }
    }
}
Also used : GlyphLayout(com.badlogic.gdx.graphics.g2d.GlyphLayout) ReverseListIterator(org.apache.commons.collections.iterators.ReverseListIterator)

Example 14 with GlyphLayout

use of com.badlogic.gdx.graphics.g2d.GlyphLayout in project ultimate-java by pantinor.

the class LogDisplay method render.

public void render(Batch batch, Party party) {
    int food = party.getSaveGame().food / 100;
    font.setColor(food < 5 ? Color.RED : Color.WHITE);
    font.draw(batch, "Food  " + food, LOG_X + 8, 438);
    font.setColor(Color.WHITE);
    if (party.getContext().getTransportContext() == TransportContext.SHIP) {
        font.draw(batch, "Hull  " + party.getSaveGame().shiphull, LOG_X + 8 + 120, 438);
    } else {
        font.draw(batch, "Gold  " + party.getSaveGame().gold, LOG_X + 8 + 140, 438);
    }
    float y = Ultima4.SCREEN_HEIGHT - 48;
    for (int i = 0; i < party.getMembers().size(); i++) {
        PartyMember pm = party.getMember(i);
        String s = (i + 1) + " - " + pm.getPlayer().name;
        String d = pm.getPlayer().hp + "" + pm.getPlayer().status.getValue();
        font.setColor(i == party.getActivePlayer() ? new Color(.35f, .93f, 0.91f, 1) : Color.WHITE);
        if (pm.getPlayer().status == StatusType.POISONED) {
            font.setColor(Color.GREEN);
        }
        if (pm.getPlayer().status == StatusType.SLEEPING) {
            font.setColor(Color.YELLOW);
        }
        if (pm.getPlayer().status == StatusType.DEAD) {
            font.setColor(Color.GRAY);
        }
        font.draw(batch, s, LOG_X + 8, y);
        font.draw(batch, d, LOG_X + 8 + 110, y);
        y = y - 24;
    }
    font.setColor(Color.WHITE);
    y = 32;
    synchronized (logs) {
        ReverseListIterator iter = new ReverseListIterator(logs);
        while (iter.hasNext()) {
            String next = (String) iter.next();
            GlyphLayout layout = new GlyphLayout(font, next, Color.WHITE, LOG_AREA_WIDTH - 8, Align.left, true);
            y += layout.height + 10;
            if (y > LOG_AREA_TOP) {
                break;
            }
            font.draw(batch, layout, LOG_X + 8, y);
        }
    }
}
Also used : PartyMember(objects.Party.PartyMember) Color(com.badlogic.gdx.graphics.Color) GlyphLayout(com.badlogic.gdx.graphics.g2d.GlyphLayout) ReverseListIterator(org.apache.commons.collections.iterators.ReverseListIterator)

Example 15 with GlyphLayout

use of com.badlogic.gdx.graphics.g2d.GlyphLayout in project bladecoder-adventure-engine by bladecoder.

the class FilteredSelectBox method layout.

@Override
public void layout() {
    Drawable bg = style.background;
    BitmapFont font = style.font;
    if (bg != null) {
        prefHeight = Math.max(bg.getTopHeight() + bg.getBottomHeight() + font.getCapHeight() - font.getDescent() * 2, bg.getMinHeight());
    } else
        prefHeight = font.getCapHeight() - font.getDescent() * 2;
    float maxItemWidth = 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)));
        maxItemWidth = Math.max(layout.width, maxItemWidth);
    }
    layoutPool.free(layout);
    prefWidth = maxItemWidth;
    if (bg != null)
        prefWidth += bg.getLeftWidth() + bg.getRightWidth();
    ListStyle listStyle = style.listStyle;
    ScrollPaneStyle scrollStyle = style.scrollStyle;
    float listWidth = maxItemWidth + listStyle.selection.getLeftWidth() + listStyle.selection.getRightWidth();
    if (scrollStyle.background != null)
        listWidth += scrollStyle.background.getLeftWidth() + scrollStyle.background.getRightWidth();
    if (selectBoxList == null || !selectBoxList.isScrollingDisabledY())
        listWidth += Math.max(style.scrollStyle.vScroll != null ? style.scrollStyle.vScroll.getMinWidth() : 0, style.scrollStyle.vScrollKnob != null ? style.scrollStyle.vScrollKnob.getMinWidth() : 0);
    prefWidth = Math.max(prefWidth, listWidth);
}
Also used : ListStyle(com.badlogic.gdx.scenes.scene2d.ui.List.ListStyle) Drawable(com.badlogic.gdx.scenes.scene2d.utils.Drawable) GlyphLayout(com.badlogic.gdx.graphics.g2d.GlyphLayout) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) ScrollPaneStyle(com.badlogic.gdx.scenes.scene2d.ui.ScrollPane.ScrollPaneStyle)

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