Package gaiasky.util.gdx.g2d
Class BitmapFontCache
java.lang.Object
gaiasky.util.gdx.g2d.BitmapFontCache
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
ConstructorDescriptionBitmapFontCache(BitmapFont font)
BitmapFontCache(BitmapFont font, boolean integer)
-
Method Summary
Modifier and TypeMethodDescriptionvoid
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
clear()
Removes all glyphs in the cache.void
void
void
com.badlogic.gdx.graphics.Color
getColor()
Returns the color used for subsequently added text.getFont()
com.badlogic.gdx.utils.Array<GlyphLayout>
int
getVertexCount(int page)
float[]
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.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
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
-
Constructor Details
-
BitmapFontCache
-
BitmapFontCache
- 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 coordinatey
- 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 textyAmount
- 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 aftersetText(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 aftersetText(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 modifyinggetColor()
. -
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 modifyinggetColor()
. -
draw
-
draw
-
draw
-
clear
public void clear()Removes all glyphs in the cache. -
setText
Clears any cached glyphs and adds glyphs for the specified text. -
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. -
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. -
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. -
setText
Clears any cached glyphs and adds the specified glyphs. -
addText
Adds glyphs for the specified text. -
addText
public GlyphLayout addText(CharSequence str, float x, float y, float targetWidth, int halign, boolean wrap)Adds glyphs for the specified text. -
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. -
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 (thecap 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, seeAlign
.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
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
-
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
-