Class BitmapFontCache

java.lang.Object
gaiasky.util.gdx.g2d.BitmapFontCache

public class BitmapFontCache
extends java.lang.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
    BitmapFontCache​(BitmapFont font)  
    BitmapFontCache​(BitmapFont font, boolean integer)  
  • Method Summary

    Modifier and Type Method Description
    void addText​(GlyphLayout layout, float x, float y)
    Adds the specified glyphs.
    GlyphLayout addText​(java.lang.CharSequence str, float x, float y)
    Adds glyphs for the specified text.
    GlyphLayout addText​(java.lang.CharSequence str, float x, float y, float targetWidth, int halign, boolean wrap)
    Adds glyphs for the specified text.
    GlyphLayout addText​(java.lang.CharSequence str, float x, float y, int start, int end, float targetWidth, int halign, boolean wrap)
    Adds glyphs for the specified text.
    GlyphLayout addText​(java.lang.CharSequence str, float x, float y, int start, int end, float targetWidth, int halign, boolean wrap, java.lang.String truncate)
    Adds glyphs for the the specified text.
    void clear()
    Removes all glyphs in the cache.
    void draw​(ExtBatch spriteBatch)  
    void draw​(ExtBatch spriteBatch, float alphaModulation)  
    void draw​(ExtBatch spriteBatch, int start, int end)  
    com.badlogic.gdx.graphics.Color getColor()
    Returns the color used for subsequently added text.
    BitmapFont getFont()  
    com.badlogic.gdx.utils.Array<GlyphLayout> getLayouts()  
    int getVertexCount​(int page)  
    float[] getVertices()  
    float[] getVertices​(int page)  
    float getX()
    Returns the x position of the cached string, relative to the position when the string was cached.
    float getY()
    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​(com.badlogic.gdx.graphics.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 setColors​(com.badlogic.gdx.graphics.Color tint)
    Sets the color of all text currently in the cache.
    void setColors​(com.badlogic.gdx.graphics.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.
    GlyphLayout setText​(java.lang.CharSequence str, float x, float y)
    Clears any cached glyphs and adds glyphs for the specified text.
    GlyphLayout setText​(java.lang.CharSequence str, float x, float y, float targetWidth, int halign, boolean wrap)
    Clears any cached glyphs and adds glyphs for the specified text.
    GlyphLayout setText​(java.lang.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.
    GlyphLayout setText​(java.lang.CharSequence str, float x, float y, int start, int end, float targetWidth, int halign, boolean wrap, java.lang.String truncate)
    Clears any cached glyphs and adds glyphs for the specified text.
    void setUseIntegerPositions​(boolean use)
    Specifies whether to use integer positions or not.
    void tint​(com.badlogic.gdx.graphics.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 usesIntegerPositions()  

    Methods inherited from class java.lang.Object

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

    • BitmapFontCache

      public BitmapFontCache​(BitmapFont font)
    • BitmapFontCache

      public BitmapFontCache​(BitmapFont 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​(com.badlogic.gdx.graphics.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​(com.badlogic.gdx.graphics.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​(com.badlogic.gdx.graphics.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 com.badlogic.gdx.graphics.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​(com.badlogic.gdx.graphics.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​(ExtBatch spriteBatch)
    • draw

      public void draw​(ExtBatch spriteBatch, int start, int end)
    • draw

      public void draw​(ExtBatch spriteBatch, float alphaModulation)
    • clear

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

      public GlyphLayout setText​(java.lang.CharSequence str, float x, float y)
      Clears any cached glyphs and adds glyphs for the specified text.
      See Also:
      addText(CharSequence, float, float, int, int, float, int, boolean, String)
    • setText

      public GlyphLayout setText​(java.lang.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:
      addText(CharSequence, float, float, int, int, float, int, boolean, String)
    • setText

      public GlyphLayout setText​(java.lang.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:
      addText(CharSequence, float, float, int, int, float, int, boolean, String)
    • setText

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

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

      public GlyphLayout addText​(java.lang.CharSequence str, float x, float y)
      Adds glyphs for the specified text.
      See Also:
      addText(CharSequence, float, float, int, int, float, int, boolean, String)
    • addText

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

      public GlyphLayout addText​(java.lang.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(CharSequence, float, float, int, int, float, int, boolean, String)
    • addText

      public GlyphLayout addText​(java.lang.CharSequence str, float x, float y, int start, int end, float targetWidth, int halign, boolean wrap, java.lang.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 BitmapFont 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.
      Parameters:
      use -
    • 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 com.badlogic.gdx.utils.Array<GlyphLayout> getLayouts()