Class TextRenderer

java.lang.Object
lol.trq.helios.text.TextRenderer

public final class TextRenderer extends Object
Lays out and draws single lines of left-to-right text with kerning, through a ShapeBatch, so text and shapes share draw calls and stay in order.

With formatting on, § followed by a code changes the look of what follows: 0-9 and a-f set a colour (keeping the style's alpha) and clear the formats, l bold, o italic, n underline, m strikethrough, k obfuscated, r reset. Codes are not drawn and take no space. Positions are the top left of the line box; the baseline is ascent * size below it and is snapped to the pixel grid.

  • Field Details

    • PALETTE

      public static final int[] PALETTE
      The 16 colours of the §0-§f codes.
  • Constructor Details

    • TextRenderer

      public TextRenderer(GlBackend gl)
      Creates a renderer.
      Parameters:
      gl - the backend, for uploading font atlases
  • Method Details

    • draw

      public float draw(ShapeBatch batch, CharSequence text, float x, float y, TextStyle style)
      Draws a line of text into a batch that has begun.
      Parameters:
      batch - the batch
      text - the text
      x - left
      y - top of the line box
      style - the style
      Returns:
      the advance width of the text in drawing units
    • width

      public float width(CharSequence text, TextStyle style)
      Measures a line of text.
      Parameters:
      text - the text
      style - the style
      Returns:
      the advance width in drawing units
    • strip

      public static String strip(CharSequence text)
      Removes formatting codes.
      Parameters:
      text - text with § codes
      Returns:
      the text without them