Search in sources :

Example 21 with GlyphLayout

use of com.badlogic.gdx.graphics.g2d.GlyphLayout in project libgdx by libgdx.

the class BitmapFontTest method create.

@Override
public void create() {
    spriteBatch = new SpriteBatch();
    // font = new BitmapFont(Gdx.files.internal("data/verdana39.fnt"), false);
    font = new BitmapFont(Gdx.files.internal("data/arial-32-pad.fnt"), false);
    // font = new FreeTypeFontGenerator(Gdx.files.internal("data/arial.ttf")).generateFont(new FreeTypeFontParameter());
    font.getData().markupEnabled = true;
    font.getData().breakChars = new char[] { '-' };
    multiPageFont = new BitmapFont(Gdx.files.internal("data/multipagefont.fnt"));
    // Add user defined color
    Colors.put("PERU", Color.valueOf("CD853F"));
    renderer = new ShapeRenderer();
    renderer.setProjectionMatrix(spriteBatch.getProjectionMatrix());
    stage = new Stage(new ScreenViewport());
    Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    BitmapFont labelFont = skin.get("default-font", BitmapFont.class);
    labelFont.getData().markupEnabled = true;
    // Notice that the last [] has been deliberately added to test the effect of excessive pop operations.
    // They are silently ignored, as expected.
    label = new Label("<<[BLUE]M[RED]u[YELLOW]l[GREEN]t[OLIVE]ic[]o[]l[]o[]r[]*[MAROON]Label[][] [Unknown Color]>>", skin);
    label.setPosition(100, 200);
    stage.addActor(label);
    Window window = new Window("[RED]Multicolor[GREEN] Title", skin);
    window.setPosition(400, 300);
    window.pack();
    stage.addActor(window);
    layout = new GlyphLayout();
}
Also used : Window(com.badlogic.gdx.scenes.scene2d.ui.Window) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) ScreenViewport(com.badlogic.gdx.utils.viewport.ScreenViewport) GlyphLayout(com.badlogic.gdx.graphics.g2d.GlyphLayout) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) ShapeRenderer(com.badlogic.gdx.graphics.glutils.ShapeRenderer)

Example 22 with GlyphLayout

use of com.badlogic.gdx.graphics.g2d.GlyphLayout in project Mindustry by Anuken.

the class Renderer method drawPlayerNames.

void drawPlayerNames() {
    GlyphLayout layout = Pools.obtain(GlyphLayout.class);
    Draw.tscl(0.25f / 2);
    for (Player player : playerGroup.all()) {
        if (!player.isLocal && !player.isDead()) {
            layout.setText(Core.font, player.name);
            Draw.color(0f, 0f, 0f, 0.3f);
            Draw.rect("blank", player.x, player.y + 8 - layout.height / 2, layout.width + 2, layout.height + 2);
            Draw.color();
            Draw.tcolor(player.getColor());
            Draw.text(player.name, player.x, player.y + 8);
            if (player.isAdmin) {
                Draw.color(player.getColor());
                float s = 3f;
                Draw.rect("icon-admin-small", player.x + layout.width / 2f + 2 + 1, player.y + 7f, s, s);
            }
            Draw.reset();
        }
    }
    Pools.free(layout);
    Draw.tscl(fontscale);
}
Also used : Player(io.anuke.mindustry.entities.Player) GlyphLayout(com.badlogic.gdx.graphics.g2d.GlyphLayout)

Example 23 with GlyphLayout

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

the class CustomList method layout.

