Search in sources :

Example 6 with GlyphLayout

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

the class BitmapFontAlignmentTest method renderSingleLineCached.

private void renderSingleLineCached() {
    String text = "Single Line 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);
    cache.setColors(Color.BLUE, 1, 4);
    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 7 with GlyphLayout

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

the class BitmapFontAlignmentTest method create.

@Override
public void create() {
    Gdx.input.setInputProcessor(new InputAdapter() {

        public boolean touchDown(int x, int y, int pointer, int newParam) {
            renderMode = (renderMode + 1) % 6;
            return false;
        }
    });
    spriteBatch = new SpriteBatch();
    texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));
    logoSprite = new Sprite(texture);
    logoSprite.setColor(1, 1, 1, 0.6f);
    logoSprite.setBounds(50, 100, 400, 100);
    font = new BitmapFont(Gdx.files.getFileHandle("data/verdana39.fnt", FileType.Internal), Gdx.files.getFileHandle("data/verdana39.png", FileType.Internal), false);
    cache = font.newFontCache();
    layout = new GlyphLayout();
}
Also used : Sprite(com.badlogic.gdx.graphics.g2d.Sprite) InputAdapter(com.badlogic.gdx.InputAdapter) GlyphLayout(com.badlogic.gdx.graphics.g2d.GlyphLayout) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Texture(com.badlogic.gdx.graphics.Texture)

Example 8 with GlyphLayout

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

the class BitmapFontMetricsTest method render.

