Class FontCache

java.lang.Object
arc.graphics.g2d.FontCache

public class FontCache extends Object
Caches glyph geometry for a BitmapFont, providing a fast way to render static text. This saves needing to compute the glyph geometry each frame.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    FontCache(Font font, boolean integer)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addText(GlyphLayout layout, float x, float y)
    Adds the specified glyphs.
    addText(CharSequence str, float x, float y)
    Adds glyphs for the specified text.
    addText(CharSequence str, float x, float y, float targetWidth, int halign, boolean wrap)
    Adds glyphs for the specified text.
    addText(CharSequence str, float x, float y, int start, int end, float targetWidth, int halign, boolean wrap)
    Adds glyphs for the specified text.
    addText(CharSequence str, float x, float y, int start, int end, float targetWidth, int halign, boolean wrap, String truncate)
    Adds glyphs for the the specified text.
    void
    Removes all glyphs in the cache.
    void
     
    void
    draw(float alphaModulation)
     
    void
    draw(int start, int end)
     
    Returns the color used for subsequently added text.
     
     
    int
    getVertexCount(int page)
     
    float[]
     
    float[]
    getVertices(int page)
     
    float
    Returns the x position of the cached string, relative to the position when the string was cached.
    float
    Returns the y position of the cached string, relative to the position when the string was cached.
    void
    setAlphas(float alpha)
    Sets the alpha component of all text currently in the cache.
    void
    setColor(float r, float g, float b, float a)
    A convenience method for setting the cache color.
    void
    setColor(Color color)
    A convenience method for setting the cache color.
    void
    setColors(float color)
    Sets the color of all text currently in the cache.
    void
    setColors(float r, float g, float b, float a)
    Sets the color of all text currently in the cache.
    void
    setColors(float color, int start, int end)
    Sets the color of the specified characters.
    void
    Sets the color of all text currently in the cache.
    void
    setColors(Color tint, int start, int end)
    Sets the color of the specified characters.
    void
    setPosition(float x, float y)
    Sets the position of the text, relative to the position when the cached text was created.
    void
    setText(GlyphLayout layout, float x, float y)
    Clears any cached glyphs and adds the specified glyphs.
    setText(CharSequence str, float x, float y)
    Clears any cached glyphs and adds glyphs for the specified text.
    setText(CharSequence str, float x, float y, float targetWidth, int halign, boolean wrap)
    Clears any cached glyphs and adds glyphs for the specified text.
    setText(CharSequence str, float x, float y, int start, int end, float targetWidth, int halign, boolean wrap)
    Clears any cached glyphs and adds glyphs for the specified text.
    setText(CharSequence str, float x, float y, int start, int end, float targetWidth, int halign, boolean wrap, String truncate)
    Clears any cached glyphs and adds glyphs for the specified text.
    void
    Specifies whether to use integer positions or not.
    void
    tint(Color tint)
    Tints all text currently in the cache.
    void
    translate(float xAmount, float yAmount)
    Sets the position of the text, relative to its current position.
    boolean
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • FontCache

      public FontCache(Font font)
    • FontCache

      public FontCache(Font font, boolean integer)
      Parameters:
      integer - If true, rendering positions will be at integer values to avoid filtering artifacts.
  • Method Details

    • setPosition

      public void setPosition(float x, float y)
      Sets the position of the text, relative to the position when the cached text was created.
      Parameters:
      x - The x coordinate
      y - The y coordinate
    • translate

      public void translate(float xAmount, float yAmount)
      Sets the position of the text, relative to its current position.
      Parameters:
      xAmount - The amount in x to move the text
      yAmount - The amount in y to move the text
    • tint

      public void tint(Color tint)
      Tints all text currently in the cache. Does not affect subsequently added text.
    • setAlphas

      public void setAlphas(float alpha)
      Sets the alpha component of all text currently in the cache. Does not affect subsequently added text.
    • setColors

      public void setColors(float color)
      Sets the color of all text currently in the cache. Does not affect subsequently added text.
    • setColors

      public void setColors(Color tint)
      Sets the color of all text currently in the cache. Does not affect subsequently added text.
    • setColors

      public void setColors(float r, float g, float b, float a)
      Sets the color of all text currently in the cache. Does not affect subsequently added text.
    • setColors

      public void setColors(Color tint, int start, int end)
      Sets the color of the specified characters. This may only be called after setText(CharSequence, float, float) and is reset every time setText is called.
    • setColors

      public void setColors(float color, int start, int end)
      Sets the color of the specified characters. This may only be called after setText(CharSequence, float, float) and is reset every time setText is called.
    • getColor

      public Color getColor()
      Returns the color used for subsequently added text. Modifying the color affects text subsequently added to the cache, but does not affect existing text currently in the cache.
    • setColor

      public void setColor(Color color)
      A convenience method for setting the cache color. The color can also be set by modifying getColor().
    • setColor

      public void setColor(float r, float g, float b, float a)
      A convenience method for setting the cache color. The color can also be set by modifying getColor().
    • draw

      public void draw()
    • draw

      public void draw(int start, int end)
    • draw

      public void draw(float alphaModulation)
    • clear

      public void clear()
      Removes all glyphs in the cache.
    • setText

      public GlyphLayout setText(CharSequence str, float x, float y)
      Clears any cached glyphs and adds glyphs for the specified text.
      See Also:
    • setText

      public GlyphLayout setText(CharSequence str, float x, float y, float targetWidth, int halign, boolean wrap)
      Clears any cached glyphs and adds glyphs for the specified text.
      See Also:
    • setText

      public GlyphLayout setText(CharSequence str, float x, float y, int start, int end, float targetWidth, int halign, boolean wrap)
      Clears any cached glyphs and adds glyphs for the specified text.
      See Also:
    • setText

      public GlyphLayout setText(CharSequence str, float x, float y, int start, int end, float targetWidth, int halign, boolean wrap, String truncate)
      Clears any cached glyphs and adds glyphs for the specified text.
      See Also:
    • setText

      public void setText(GlyphLayout layout, float x, float y)
      Clears any cached glyphs and adds the specified glyphs.
      See Also:
    • addText

      public GlyphLayout addText(CharSequence str, float x, float y)
      Adds glyphs for the specified text.
      See Also:
    • addText

      public GlyphLayout addText(CharSequence str, float x, float y, float targetWidth, int halign, boolean wrap)
      Adds glyphs for the specified text.
      See Also:
    • addText

      public GlyphLayout addText(CharSequence str, float x, float y, int start, int end, float targetWidth, int halign, boolean wrap)
      Adds glyphs for the specified text.
      See Also:
    • addText

      public GlyphLayout addText(CharSequence str, float x, float y, int start, int end, float targetWidth, int halign, boolean wrap, String truncate)
      Adds glyphs for the the specified text.
      Parameters:
      x - The x position for the left most character.
      y - The y position for the top of most capital letters in the font (the cap height).
      start - The first character of the string to draw.
      end - The last character of the string to draw (exclusive).
      targetWidth - The width of the area the text will be drawn, for wrapping or truncation.
      halign - Horizontal alignment of the text, see Align.
      wrap - If true, the text will be wrapped within targetWidth.
      truncate - If not null, the text will be truncated within targetWidth with this string appended. May be an empty string.
      Returns:
      The glyph layout for the cached string (the layout's height is the distance from y to the baseline).
    • addText

      public void addText(GlyphLayout layout, float x, float y)
      Adds the specified glyphs.
    • getX

      public float getX()
      Returns the x position of the cached string, relative to the position when the string was cached.
    • getY

      public float getY()
      Returns the y position of the cached string, relative to the position when the string was cached.
    • getFont

      public Font getFont()
    • setUseIntegerPositions

      public void setUseIntegerPositions(boolean use)
      Specifies whether to use integer positions or not. Default is to use them so filtering doesn't kick in as badly.
    • usesIntegerPositions

      public boolean usesIntegerPositions()
      Returns:
      whether this font uses integer positions for drawing.
    • getVertices

      public float[] getVertices()
    • getVertices

      public float[] getVertices(int page)
    • getVertexCount

      public int getVertexCount(int page)
    • getLayouts

      public Seq<GlyphLayout> getLayouts()