public void layout() {
    final BitmapFont font = style.font;
    final BitmapFont subfont = style.subtitleFont;
    final Drawable selectedDrawable = style.selection;
    cellRenderer.layout(style);
    GlyphLayout textLayout = new GlyphLayout();
    prefWidth = 0;
    for (int i = 0; i < items.size; i++) {
        textLayout.setText(font, cellRenderer.getCellTitle(items.get(i)));
        prefWidth = Math.max(textLayout.width, prefWidth);
        if (cellRenderer.hasImage()) {
            TextureRegion r = cellRenderer.getCellImage(items.get(i));
            float ih = r.getRegionHeight();
            float iw = r.getRegionWidth();
            if (ih > getItemHeight() - 10) {
                ih = getItemHeight() - 10;
                iw *= ih / r.getRegionHeight();
            }
            prefWidth = Math.max(iw + textLayout.width, prefWidth);
        }
        if (cellRenderer.hasSubtitle()) {
            String subtitle = cellRenderer.getCellSubTitle(items.get(i));
            if (subtitle != null) {
                textLayout.setText(subfont, subtitle);
                prefWidth = Math.max(textLayout.width, prefWidth);
            }
        }
    }
    prefWidth += selectedDrawable.getLeftWidth() + selectedDrawable.getRightWidth();
    prefHeight = items.size * cellRenderer.getItemHeight();
    Drawable background = style.background;
    if (background != null) {
        prefWidth += background.getLeftWidth() + background.getRightWidth();
        prefHeight += background.getTopHeight() + background.getBottomHeight();
    }
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) Drawable(com.badlogic.gdx.scenes.scene2d.utils.Drawable) GlyphLayout(com.badlogic.gdx.graphics.g2d.GlyphLayout) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont)

Example 24 with GlyphLayout

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

the class StartScreen method render.