@Override
public void render() {
    // red.a = (red.a + Gdx.graphics.getDeltaTime() * 0.1f) % 1;
    int viewHeight = Gdx.graphics.getHeight();
    Gdx.gl.glClearColor(1, 1, 1, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    spriteBatch.begin();
    // String text = "Sphinx of black quartz, judge my vow.";
    String text = "Sphinx of black quartz.";
    font.setColor(Color.RED);
    float x = 100, y = 100;
    float alignmentWidth;
    smallFont.setColor(Color.BLACK);
    smallFont.draw(spriteBatch, "draw position", 20, viewHeight - 0);
    smallFont.setColor(Color.BLUE);
    smallFont.draw(spriteBatch, "bounds", 20, viewHeight - 20);
    smallFont.setColor(Color.MAGENTA);
    smallFont.draw(spriteBatch, "baseline", 20, viewHeight - 40);
    smallFont.setColor(Color.GREEN);
    smallFont.draw(spriteBatch, "x height", 20, viewHeight - 60);
    smallFont.setColor(Color.CYAN);
    smallFont.draw(spriteBatch, "ascent", 20, viewHeight - 80);
    smallFont.setColor(Color.RED);
    smallFont.draw(spriteBatch, "descent", 20, viewHeight - 100);
    smallFont.setColor(Color.ORANGE);
    smallFont.draw(spriteBatch, "line height", 20, viewHeight - 120);
    smallFont.setColor(Color.LIGHT_GRAY);
    smallFont.draw(spriteBatch, "cap height", 20, viewHeight - 140);
    font.setColor(Color.BLACK);
    GlyphLayout layout = font.draw(spriteBatch, text, x, y);
    spriteBatch.end();
    renderer.begin(ShapeType.Filled);
    renderer.setColor(Color.BLACK);
    renderer.rect(x - 3, y - 3, 6, 6);
    renderer.end();
    float baseline = y - font.getCapHeight();
    renderer.begin(ShapeType.Line);
    renderer.setColor(Color.LIGHT_GRAY);
    renderer.line(0, y, 9999, y);
    renderer.setColor(Color.MAGENTA);
    renderer.line(0, baseline, 9999, baseline);
    renderer.setColor(Color.GREEN);
    renderer.line(0, baseline + font.getXHeight(), 9999, baseline + font.getXHeight());
    renderer.setColor(Color.CYAN);
    renderer.line(0, y + font.getAscent(), 9999, y + font.getAscent());
    renderer.setColor(Color.RED);
    renderer.line(0, baseline + font.getDescent(), 9999, baseline + font.getDescent());
    renderer.setColor(Color.ORANGE);
    renderer.line(0, y - font.getLineHeight(), 9999, y - font.getLineHeight());
    renderer.end();
    renderer.begin(ShapeType.Line);
    renderer.setColor(Color.BLUE);
    renderer.rect(x, y, layout.width, -layout.height);
    renderer.end();
}
Also used : GlyphLayout(com.badlogic.gdx.graphics.g2d.GlyphLayout)

Example 9 with GlyphLayout

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

the class FreeTypeMetricsTest method render.

@Override
public void render() {
    // red.a = (red.a + Gdx.graphics.getDeltaTime() * 0.1f) % 1;
    int viewHeight = Gdx.graphics.getHeight();
    Gdx.gl.glClearColor(1, 1, 1, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    spriteBatch.begin();
    // String text = "Sphinx of black quartz, judge my vow.";
    String text = "Sphinx of black quartz.";
    font.setColor(Color.RED);
    float x = 20, y = 200;
    float alignmentWidth;
    smallFont.setColor(Color.BLACK);
    smallFont.draw(spriteBatch, "draw position", 20, viewHeight - 0);
    smallFont.setColor(Color.BLUE);
    smallFont.draw(spriteBatch, "bounds", 20, viewHeight - 20);
    smallFont.setColor(Color.MAGENTA);
    smallFont.draw(spriteBatch, "baseline", 20, viewHeight - 40);
    smallFont.setColor(Color.GREEN);
    smallFont.draw(spriteBatch, "x height", 20, viewHeight - 60);
    smallFont.setColor(Color.CYAN);
    smallFont.draw(spriteBatch, "ascent", 20, viewHeight - 80);
    smallFont.setColor(Color.RED);
    smallFont.draw(spriteBatch, "descent", 20, viewHeight - 100);
    smallFont.setColor(Color.ORANGE);
    smallFont.draw(spriteBatch, "line height", 20, viewHeight - 120);
    smallFont.setColor(Color.LIGHT_GRAY);
    smallFont.draw(spriteBatch, "cap height", 20, viewHeight - 140);
    font.setColor(Color.BLACK);
    GlyphLayout layout = font.draw(spriteBatch, text, x, y);
    spriteBatch.end();
    renderer.begin(ShapeType.Filled);
    renderer.setColor(Color.BLACK);
    renderer.rect(x - 3, y - 3, 6, 6);
    renderer.end();
    float baseline = y - font.getCapHeight();
    renderer.begin(ShapeType.Line);
    renderer.setColor(Color.LIGHT_GRAY);
    renderer.line(0, y, 9999, y);
    renderer.setColor(Color.MAGENTA);
    renderer.line(0, baseline, 9999, baseline);
    renderer.setColor(Color.GREEN);
    renderer.line(0, baseline + font.getXHeight(), 9999, baseline + font.getXHeight());
    renderer.setColor(Color.CYAN);
    renderer.line(0, y + font.getAscent(), 9999, y + font.getAscent());
    renderer.setColor(Color.RED);
    renderer.line(0, baseline + font.getDescent(), 9999, baseline + font.getDescent());
    renderer.setColor(Color.ORANGE);
    renderer.line(0, y - font.getLineHeight(), 9999, y - font.getLineHeight());
    renderer.end();
    renderer.begin(ShapeType.Line);
    renderer.setColor(Color.BLUE);
    renderer.rect(x, y, layout.width, -layout.height);
    renderer.end();
}
Also used : GlyphLayout(com.badlogic.gdx.graphics.g2d.GlyphLayout)

Example 10 with GlyphLayout

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

the class Texto method mostratMensaje.

public void mostratMensaje(SpriteBatch batch, String mensaje, float x, float y, float r, float g, float b) {
    glyph = new GlyphLayout(font, mensaje, new Color(r, g, b, 1), 1000f, 1, true);
    float anchoText = glyph.width;
    font.draw(batch, glyph, x - anchoText / 2, y);
}
Also used : Color(com.badlogic.gdx.graphics.Color) 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