/** Clears the text. */ public void clear() { // Clear mesh builder.reset(); // Reset text position x = 0; y = 0; }
/** * Adds some text. * * @param text Text to add */ public void append(String text) { // Note current buffer position final int start = builder.getVertexCount(); // Build glyphs for (char ch : text.toCharArray()) { // Handle carriage returns if (ch == '\n') { newline(); continue; } // Determine width of this character final float w = font.getWidth(ch); // Start newline if wrapped if (x + w > width) { newline(); } // Build quad for glyph final Quad quad = new Quad(new Point(x * scale, y * scale, 0), w * scale, font.getHeight() * scale, false); quad.setColour(col); quad.setTextureCoords(font.getTextureCoords(ch)); // Add glyph builder.addQuad(quad.getVertices()); // Move to next glyph location x += w; } // Update mesh builder.build(start, builder.getVertexCount()); builder.flag = true; }
/** * Constructor. * * @param font Font properties */ public TextBuilder(TextureFont font) { Check.notNull(font); this.font = font; builder = new MeshBuilder(MeshLayout.create(Primitive.TRIANGLES, "+VC0", false)); builder.allocate(256); // TODO }