@Override
public void render(float delta) {
    time += Gdx.graphics.getDeltaTime();
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    float x = Ultima4.SCREEN_WIDTH / 2 - 320;
    float y = 100;
    float width = 640;
    float height = 50;
    if (state == State.INIT) {
        camera.update();
        splashRenderer.setView(camera.combined, 0, 0, 19 * tilePixelWidth, 5 * tilePixelHeight);
        splashRenderer.render();
        batch.begin();
        batch.draw(title, 0, 0);
        font.draw(batch, "In another world, in a time to come.", 320, Ultima4.SCREEN_HEIGHT - 295);
        font.draw(batch, "LIBGDX Conversion by Paul Antinori", 300, 84);
        font.draw(batch, "Copyright 1987 Lord British", 350, 48);
        batch.draw(beast1.getKeyFrame(time, true), 0, Ultima4.SCREEN_HEIGHT - 31 * 2, 48 * 2, 31 * 2);
        batch.draw(beast2.getKeyFrame(time, true), Ultima4.SCREEN_WIDTH - 48 * 2, Ultima4.SCREEN_HEIGHT - 31 * 2, 48 * 2, 31 * 2);
        batch.end();
        stage.act();
        stage.draw();
    } else if (state == State.ASK_NAME) {
        batch.begin();
        batch.draw(title, 0, 0);
        font.draw(batch, "By what name shalt thou be known", 320, 315);
        font.draw(batch, "in this world and time?", 320, 290);
        font.draw(batch, nameBuffer.toString(), 320, 265);
        batch.draw(beast1.getKeyFrame(time, true), 0, Ultima4.SCREEN_HEIGHT - 31 * 2, 48 * 2, 31 * 2);
        batch.draw(beast2.getKeyFrame(time, true), Ultima4.SCREEN_WIDTH - 48 * 2, Ultima4.SCREEN_HEIGHT - 31 * 2, 48 * 2, 31 * 2);
        batch.end();
        Gdx.input.setInputProcessor(nia);
    } else if (state == State.ASK_SEX) {
        batch.begin();
        batch.draw(title, 0, 0);
        font.draw(batch, "Art thou Male or Female?", 320, 315);
        font.draw(batch, sexBuffer.toString(), 320, 275);
        batch.draw(beast1.getKeyFrame(time, true), 0, Ultima4.SCREEN_HEIGHT - 31 * 2, 48 * 2, 31 * 2);
        batch.draw(beast2.getKeyFrame(time, true), Ultima4.SCREEN_WIDTH - 48 * 2, Ultima4.SCREEN_HEIGHT - 31 * 2, 48 * 2, 31 * 2);
        batch.end();
        Gdx.input.setInputProcessor(sia);
    } else if (state == State.TELL_STORY) {
        if (storyInd == 0) {
            storyTexture = ta.findRegion("tree");
        } else if (storyInd == 6) {
            storyTexture = ta.findRegion("portal");
        } else if (storyInd == 11) {
            storyTexture = ta.findRegion("tree");
        } else if (storyInd == 15) {
            storyTexture = ta.findRegion("outside");
        } else if (storyInd == 17) {
            storyTexture = ta.findRegion("inside");
        } else if (storyInd == 20) {
            storyTexture = ta.findRegion("wagon");
        } else if (storyInd == 21) {
            storyTexture = ta.findRegion("gypsy");
        } else if (storyInd == 23) {
            storyTexture = ta.findRegion("abacus");
        }
        batch.begin();
        batch.draw(beast1.getKeyFrame(time, true), 0, Ultima4.SCREEN_HEIGHT - 31 * 2, 48 * 2, 31 * 2);
        batch.draw(beast2.getKeyFrame(time, true), Ultima4.SCREEN_WIDTH - 48 * 2, Ultima4.SCREEN_HEIGHT - 31 * 2, 48 * 2, 31 * 2);
        batch.draw(storyTexture, Ultima4.SCREEN_WIDTH / 2 - 320, 200, 640, 304);
        GlyphLayout layout = new GlyphLayout(font, initScripts[storyInd], 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();
        Gdx.input.setInputProcessor(stia);
    } else if (state == State.ASK_QUESTIONS || state == State.DONE) {
        batch.begin();
        batch.draw(beast1.getKeyFrame(time, true), 0, Ultima4.SCREEN_HEIGHT - 31 * 2, 48 * 2, 31 * 2);
        batch.draw(beast2.getKeyFrame(time, true), Ultima4.SCREEN_WIDTH - 48 * 2, Ultima4.SCREEN_HEIGHT - 31 * 2, 48 * 2, 31 * 2);
        batch.draw(storyTexture, Ultima4.SCREEN_WIDTH / 2 - 320, 200, 640, 304);
        for (Sprite b : beads) {
            batch.draw(b, b.getX(), b.getY(), 16, 24);
        }
        if (questionRound > 6) {
            questionRound = 6;
        }
        String v1 = Virtue.get(questionTree[questionRound * 2]).toString().toLowerCase();
        String v2 = Virtue.get(questionTree[questionRound * 2 + 1]).toString().toLowerCase();
        batch.draw(ta.findRegion(v1), 225, 232, 178, 244);
        batch.draw(ta.findRegion(v2), 625, 232, 178, 244);
        if (state == State.ASK_QUESTIONS) {
            if (pauseFlag) {
                StringBuffer sb = new StringBuffer();
                sb.append(gypsyText[questionRound == 0 ? GYP_PLACES_FIRST : (questionRound == 6 ? GYP_PLACES_LAST : GYP_PLACES_TWOMORE)]);
                sb.append(gypsyText[GYP_UPON_TABLE]);
                sb.append(String.format("%s and %s.  She says", gypsyText[questionTree[questionRound * 2] + 4], gypsyText[questionTree[questionRound * 2 + 1] + 4]));
                sb.append("\nConsider this:");
                String text = sb.toString();
                GlyphLayout layout = new GlyphLayout(font, text, Color.WHITE, width, Align.left, true);
                x += width / 2 - layout.width / 2;
                y += height / 2 + layout.height / 2;
                font.draw(batch, layout, x, y);
            } else {
                GlyphLayout layout = new GlyphLayout(font, currentQuestion, Color.WHITE, width, Align.left, true);
                x += width / 2 - layout.width / 2;
                y += height / 2 + layout.height / 2;
                font.draw(batch, layout, x, y);
            }
            Gdx.input.setInputProcessor(qia);
        } else {
            GlyphLayout layout = new GlyphLayout(font, gypsyText[storyInd], Color.WHITE, width, Align.left, true);
            x += width / 2 - layout.width / 2;
            y += height / 2 + layout.height / 2;
            font.draw(batch, layout, x, y);
            Gdx.input.setInputProcessor(dia);
        }
        batch.end();
    }
}
Also used : Sprite(com.badlogic.gdx.graphics.g2d.Sprite) 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