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);
}
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();
}
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();
}
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();
}
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);
}
Aggregations