Package squidpony.squidgrid.gui.gdx
Class TextCellFactory
java.lang.Object
squidpony.squidgrid.gui.gdx.TextCellFactory
- All Implemented Interfaces:
com.badlogic.gdx.utils.Disposable
- Direct Known Subclasses:
TextFamily
public class TextCellFactory extends Object implements com.badlogic.gdx.utils.Disposable
Class for creating text blocks.
This class defaults to having no padding and having no font set. You can use a
default square or narrow font by calling the appropriate method, or set the font
to any AngelCode bitmap font on the classpath (typically in libGDX, this would be
in the assets folder; these fonts can be created by Hiero in the libGDX tools,
see https://github.com/libgdx/libgdx/wiki/Hiero for more)
After all settings are set, one of the initialization methods must be called
before the factory can be used.
In order to easily support Unicode, strings are treated as a series of code
points.
All images have transparent backgrounds.
- Author:
- Eben Howard - http://squidpony.com - howard@squidpony.com, Tommy Ettinger
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
TextCellFactory.Glyph
A kind of Actor for one char (with one color) that is innately drawn with a specific TextCellFactory, and will match the layout behavior of that TextCellFactory when it is used for other purposes. -
Field Summary
Fields Modifier and Type Field Description float
actualCellHeight
float
actualCellWidth
protected com.badlogic.gdx.assets.AssetManager
assetManager
TheAssetManager
from where to load the font.protected com.badlogic.gdx.graphics.g2d.TextureRegion
block
com.badlogic.gdx.graphics.g2d.BitmapFont
bmpFont
protected int
bottomPadding
static String
DEFAULT_FITTING
The commonly used symbols in roguelike games.protected float
descent
protected char
directionGlyph
protected com.badlogic.gdx.graphics.g2d.TextureRegion
dirMarker
protected boolean
distanceField
protected float
distanceFieldScaleX
protected float
distanceFieldScaleY
protected String
fitting
protected OrderedMap<Character,com.badlogic.gdx.graphics.g2d.TextureRegion>
glyphTextures
protected float
height
protected boolean
initialized
protected boolean
initializedByFont
protected boolean
initializedBySize
protected int
leftPadding
protected float
lineHeight
protected boolean
msdf
protected StringBuilder
mut
protected int
rightPadding
protected IColorCenter<com.badlogic.gdx.graphics.Color>
scc
com.badlogic.gdx.graphics.glutils.ShaderProgram
shader
For distance field and MSDF fonts, this is the ShaderProgram that will produce the intended effect.protected float
smoothingMultiplier
static String
SQUID_FITTING
All symbols that squidlib-util permits itself to generate; this is a shared subset across most of the larger fonts inDefaultResources
.protected com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle
style
protected regexodus.ds.CharCharMap
swap
protected int
topPadding
protected float
width
-
Constructor Summary
Constructors Constructor Description TextCellFactory()
Creates a default valued factory.TextCellFactory(com.badlogic.gdx.assets.AssetManager assetManager)
A default valued factory that uses the givenAssetManager
to load the font file. -
Method Summary
Modifier and Type Method Description TextCellFactory
addFit(String fit)
Adds the code points in the string to the list of characters that will be guaranteed to fit.TextCellFactory
addSwap(char find, char replace)
Adds a pair of chars as a replacement pair, so when the find char is requested to be drawn, the replace char is used instead.TextCellFactory
addSwap(String find, String replace)
Adds a pair of Strings (typically both with length 1) as a replacement pair, so when the find String is requested to be drawn, the replace String is used instead.TextCellFactory
addSwaps(OrderedMap<Character,Character> swaps)
Appends to the mapping of replacement pairs, adding or replacing any entries in the current mapping with the entries in a Map of Character keys to String values.boolean
antialias()
Returns whether this factory is currently set to do antialiasing on the characters rendered, which is always true.TextCellFactory
antialias(boolean antialias)
Deprecated.AA is the wave of the future!int
bottomPadding()
Returns the padding on the bottom side.TextCellFactory
bottomPadding(int padding)
Sets the amount of padding on the bottom side to the provided value.TextCellFactory
clearSwaps()
Clears all replacement pairs this has been told to swap.void
configureShader(com.badlogic.gdx.graphics.g2d.Batch batch)
If using a distance field font, you MUST call this at some point while the batch has begun, or use code that calls it for you (which is now much of SquidLib).TextCellFactory
copy()
TextCellFactory
defaultDistanceFieldFont()
Sets the TextCellFactory to use a square distance field font that will resize to whatever size you request.TextCellFactory
defaultFont()
Sets this factory to use a default 12x24 font that supports Latin, Greek, Cyrillic, and many more, including box-drawing characters, zodiac signs, playing-card suits, and chess piece symbols.TextCellFactory
defaultNarrowDistanceFieldFont()
Sets the TextCellFactory to use a half-square distance field font that will resize to whatever size you request.TextCellFactory
defaultNarrowFont()
Sets this factory to use a default 12x24 font that renders very accurately, with no gaps between box-drawing characters and very geometric lines.TextCellFactory
defaultSquareFont()
Sets this factory to use a default 12x12 font, which...void
dispose()
Releases all resources of this object.void
draw(com.badlogic.gdx.graphics.g2d.Batch batch, char c, float x, float y)
Use the specified Batch to draw a char with the default color (white), with x and y determining the world-space coordinates for the upper-left corner.void
draw(com.badlogic.gdx.graphics.g2d.Batch batch, char c, float encodedColor, float x, float y)
Use the specified Batch to draw a String (often just one char long) in the specified LibGDX Color, with x and y determining the world-space coordinates for the upper-left corner.void
draw(com.badlogic.gdx.graphics.g2d.Batch batch, char c, com.badlogic.gdx.graphics.Color color, float x, float y)
Use the specified Batch to draw a char in the specified LibGDX Color, with x and y determining the world-space coordinates for the upper-left corner.void
draw(com.badlogic.gdx.graphics.g2d.Batch batch, float[][] encodedColors, float x, float y)
Draws a 2D array of floats that represent encoded colors, with each float used for a block of color the size of one character cell (it will beactualCellWidth
byactualCellHeight
in size, using world units).void
draw(com.badlogic.gdx.graphics.g2d.Batch batch, float[][] encodedColors, float x, float y, int xSubCells, int ySubCells)
Draws a 2D array of floats that represent encoded colors, with each float used for a block of color that will be a fraction of the size of one character cell (it will beactualCellWidth
divided byxSubCells
byactualCellHeight
divided byySubCells
in size, using world units).void
draw(com.badlogic.gdx.graphics.g2d.Batch batch, com.badlogic.gdx.graphics.g2d.TextureRegion tr, float x, float y)
Use the specified Batch to draw a TextureRegion with the default tint color (white, so un-tinted), with x and y determining the world-space coordinates for the upper-left corner.void
draw(com.badlogic.gdx.graphics.g2d.Batch batch, com.badlogic.gdx.graphics.g2d.TextureRegion tr, float encodedColor, float x, float y)
Use the specified Batch to draw a TextureRegion tinted with the specified encoded color as a float, with x and y determining the world-space coordinates for the upper-left corner.void
draw(com.badlogic.gdx.graphics.g2d.Batch batch, com.badlogic.gdx.graphics.g2d.TextureRegion tr, float x, float y, float width, float height)
Use the specified Batch to draw a TextureRegion with the default tint color (white, so un-tinted), with x and y determining the world-space coordinates for the upper-left corner.void
draw(com.badlogic.gdx.graphics.g2d.Batch batch, com.badlogic.gdx.graphics.g2d.TextureRegion tr, float encodedColor, float x, float y, float width, float height)
Use the specified Batch to draw a TextureRegion tinted with the specified LibGDX Color, with x and y determining the world-space coordinates for the upper-left corner.void
draw(com.badlogic.gdx.graphics.g2d.Batch batch, com.badlogic.gdx.graphics.g2d.TextureRegion tr, float r, float g, float b, float a, float x, float y)
Use the specified Batch to draw a TextureRegion tinted with the specified rgba color, with x and y determining the world-space coordinates for the upper-left corner.void
draw(com.badlogic.gdx.graphics.g2d.Batch batch, com.badlogic.gdx.graphics.g2d.TextureRegion tr, float r, float g, float b, float a, float x, float y, float width, float height)
Use the specified Batch to draw a TextureRegion tinted with the specified rgba color, with x and y determining the world-space coordinates for the upper-left corner.void
draw(com.badlogic.gdx.graphics.g2d.Batch batch, com.badlogic.gdx.graphics.g2d.TextureRegion tr, com.badlogic.gdx.graphics.Color color, float x, float y)
Use the specified Batch to draw a TextureRegion tinted with the specified LibGDX Color, with x and y determining the world-space coordinates for the upper-left corner.void
draw(com.badlogic.gdx.graphics.g2d.Batch batch, com.badlogic.gdx.graphics.g2d.TextureRegion tr, com.badlogic.gdx.graphics.Color color, float x, float y, float width, float height)
Use the specified Batch to draw a TextureRegion tinted with the specified LibGDX Color, with x and y determining the world-space coordinates for the upper-left corner.void
draw(com.badlogic.gdx.graphics.g2d.Batch batch, CharSequence s, float x, float y)
Use the specified Batch to draw a String or other CharSequence (often just one char long) with the default color (white), with x and y determining the world-space coordinates for the upper-left corner.void
draw(com.badlogic.gdx.graphics.g2d.Batch batch, CharSequence s, float encodedColor, float x, float y)
Use the specified Batch to draw a String or other CharSequence (often just one char long) in the specified LibGDX Color, with x and y determining the world-space coordinates for the upper-left corner.void
draw(com.badlogic.gdx.graphics.g2d.Batch batch, CharSequence s, float r, float g, float b, float a, float x, float y)
Use the specified Batch to draw a String or other CharSequence (often just one char long) in the specified rgba color, with x and y determining the world-space coordinates for the upper-left corner.void
draw(com.badlogic.gdx.graphics.g2d.Batch batch, CharSequence s, com.badlogic.gdx.graphics.Color color, float x, float y)
Use the specified Batch to draw a String or other CharSequence (often just one char long) in the specified LibGDX Color, with x and y determining the world-space coordinates for the upper-left corner.void
draw(com.badlogic.gdx.graphics.Pixmap pixmap, float[][] encodedColors)
Given a Pixmap and a 2D float array, uses each float in the array as an encoded color for a pixel in the Pixmap at a location determined by the float's position in the array.String
fit()
Returns the current String of code points that are used for sizing the cells.TextCellFactory
fit(String fit)
Sets the characters that will be guaranteed to fit to the provided ones.com.badlogic.gdx.graphics.g2d.BitmapFont
font()
Returns theBitmapFont
used by this factory.TextCellFactory
font(com.badlogic.gdx.graphics.g2d.BitmapFont bitmapFont)
Sets this factory to use the provided BitmapFont as its font without re-constructing anything.TextCellFactory
font(String fontpath)
Sets this factory to use the provided font.TextCellFactory
fontDistanceField(String fontPath, String texturePath)
Sets the font to a distance field font with the given String path to a .fnt file and String path to a texture.TextCellFactory
fontMultiDistanceField(String fontPath, String texturePath)
regexodus.ds.CharCharMap
getAllSwaps()
Gets the current mapping of "swaps", or replacement pairs, to replace keys requested for drawing with their values in theCharCharMap
.float
getDescent()
Gets the descent of this TextCellFactory's BitmapFont, which may be useful for layout outside this class.char
getDirectionGlyph()
float
getDistanceFieldScaleX()
float
getDistanceFieldScaleY()
float
getSmoothingMultiplier()
If this uses a distance field font, the smoothing multiplier affects how crisp or blurry lines are, with higher numbers generally resulting in more crisp fonts, but numbers that are too high cause jagged aliasing.com.badlogic.gdx.graphics.g2d.TextureRegion
getSolid()
Returns a solid block of white, 1x1 pixel in size; can be drawn at other sizes by Batch.TextCellFactory.Glyph
glyph(char shown, float encodedColor, float x, float y)
Gets a Glyph with the given char to show, color as a packed float, and position as x and y in world coordinates.TextCellFactory.Glyph
glyph(char shown, com.badlogic.gdx.graphics.Color color, float x, float y)
Gets a Glyph with the given char to show, libGDX Color, and position as x and y in world coordinates.float
height()
Returns the height of a single cell.TextCellFactory
height(float height)
Sets the factory's cell height to the provided value.TextCellFactory
includedFont()
Sets this factory to use the one font included with libGDX, which is Arial at size 15 px.TextCellFactory
initByFont()
Initializes the factory to then be able to create text cells on demand.TextCellFactory
initBySize()
Initializes the factory to then be able to create text cells on demand.boolean
initialized()
Returns true if this factory is fully initialized and ready to build text cells.TextCellFactory
initVerbatim()
Identical toinitBySize()
.boolean
isDistanceField()
boolean
isMultiDistanceField()
int
leftPadding()
Returns the padding on the left side.TextCellFactory
leftPadding(int padding)
Sets the amount of padding on the left side to the provided value.com.badlogic.gdx.scenes.scene2d.Actor
makeActor(char c, float encodedColor)
Converts a char into a Label, or if the argument c is '\0', creates an Image of a solid block.com.badlogic.gdx.scenes.scene2d.Actor
makeActor(char c, com.badlogic.gdx.graphics.Color color)
Converts a char into a Label, or if the argument c is '\0', creates an Image of a solid block.com.badlogic.gdx.scenes.scene2d.Actor
makeActor(char c, Collection<com.badlogic.gdx.graphics.Color> colors)
Converts a char into a ColorChangeLabel, or if the argument c is '\0', creates a ColorChangeImage of a solid block.com.badlogic.gdx.scenes.scene2d.Actor
makeActor(char c, Collection<com.badlogic.gdx.graphics.Color> colors, float loopTime)
Converts a char into a ColorChangeLabel, or if the argument c is '\0', creates a ColorChangeImage of a solid block.com.badlogic.gdx.scenes.scene2d.Actor
makeActor(char c, Collection<com.badlogic.gdx.graphics.Color> colors, float loopTime, boolean doubleWidth)
Converts a char into a ColorChangeLabel, or if the argument c is '\0', creates a ColorChangeImage of a solid block.com.badlogic.gdx.scenes.scene2d.Actor
makeActor(com.badlogic.gdx.graphics.g2d.TextureRegion tr, com.badlogic.gdx.graphics.Color color)
Converts a TextureRegion into an Image, or if the argument s is null, creates an Image of a solid block.com.badlogic.gdx.scenes.scene2d.Actor
makeActor(com.badlogic.gdx.graphics.g2d.TextureRegion tr, com.badlogic.gdx.graphics.Color color, float width, float height)
Converts a TextureRegion into an Image, or if the argument s is null, creates an Image of a solid block.com.badlogic.gdx.scenes.scene2d.Actor
makeActor(com.badlogic.gdx.graphics.g2d.TextureRegion tr, Collection<com.badlogic.gdx.graphics.Color> colors)
com.badlogic.gdx.scenes.scene2d.Actor
makeActor(com.badlogic.gdx.graphics.g2d.TextureRegion tr, Collection<com.badlogic.gdx.graphics.Color> colors, float loopTime)
com.badlogic.gdx.scenes.scene2d.Actor
makeActor(com.badlogic.gdx.graphics.g2d.TextureRegion tr, Collection<com.badlogic.gdx.graphics.Color> colors, float loopTime, boolean doubleWidth)
Converts a TextureRegion into a ColorChangeImage that will cycle through the given colors.com.badlogic.gdx.scenes.scene2d.Actor
makeActor(com.badlogic.gdx.graphics.g2d.TextureRegion tr, Collection<com.badlogic.gdx.graphics.Color> colors, float loopTime, boolean doubleWidth, float width, float height)
Converts a TextureRegion into a ColorChangeImage that will cycle through the given colors.com.badlogic.gdx.scenes.scene2d.Actor
makeActor(String s, com.badlogic.gdx.graphics.Color color)
Converts a String into a Label, or if the argument s is null, creates an Image of a solid block.com.badlogic.gdx.scenes.scene2d.Actor
makeActor(String s, Collection<com.badlogic.gdx.graphics.Color> colors)
Converts a String into a ColorChangeLabel, or if the argument s is null, creates a ColorChangeImage of a solid block.com.badlogic.gdx.scenes.scene2d.Actor
makeActor(String s, Collection<com.badlogic.gdx.graphics.Color> colors, float loopTime)
Converts a String into a ColorChangeLabel, or if the argument s is null, creates a ColorChangeImage of a solid block.com.badlogic.gdx.scenes.scene2d.Actor
makeActor(String s, Collection<com.badlogic.gdx.graphics.Color> colors, float loopTime, boolean doubleWidth)
Converts a String into a ColorChangeLabel, or if the argument s is null, creates a ColorChangeImage of a solid block.com.badlogic.gdx.scenes.scene2d.ui.Image
makeDirectionMarker(com.badlogic.gdx.graphics.Color color)
Creates a Image Actor that should look like the glyph '^' in this font, but will be rotate-able.com.badlogic.gdx.scenes.scene2d.ui.Image
makeDirectionMarker(Collection<com.badlogic.gdx.graphics.Color> colors, float loopTime, boolean doubleWidth)
Creates a ColorChangeImage Actor that should look like the glyph '^' in this font, but will be rotate-able.ColorChangeImage
makeGlyphImage(char glyph, com.badlogic.gdx.graphics.Color color)
Given a char and a Color, makes a ColorChangeImage of that colored char so it can be rotated and so on.ColorChangeImage
makeGlyphImage(char glyph, com.badlogic.gdx.graphics.Color color, boolean doubleWidth)
Given a char and a Color, makes a ColorChangeImage of that colored char so it can be rotated and so on.ColorChangeImage
makeGlyphImage(char glyph, Collection<com.badlogic.gdx.graphics.Color> colors, float loopTime, boolean doubleWidth)
Given a char and a Collection of Color (such as a List that might be produced bySquidColorCenter.gradient(Color, Color)
), makes a ColorChangeImage of that char so it can be rotated and so on.com.badlogic.gdx.scenes.scene2d.ui.Label
makeWrappingString(String s)
Converts a String into a Label, or if the argument s is null, creates an Image of a solid block.TextCellFactory
padding(int padding)
Sets the amount of padding on all sides to the provided value.TextCellFactory
removeSwap(char find)
Removes the replacement pair, if present, that searches for the given key, find.TextCellFactory
removeSwap(String find)
Removes the replacement pair, if present, that searches for the given key, find.TextCellFactory
resetSize()
Acts like callinginitBySize()
, but doesn't create new ShaderPrograms or other objects if this has already been initialized.TextCellFactory
resetSize(float newWidth, float newHeight)
Acts like callingwidth(float)
,height(float)
, andinitBySize()
in succession, but doesn't create new ShaderPrograms or other objects if this has already been initialized.int
rightPadding()
Returns the padding on the right side.TextCellFactory
rightPadding(int padding)
Sets the amount of padding on the right side to the provided value.TextCellFactory
setAllSwaps(OrderedMap<Character,Character> swaps)
Sets the mapping of replacement pairs to a different one as a Map of Character keys to String values.TextCellFactory
setColorCenter(IColorCenter<com.badlogic.gdx.graphics.Color> icc)
TextCellFactory
setDirectionGlyph(char directionGlyph)
TextCellFactory
setSmoothingMultiplier(float smoothingMultiplier)
If this uses a distance field font, the smoothing multiplier affects how crisp or blurry lines are, with higher numbers generally resulting in more crisp fonts, but numbers that are too high cause jagged aliasing.void
setStyle(int style)
Not implemented in this class; in subclasses that do, this should change the currently-used font style, such as from regular to italic or bold.int
supportedStyles()
How many styles are supported by this TextCellFactory; always 1 unless changed in a subclass.int
topPadding()
Returns the padding on the top side.TextCellFactory
topPadding(int padding)
Sets the amount of padding on the top side to the provided value.TextCellFactory
tweakHeight(float height)
Sets the factory's height used for text to the provided value, but does not change the size of a cell.TextCellFactory
tweakWidth(float width)
Sets the factory's height used for text to the provided value, but does not change the size of a cell.float
width()
Returns the width of a single cell.TextCellFactory
width(float width)
Sets the factory's cell width to the provided value.boolean
willFit(int codepoint)
Returns true if the given character will fit inside the current cell dimensions with the current font.
-
Field Details
-
DEFAULT_FITTING
The commonly used symbols in roguelike games.- See Also:
- Constant Field Values
-
SQUID_FITTING
All symbols that squidlib-util permits itself to generate; this is a shared subset across most of the larger fonts inDefaultResources
.- See Also:
- Constant Field Values
-
assetManager
TheAssetManager
from where to load the font. Use it to share loading of a font's file across multiple factories. -
bmpFont
-
block
-
dirMarker
-
fitting
-
scc
-
leftPadding
-
rightPadding
-
topPadding
-
bottomPadding
-
width
-
height
-
actualCellWidth
-
actualCellHeight
-
distanceFieldScaleX
-
distanceFieldScaleY
-
initialized
-
initializedByFont
-
initializedBySize
-
distanceField
-
msdf
-
shader
For distance field and MSDF fonts, this is the ShaderProgram that will produce the intended effect. Usually should not be changed manually unless you know what you are doing. -
smoothingMultiplier
-
descent
-
lineHeight
-
style
-
swap
-
directionGlyph
-
glyphTextures
-
mut
-
-
Constructor Details
-
TextCellFactory
public TextCellFactory()Creates a default valued factory. One of the initialization methods must be called before this factory can be used! -
TextCellFactory
A default valued factory that uses the givenAssetManager
to load the font file. Use this constructor if you are likely to load the same font over and over (recall that, without anAssetManager
, each instance ofTextCellFactory
will load its font from disk). This primarily matters if you are using fonts not bundled with SquidLib, since accessing a BitmapFont with a method (not a String) from DefaultResources caches the BitmapFont already.- Parameters:
assetManager
- an ordinary libGDX AssetManager
-
-
Method Details
-
supportedStyles
How many styles are supported by this TextCellFactory; always 1 unless changed in a subclass. -
copy
-
initByFont
Initializes the factory to then be able to create text cells on demand.
Will match the width and height to the space width of the font and the line height of the font, respectively. Calling this after the factory has already been initialized will re-initialize it. This will not work with distance field or MSDF fonts; for those, useinitBySize()
.- Returns:
- this for method chaining
-
initBySize
Initializes the factory to then be able to create text cells on demand.
Will strictly use the provided width and height values to size the cells. Calling this after the factory has already been initialized will re-initialize it, but will re-create several objects (including compiling a ShaderProgram, which can be very challenging for a GPU to do each frame). If you need to re-initialize often to adjust size, useresetSize()
, which does not allocate new objects if this was already initialized, and will just delegate to this method if this wasn't initialized.- Returns:
- this for method chaining
-
resetSize
Acts like callinginitBySize()
, but doesn't create new ShaderPrograms or other objects if this has already been initialized. If this has not been initialized, simply returns initBySize(). This method is safe to call every frame if the font size continually changes, where initBySize() is not.- Returns:
- this for chaining
-
resetSize
Acts like callingwidth(float)
,height(float)
, andinitBySize()
in succession, but doesn't create new ShaderPrograms or other objects if this has already been initialized. If this has not been initialized, calls width() and height() and then simply returns initBySize(). This method is safe to call every frame if the font size continually changes, where initBySize() is not.- Parameters:
newWidth
- the new width of a single cell, as a float that usually corresponds to pixelsnewHeight
- the new height of a single cell, as a float that usually corresponds to pixels- Returns:
- this for chaining
-
initVerbatim
Identical toinitBySize()
.- Returns:
- this for method chaining
- See Also:
The docs for initBySize() apply here.
-
font
Returns theBitmapFont
used by this factory.- Returns:
- the BitmapFont this uses
-
font
Sets this factory to use the provided font. This is a way to complete a needed step; the font must be set before initializing, which can be done by a few methods in this class. This should be called with an argument such as "Rogue-Zodiac-6x12.fnt", that is, it should have the .fnt extension as opposed to the .png that accompanies such a bitmap font. The bitmap font should be either in the internal folder that libGDX knows about, which means it is in the assets folder of your project usually. These BitmapFont resources are already known by SquidLib, but may need separate downloads (detailed in the linked DefaultResources documentation):DefaultResources.getDefaultFont()
= "Zodiac-Square-12x12.fnt"DefaultResources.getDefaultNarrowFont()
= "Rogue-Zodiac-6x12.fnt"DefaultResources.getDefaultUnicodeFont()
= "Mandrill-6x16.fnt"DefaultResources.getSmoothFont()
= "Inconsolata-LGC-8x18.fnt"DefaultResources.getLargeFont()
= "Zodiac-Square-24x24.fnt"DefaultResources.getLargeNarrowFont()
= "Rogue-Zodiac-12x24.fnt"DefaultResources.getLargeUnicodeFont()
= "Mandrill-12x32.fnt"DefaultResources.getLargeSmoothFont()
= "Inconsolata-LGC-12x24.fnt"DefaultResources.getExtraLargeNarrowFont()
= "Rogue-Zodiac-18x36.fnt"
See https://github.com/libgdx/libgdx/wiki/Hiero for some ways to create a bitmap font this can use. Several fonts in this list were created using Hiero (not Hiero4), and several were created with AngelCode's BMFont tool.- Parameters:
fontpath
- the path to the font to use- Returns:
- this factory for method chaining
-
font
Sets this factory to use the provided BitmapFont as its font without re-constructing anything. This is a way to complete a needed step; the font must be set before initializing, which can be done by a few methods in this class. This should be called with an argument such asDefaultResources.getDefaultFont()
or any other variable with BitmapFont as its type. The bitmap font will not be loaded from file with this method, which it would be if you called the overload of font() that takes a String more than once. These BitmapFont resources are already known by SquidLib, but may need separate downloads (detailed in the linked DefaultResources documentation):DefaultResources.getDefaultFont()
= "Zodiac-Square-12x12.fnt"DefaultResources.getDefaultNarrowFont()
= "Rogue-Zodiac-6x12.fnt"DefaultResources.getDefaultUnicodeFont()
= "Mandrill-6x16.fnt"DefaultResources.getSmoothFont()
= "Inconsolata-LGC-8x18.fnt"DefaultResources.getLargeFont()
= "Zodiac-Square-24x24.fnt"DefaultResources.getLargeNarrowFont()
= "Rogue-Zodiac-12x24.fnt"DefaultResources.getLargeUnicodeFont()
= "Mandrill-12x32.fnt"DefaultResources.getLargeSmoothFont()
= "Inconsolata-LGC-12x24.fnt"DefaultResources.getExtraLargeNarrowFont()
= "Rogue-Zodiac-18x36.fnt"
See https://github.com/libgdx/libgdx/wiki/Hiero for some ways to create a bitmap font this can use. Several fonts in this list were created using Hiero (not Hiero4), and several were created with AngelCode's BMFont tool.- Parameters:
bitmapFont
- the BitmapFont this should use- Returns:
- this factory for method chaining
-
fontDistanceField
Sets the font to a distance field font with the given String path to a .fnt file and String path to a texture. Distance field fonts should scale cleanly to multiple resolutions without artifacts. Does not use AssetManager since you shouldn't need to reload the font if it scales with one image. You need to configure the shader to use distance field fonts unless a class already does this for you (SquidLayers handles shader configuration internally, for example). TextCellFactory has a method, configureShader(Batch), that does this and should be called while that Batch has begun rendering, typically in an override of some containing Scene2D Group's draw(Batch, float) method.
At least two distance field fonts are included in SquidLib; one is square, one is narrow, and they can both be accessed using either the predefined TextCellFactory objects in DefaultResources, accessible with getStretchableFont() for narrow or getStretchableSquareFont() for square, or the setter methods in this class, defaultDistanceFieldFont() for square and defaultNarrowDistanceFieldFont() for narrow.
To create distance field fonts that work well with monospace layout is... time-consuming and error-prone, though not especially difficult for most fonts. The process is documented as well as we can, given how differently all fonts are made, in a file not included in the distribution JAR but present on GitHub: Instructions here. A separate project is dedicated to automating this process somewhat, Glamer; Glamer can also produce MSDF fonts.- Parameters:
fontPath
- the path to a .fnt bitmap font file with distance field effects applied, which requires a complex process to create.texturePath
- the path to the texture used by the bitmap font- Returns:
- this factory for method chaining
-
fontMultiDistanceField
- Parameters:
fontPath
- the path to a .fnt bitmap font file with multi-channel distance field effects applied, which requires a complex process to create.texturePath
- the path to the texture used by the bitmap font- Returns:
- this factory for method chaining
-
includedFont
Sets this factory to use the one font included with libGDX, which is Arial at size 15 px. Does it correctly display when used in a grid? Probably not as well as you'd hope. You should probably get some of the assets that accompany SquidLib, and can be downloaded directly from GitHub (not available as one monolithic jar via Maven Central, but that lets you pick and choose individual assets). Get a .fnt and its matching .png file from https://github.com/SquidPony/SquidLib/tree/master/assets and you can pass them tofont(String)
orfontDistanceField(String, String)
.- Returns:
- this factory for method chaining
-
defaultFont
Sets this factory to use a default 12x24 font that supports Latin, Greek, Cyrillic, and many more, including box-drawing characters, zodiac signs, playing-card suits, and chess piece symbols. This is enough to support the output of anything that DungeonUtility can make for a dungeon or FakeLanguageGen can make for text with its defaults, which is difficult for any font to do. The box-drawing characters in this don't quite line up, and in some colors there may appear to be gaps (white text on black backgrounds will show it, but not much else). This is a way to complete a needed step; the font must be set before initializing, which can be done by a few methods in this class.- Returns:
- this factory for method chaining
-
defaultNarrowFont
Sets this factory to use a default 12x24 font that renders very accurately, with no gaps between box-drawing characters and very geometric lines. This is a way to complete a needed step; the font must be set before initializing, which can be done by a few methods in this class.- Returns:
- this factory for method chaining
-
defaultSquareFont
Sets this factory to use a default 12x12 font, which... is square, and doesn't look as bad as many square fonts do, plus it supports box-drawing characters with no gaps. This is a way to complete a needed step; the font must be set before initializing, which can be done by a few methods in this class.- Returns:
- this factory for method chaining
-
defaultDistanceFieldFont
Sets the TextCellFactory to use a square distance field font that will resize to whatever size you request. You must configure the shader if you use a distance field font, unless a class does it for you, like SquidLayers. The configureShader(Batch) method of this class can be used to set up the shader if you don't use SquidLayers; see its docs for more information.- Returns:
- this TextCellFactory set to use a square distance field font
-
defaultNarrowDistanceFieldFont
Sets the TextCellFactory to use a half-square distance field font that will resize to whatever size you request. You must configure the shader if you use a distance field font, unless a class does it for you, like SquidLayers. The configureShader(Batch) method of this class can be used to set up the shader if you don't use SquidLayers; see its docs for more information.- Returns:
- this TextCellFactory set to use a half-square distance field font
-
width
Returns the width of a single cell.- Returns:
- the width
-
width
Sets the factory's cell width to the provided value. Clamps at 1 on the lower bound to ensure valid calculations.- Parameters:
width
- the desired width- Returns:
- this factory for method chaining
-
height
Returns the height of a single cell.- Returns:
- the height of a single cell
-
height
Sets the factory's cell height to the provided value. Clamps at 1 on the lower bound to ensure valid calculations.- Parameters:
height
- the desired width- Returns:
- this factory for method chaining
-
tweakWidth
Sets the factory's height used for text to the provided value, but does not change the size of a cell. Clamps at 1 on the lower bound to ensure valid calculations.- Parameters:
width
- the desired width- Returns:
- this factory for method chaining
-
tweakHeight
Sets the factory's height used for text to the provided value, but does not change the size of a cell. Clamps at 1 on the lower bound to ensure valid calculations.- Parameters:
height
- the desired height- Returns:
- this factory for method chaining
-
fit
Returns the current String of code points that are used for sizing the cells. Note that this is actually a set of codepoints and treating them as an array of chars might give undesired results.- Returns:
- the String used for sizing calculations
-
fit
Sets the characters that will be guaranteed to fit to the provided ones. This will override any previously set string.- Parameters:
fit
- the String of code points to size to- Returns:
- this factory for method chaining
-
addFit
Adds the code points in the string to the list of characters that will be guaranteed to fit.- Parameters:
fit
- the String of code points to size to- Returns:
- this factory for method chaining
-
antialias
Returns whether this factory is currently set to do antialiasing on the characters rendered, which is always true.- Returns:
- true if antialiasing is set, so, always
-
antialias
Deprecated.AA is the wave of the future!All fonts will be rendered with antialiasing, this doesn't do anything.- Parameters:
antialias
- ignored, will always use antialiasing- Returns:
- this factory for method chaining
-
padding
Sets the amount of padding on all sides to the provided value.- Parameters:
padding
- how much padding in pixels- Returns:
- this for method chaining
-
leftPadding
Returns the padding on the left side.- Returns:
- amount of padding in pixels
-
leftPadding
Sets the amount of padding on the left side to the provided value.- Parameters:
padding
- how much padding in pixels- Returns:
- this for method chaining
-
rightPadding
Returns the padding on the right side.- Returns:
- amount of padding in pixels
-
rightPadding
Sets the amount of padding on the right side to the provided value.- Parameters:
padding
- how much padding in pixels- Returns:
- this for method chaining
-
topPadding
Returns the padding on the top side.- Returns:
- amount of padding in pixels
-
topPadding
Sets the amount of padding on the top side to the provided value.- Parameters:
padding
- how much padding in pixels- Returns:
- this for method chaining
-
bottomPadding
Returns the padding on the bottom side.- Returns:
- amount of padding in pixels
-
bottomPadding
Sets the amount of padding on the bottom side to the provided value.- Parameters:
padding
- how much padding in pixels- Returns:
- this for method chaining
-
setColorCenter
- Parameters:
icc
- The color center to use. Should not benull
.- Returns:
this
- Throws:
NullPointerException
- Ificc
isnull
.
-
initialized
Returns true if this factory is fully initialized and ready to build text cells.- Returns:
- true if initialized
-
willFit
Returns true if the given character will fit inside the current cell dimensions with the current font. ISO Control characters, non-printing characters and invalid unicode characters are all considered by definition to fit.- Parameters:
codepoint
- the codepoint of the char in question- Returns:
- true if the char will fit, or if it is non-printing in some way; false otherwise
-
draw
Use the specified Batch to draw a String or other CharSequence (often just one char long) with the default color (white), with x and y determining the world-space coordinates for the upper-left corner.- Parameters:
batch
- the LibGDX Batch to do the drawings
- the string to draw, often but not necessarily one char. Can be null to draw a solid block instead.x
- x of the upper-left corner of the region of text in world coordinates.y
- y of the upper-left corner of the region of text in world coordinates.
-
draw
Use the specified Batch to draw a char with the default color (white), with x and y determining the world-space coordinates for the upper-left corner. If c is'\0'
, will draw a solid white block instead.- Parameters:
batch
- the LibGDX Batch to do the drawingc
- the char to draw. Can be'\0'
to draw a solid block instead.x
- x of the upper-left corner of the region of text in world coordinates.y
- y of the upper-left corner of the region of text in world coordinates.
-
draw
public void draw(com.badlogic.gdx.graphics.g2d.Batch batch, CharSequence s, float r, float g, float b, float a, float x, float y)Use the specified Batch to draw a String or other CharSequence (often just one char long) in the specified rgba color, with x and y determining the world-space coordinates for the upper-left corner.- Parameters:
batch
- the LibGDX Batch to do the drawings
- the string to draw, often but not necessarily one char. Can be null to draw a solid block instead.r
- 0.0f to 1.0f red valueg
- 0.0f to 1.0f green valueb
- 0.0f to 1.0f blue valuea
- 0.0f to 1.0f alpha valuex
- x of the upper-left corner of the region of text in world coordinates.y
- y of the upper-left corner of the region of text in world coordinates.
-
draw
public void draw(com.badlogic.gdx.graphics.g2d.Batch batch, CharSequence s, com.badlogic.gdx.graphics.Color color, float x, float y)Use the specified Batch to draw a String or other CharSequence (often just one char long) in the specified LibGDX Color, with x and y determining the world-space coordinates for the upper-left corner.- Parameters:
batch
- the LibGDX Batch to do the drawings
- the string to draw, often but not necessarily one char. Can be null to draw a solid block instead.color
- the LibGDX Color to draw the char(s) with, all the same colorx
- x of the upper-left corner of the region of text in world coordinates.y
- y of the upper-left corner of the region of text in world coordinates.
-
draw
public void draw(com.badlogic.gdx.graphics.g2d.Batch batch, CharSequence s, float encodedColor, float x, float y)Use the specified Batch to draw a String or other CharSequence (often just one char long) in the specified LibGDX Color, with x and y determining the world-space coordinates for the upper-left corner.- Parameters:
batch
- the LibGDX Batch to do the drawings
- the string to draw, often but not necessarily one char. Can be null to draw a solid block instead.encodedColor
- the LibGDX Color to use, converted to float as byColor.toFloatBits()
x
- x of the upper-left corner of the region of text in world coordinates.y
- y of the upper-left corner of the region of text in world coordinates.
-
draw
public void draw(com.badlogic.gdx.graphics.g2d.Batch batch, char c, com.badlogic.gdx.graphics.Color color, float x, float y)Use the specified Batch to draw a char in the specified LibGDX Color, with x and y determining the world-space coordinates for the upper-left corner.- Parameters:
batch
- the LibGDX Batch to do the drawingc
- the char to draw. Can be'\0'
to draw a solid block instead.color
- the LibGDX Color (or SquidLib SColor) to use, as an objectx
- x of the upper-left corner of the region of text in world coordinates.y
- y of the upper-left corner of the region of text in world coordinates.
-
draw
public void draw(com.badlogic.gdx.graphics.g2d.Batch batch, char c, float encodedColor, float x, float y)Use the specified Batch to draw a String (often just one char long) in the specified LibGDX Color, with x and y determining the world-space coordinates for the upper-left corner.- Parameters:
batch
- the LibGDX Batch to do the drawingc
- the char to draw. Can be'\0'
to draw a solid block instead.encodedColor
- the LibGDX Color to use, converted to float as byColor.toFloatBits()
x
- x of the upper-left corner of the region of text in world coordinates.y
- y of the upper-left corner of the region of text in world coordinates.
-
draw
public void draw(com.badlogic.gdx.graphics.g2d.Batch batch, com.badlogic.gdx.graphics.g2d.TextureRegion tr, float x, float y)Use the specified Batch to draw a TextureRegion with the default tint color (white, so un-tinted), with x and y determining the world-space coordinates for the upper-left corner. The TextureRegion will be stretched if its size does not match what this TextCellFactory uses for width and height.- Parameters:
batch
- the LibGDX Batch to do the drawingtr
- the TextureRegion to draw. Can be null to draw a solid block instead.x
- x of the upper-left corner of the region of text in world coordinates.y
- y of the upper-left corner of the region of text in world coordinates.
-
draw
public void draw(com.badlogic.gdx.graphics.g2d.Batch batch, com.badlogic.gdx.graphics.g2d.TextureRegion tr, float r, float g, float b, float a, float x, float y)Use the specified Batch to draw a TextureRegion tinted with the specified rgba color, with x and y determining the world-space coordinates for the upper-left corner. The TextureRegion will be stretched if its size does not match what this TextCellFactory uses for width and height.- Parameters:
batch
- the LibGDX Batch to do the drawingtr
- the TextureRegion to draw. Can be null to draw a solid block instead.r
- 0.0 to 0.1 red valueg
- 0.0 to 0.1 green valueb
- 0.0 to 0.1 blue valuea
- 0.0 to 0.1 alpha valuex
- x of the upper-left corner of the region of text in world coordinates.y
- y of the upper-left corner of the region of text in world coordinates.
-
draw
public void draw(com.badlogic.gdx.graphics.g2d.Batch batch, com.badlogic.gdx.graphics.g2d.TextureRegion tr, com.badlogic.gdx.graphics.Color color, float x, float y)Use the specified Batch to draw a TextureRegion tinted with the specified LibGDX Color, with x and y determining the world-space coordinates for the upper-left corner. The TextureRegion will be stretched if its size does not match what this TextCellFactory uses for width and height.- Parameters:
batch
- the LibGDX Batch to do the drawingtr
- the TextureRegion to draw. Can be null to draw a solid block instead.color
- the LibGDX Color to draw the char(s) with, all the same colorx
- x of the upper-left corner of the region of text in world coordinates.y
- y of the upper-left corner of the region of text in world coordinates.
-
draw
public void draw(com.badlogic.gdx.graphics.g2d.Batch batch, com.badlogic.gdx.graphics.g2d.TextureRegion tr, float encodedColor, float x, float y)Use the specified Batch to draw a TextureRegion tinted with the specified encoded color as a float, with x and y determining the world-space coordinates for the upper-left corner. The TextureRegion will be stretched if its size does not match what this TextCellFactory uses for width and height. Colors can be converted to and from floats using methods in SColor such asSColor.floatGet(float, float, float, float)
,SColor.toFloatBits()
,SColor.colorFromFloat(Color, float)
, andSColor.lerpFloatColors(float, float, float)
.- Parameters:
batch
- the LibGDX Batch to do the drawingtr
- the TextureRegion to draw. Can be null to draw a solid block instead.encodedColor
- the float encoding a color (as ABGR8888; SColor can produce these) to draw the image withx
- x of the upper-left corner of the image in world coordinates.y
- y of the upper-left corner of the image in world coordinates.
-
draw
public void draw(com.badlogic.gdx.graphics.g2d.Batch batch, com.badlogic.gdx.graphics.g2d.TextureRegion tr, float x, float y, float width, float height)Use the specified Batch to draw a TextureRegion with the default tint color (white, so un-tinted), with x and y determining the world-space coordinates for the upper-left corner. The TextureRegion will be stretched only if the supplied width and height do not match what its own dimensions are.- Parameters:
batch
- the LibGDX Batch to do the drawingtr
- the TextureRegion to draw. Can be null to draw a solid block instead.x
- x of the upper-left corner of the region of text in world coordinates.y
- y of the upper-left corner of the region of text in world coordinates.width
- the width of the TextureRegion or solid block in pixels.height
- the height of the TextureRegion or solid block in pixels.
-
draw
public void draw(com.badlogic.gdx.graphics.g2d.Batch batch, com.badlogic.gdx.graphics.g2d.TextureRegion tr, float r, float g, float b, float a, float x, float y, float width, float height)Use the specified Batch to draw a TextureRegion tinted with the specified rgba color, with x and y determining the world-space coordinates for the upper-left corner. The TextureRegion will be stretched only if the supplied width and height do not match what its own dimensions are.- Parameters:
batch
- the LibGDX Batch to do the drawingtr
- the TextureRegion to draw. Can be null to draw a solid block instead.r
- 0.0 to 0.1 red valueg
- 0.0 to 0.1 green valueb
- 0.0 to 0.1 blue valuea
- 0.0 to 0.1 alpha valuex
- x of the upper-left corner of the region of text in world coordinates.y
- y of the upper-left corner of the region of text in world coordinates.width
- the width of the TextureRegion or solid block in pixels.height
- the height of the TextureRegion or solid block in pixels.
-
draw
public void draw(com.badlogic.gdx.graphics.g2d.Batch batch, com.badlogic.gdx.graphics.g2d.TextureRegion tr, com.badlogic.gdx.graphics.Color color, float x, float y, float width, float height)Use the specified Batch to draw a TextureRegion tinted with the specified LibGDX Color, with x and y determining the world-space coordinates for the upper-left corner. The TextureRegion will be stretched only if the supplied width and height do not match what its own dimensions are.- Parameters:
batch
- the LibGDX Batch to do the drawingtr
- the TextureRegion to draw. Can be null to draw a solid block instead.color
- the LibGDX Color to draw the image with, all the same colorx
- x of the upper-left corner of the image in world coordinates.y
- y of the upper-left corner of the image in world coordinates.width
- the width of the TextureRegion or solid block in pixels.height
- the height of the TextureRegion or solid block in pixels.
-
draw
public void draw(com.badlogic.gdx.graphics.g2d.Batch batch, com.badlogic.gdx.graphics.g2d.TextureRegion tr, float encodedColor, float x, float y, float width, float height)Use the specified Batch to draw a TextureRegion tinted with the specified LibGDX Color, with x and y determining the world-space coordinates for the upper-left corner. The TextureRegion will be stretched only if the supplied width and height do not match what its own dimensions are.- Parameters:
batch
- the LibGDX Batch to do the drawingtr
- the TextureRegion to draw. Can be null to draw a solid block instead.encodedColor
- the float encoding a color (as ABGR8888; SColor can produce these) to draw the image withx
- x of the upper-left corner of the image in world coordinates.y
- y of the upper-left corner of the image in world coordinates.width
- the width of the TextureRegion or solid block in pixels.height
- the height of the TextureRegion or solid block in pixels.
-
draw
public void draw(com.badlogic.gdx.graphics.g2d.Batch batch, float[][] encodedColors, float x, float y)Draws a 2D array of floats that represent encoded colors, with each float used for a block of color the size of one character cell (it will beactualCellWidth
byactualCellHeight
in size, using world units).- Parameters:
batch
- the LibGDX Batch to do the drawingencodedColors
- a 2D float array of encoded colors, each usually produced byColor.toFloatBits()
or an SColor methodx
- the x-position where this should render the block of many colorsy
- the y-position where this should render the block of many colors
-
draw
public void draw(com.badlogic.gdx.graphics.g2d.Batch batch, float[][] encodedColors, float x, float y, int xSubCells, int ySubCells)Draws a 2D array of floats that represent encoded colors, with each float used for a block of color that will be a fraction of the size of one character cell (it will beactualCellWidth
divided byxSubCells
byactualCellHeight
divided byySubCells
in size, using world units). Typically the 2D float array should be larger than the 2D storage for text drawn over the colorful blocks (such as a 2D char array), since more than one subcell may be drawn in the space of one character cell.- Parameters:
batch
- the LibGDX Batch to do the drawingencodedColors
- a 2D float array of encoded colors, each usually produced byColor.toFloatBits()
or an SColor methodx
- the x-position where this should render the block of many colorsy
- the y-position where this should render the block of many colorsxSubCells
- how many blocks of color should fit across the span ofactualCellWidth
, each one float; must not be 0ySubCells
- how many blocks of color should fit across the span ofactualCellHeight
, each one float; must not be 0
-
draw
Given a Pixmap and a 2D float array, uses each float in the array as an encoded color for a pixel in the Pixmap at a location determined by the float's position in the array. This is meant to be used to draw backgrounds that will be stretched by theactualCellWidth
andactualCellHeight
of this TextCellFactory.
Oddly, this doesn't seem to be very fast compared todraw(Batch, float[][], float, float)
, so if you need to draw backgrounds then prefer that method (as SparseLayers does). It also doesn't work with a FilterBatch, so if you want to use FloatFilter to adjust colors, you would need to use the other draw method for backgrounds.- Parameters:
pixmap
- a non-null Pixmap that will be modifiedencodedColors
- a 2D float array that must be non-null and non-empty, and contains packed colors
-
makeWrappingString
Converts a String into a Label, or if the argument s is null, creates an Image of a solid block. Can be used for preparing glyphs for animation effects.- Parameters:
s
- a String to make into an Actor, which can be null for a solid block.- Returns:
- the Actor, with no position set.
-
makeActor
public com.badlogic.gdx.scenes.scene2d.Actor makeActor(String s, com.badlogic.gdx.graphics.Color color)Converts a String into a Label, or if the argument s is null, creates an Image of a solid block. Can be used for preparing glyphs for animation effects, and is used internally for this purpose.- Parameters:
s
- a String to make into an Actor, which can be null for a solid block.color
- a Color to tint s with.- Returns:
- the Actor, with no position set.
-
makeActor
public com.badlogic.gdx.scenes.scene2d.Actor makeActor(String s, Collection<com.badlogic.gdx.graphics.Color> colors)Converts a String into a ColorChangeLabel, or if the argument s is null, creates a ColorChangeImage of a solid block. Can be used for preparing glyphs for animation effects, and is used internally for this purpose. The ColorChange classes will rotate between all colors given in the List each second, and are not affected by setColor, though they are affected by their setColors methods. Their color change is not considered an animation for the purposes of things like SquidPanel.hasActiveAnimations() .- Parameters:
s
- a String to make into an Actor, which can be null for a solid block.colors
- a List of Color to tint s with, looping through all elements in the list each second- Returns:
- the Actor, with no position set.
-
makeActor
public com.badlogic.gdx.scenes.scene2d.Actor makeActor(String s, Collection<com.badlogic.gdx.graphics.Color> colors, float loopTime)Converts a String into a ColorChangeLabel, or if the argument s is null, creates a ColorChangeImage of a solid block. Can be used for preparing glyphs for animation effects, and is used internally for this purpose. The ColorChange classes will rotate between all colors given in the List each second, and are not affected by setColor, though they are affected by their setColors methods. Their color change is not considered an animation for the purposes of things like SquidPanel.hasActiveAnimations() .- Parameters:
s
- a String to make into an Actor, which can be null for a solid block.colors
- a List of Color to tint s with, looping through all elements in the list each secondloopTime
- the amount of time, in seconds, to spend looping through all colors in the list- Returns:
- the Actor, with no position set.
-
makeActor
public com.badlogic.gdx.scenes.scene2d.Actor makeActor(String s, Collection<com.badlogic.gdx.graphics.Color> colors, float loopTime, boolean doubleWidth)Converts a String into a ColorChangeLabel, or if the argument s is null, creates a ColorChangeImage of a solid block. Can be used for preparing glyphs for animation effects, and is used internally for this purpose. The ColorChange classes will rotate between all colors given in the List each second, and are not affected by setColor, though they are affected by their setColors methods. Their color change is not considered an animation for the purposes of things like SquidPanel.hasActiveAnimations() .- Parameters:
s
- a String to make into an Actor, which can be null for a solid block.colors
- a List of Color to tint s with, looping through all elements in the list each secondloopTime
- the amount of time, in seconds, to spend looping through all colors in the list- Returns:
- the Actor, with no position set.
-
makeActor
public com.badlogic.gdx.scenes.scene2d.Actor makeActor(char c, com.badlogic.gdx.graphics.Color color)Converts a char into a Label, or if the argument c is '\0', creates an Image of a solid block. Can be used for preparing glyphs for animation effects, and is used internally for this purpose.- Parameters:
c
- a char to make into an Actor, which can be the character with Unicode value 0 for a solid block.color
- a Color to tint c with.- Returns:
- the Actor, with no position set.
-
makeActor
Converts a char into a Label, or if the argument c is '\0', creates an Image of a solid block. Can be used for preparing glyphs for animation effects, and is used internally for this purpose. Instead of a libGDX Color object, this takes an encoded float that represents a color as libGDX often does internally, ABGR-packed format. You can use various methods in SColor to produce these, likeSColor.floatGet(float, float, float, float)
orColor.toFloatBits()
.- Parameters:
c
- a char to make into an Actor, which can be the character with Unicode value 0 for a solid block.encodedColor
- an ABGR packed float (as produced bySColor.floatGet(float, float, float, float)
) to use as c's color- Returns:
- the Actor, with no position set.
-
makeActor
public com.badlogic.gdx.scenes.scene2d.Actor makeActor(char c, Collection<com.badlogic.gdx.graphics.Color> colors)Converts a char into a ColorChangeLabel, or if the argument c is '\0', creates a ColorChangeImage of a solid block. Can be used for preparing glyphs for animation effects, and is used internally for this purpose. The ColorChange classes will rotate between all colors given in the List each second, and are not affected by setColor, though they are affected by their setColors methods. Their color change is not considered an animation for the purposes of things like SquidPanel.hasActiveAnimations() .- Parameters:
c
- a char to make into an Actor, which can be the character with Unicode value 0 for a solid block.colors
- a List of Color to tint c with, looping through all elements in the list each second- Returns:
- the Actor, with no position set.
-
makeActor
public com.badlogic.gdx.scenes.scene2d.Actor makeActor(char c, Collection<com.badlogic.gdx.graphics.Color> colors, float loopTime)Converts a char into a ColorChangeLabel, or if the argument c is '\0', creates a ColorChangeImage of a solid block. Can be used for preparing glyphs for animation effects, and is used internally for this purpose. The ColorChange classes will rotate between all colors given in the List each second, and are not affected by setColor, though they are affected by their setColors methods. Their color change is not considered an animation for the purposes of things like SquidPanel.hasActiveAnimations() .- Parameters:
c
- a char to make into an Actor, which can be the character with Unicode value 0 for a solid block.colors
- a List of Color to tint c with, looping through all elements in the list each secondloopTime
- the amount of time, in seconds, to spend looping through all colors in the list- Returns:
- the Actor, with no position set.
-
makeActor
public com.badlogic.gdx.scenes.scene2d.Actor makeActor(char c, Collection<com.badlogic.gdx.graphics.Color> colors, float loopTime, boolean doubleWidth)Converts a char into a ColorChangeLabel, or if the argument c is '\0', creates a ColorChangeImage of a solid block. Can be used for preparing glyphs for animation effects, and is used internally for this purpose. The ColorChange classes will rotate between all colors given in the List each second, and are not affected by setColor, though they are affected by their setColors methods. Their color change is not considered an animation for the purposes of things like SquidPanel.hasActiveAnimations() .- Parameters:
c
- a char to make into an Actor, which can be the character with Unicode value 0 for a solid block.colors
- a List of Color to tint c with, looping through all elements in the list each secondloopTime
- the amount of time, in seconds, to spend looping through all colors in the list- Returns:
- the Actor, with no position set.
-
makeActor
public com.badlogic.gdx.scenes.scene2d.Actor makeActor(com.badlogic.gdx.graphics.g2d.TextureRegion tr, Collection<com.badlogic.gdx.graphics.Color> colors) -
makeActor
public com.badlogic.gdx.scenes.scene2d.Actor makeActor(com.badlogic.gdx.graphics.g2d.TextureRegion tr, Collection<com.badlogic.gdx.graphics.Color> colors, float loopTime) -
makeActor
public com.badlogic.gdx.scenes.scene2d.Actor makeActor(com.badlogic.gdx.graphics.g2d.TextureRegion tr, Collection<com.badlogic.gdx.graphics.Color> colors, float loopTime, boolean doubleWidth)Converts a TextureRegion into a ColorChangeImage that will cycle through the given colors. ColorChange classes will rotate between all colors given in the List each loopTime, and are not affected by setColor, though they are affected by their setColors methods. Their color change is not considered an animation for the purposes of things like SquidPanel.hasActiveAnimations() .- Parameters:
tr
- a TextureRegion to make into an Actor, which can be null for a solid block.colors
- a List of Color to tint c with, looping through all elements in the list each secondloopTime
- the amount of time, in seconds, to spend looping through all colors in the list- Returns:
- the Actor, with no position set.
-
makeActor
public com.badlogic.gdx.scenes.scene2d.Actor makeActor(com.badlogic.gdx.graphics.g2d.TextureRegion tr, Collection<com.badlogic.gdx.graphics.Color> colors, float loopTime, boolean doubleWidth, float width, float height)Converts a TextureRegion into a ColorChangeImage that will cycle through the given colors. ColorChange classes will rotate between all colors given in the List each loopTime, and are not affected by setColor, though they are affected by their setColors methods. Their color change is not considered an animation for the purposes of things like SquidPanel.hasActiveAnimations() .- Parameters:
tr
- a TextureRegion to make into an Actor, which can be null for a solid block.colors
- a List of Color to tint c with, looping through all elements in the list each secondloopTime
- the amount of time, in seconds, to spend looping through all colors in the list- Returns:
- the Actor, with no position set.
-
makeDirectionMarker
public com.badlogic.gdx.scenes.scene2d.ui.Image makeDirectionMarker(Collection<com.badlogic.gdx.graphics.Color> colors, float loopTime, boolean doubleWidth)Creates a ColorChangeImage Actor that should look like the glyph '^' in this font, but will be rotate-able. The ColorChange classes will rotate between all colors given in the List in the given amount of loopTime, and are not affected by setColor, though they are affected by their setColors methods. Their color change is not considered an animation for the purposes of things like SquidPanel.hasActiveAnimations() .- Parameters:
colors
- a List of Color to tint the '^' with, looping through all elements in the list each secondloopTime
- the amount of time, in seconds, to spend looping through all colors in the list- Returns:
- the Actor, with no position set.
-
makeDirectionMarker
public com.badlogic.gdx.scenes.scene2d.ui.Image makeDirectionMarker(com.badlogic.gdx.graphics.Color color)Creates a Image Actor that should look like the glyph '^' in this font, but will be rotate-able.- Parameters:
color
- a Color to tint the '^' with- Returns:
- the Actor, with no position set.
-
makeGlyphImage
Given a char and a Color, makes a ColorChangeImage of that colored char so it can be rotated and so on.- Parameters:
glyph
- a char; should probably be visible, so not space or tabcolor
- a Color to use for the image; will not change even though ColorChangeImage permits this- Returns:
- the ColorChangeImage with the one color for glyph
-
makeGlyphImage
public ColorChangeImage makeGlyphImage(char glyph, com.badlogic.gdx.graphics.Color color, boolean doubleWidth)Given a char and a Color, makes a ColorChangeImage of that colored char so it can be rotated and so on. This overload allows double-width mode to be specified.- Parameters:
glyph
- a char; should probably be visible, so not space or tabcolor
- a Color to use for the image; will not change even though ColorChangeImage permits thisdoubleWidth
- true if layout uses two chars of width per logical cell, false otherwise- Returns:
- the ColorChangeImage with the one color for glyph
-
makeGlyphImage
public ColorChangeImage makeGlyphImage(char glyph, Collection<com.badlogic.gdx.graphics.Color> colors, float loopTime, boolean doubleWidth)Given a char and a Collection of Color (such as a List that might be produced bySquidColorCenter.gradient(Color, Color)
), makes a ColorChangeImage of that char so it can be rotated and so on. The colors will cycle through the given collection onceperloopTime
seconds. You can specify double-width mode if you use it, probably in SquidPanel or SquidLayers.- Parameters:
glyph
- a char; should probably be visible, so not space or tabcolors
- a Collection of Colors to use for the image; the image will cycle through them in orderloopTime
- the amount of time, in seconds, it should take for all colors to be cycled throughdoubleWidth
- true if layout uses two chars of width per logical cell, false otherwise- Returns:
- the ColorChangeImage with the one color for glyph
-
makeActor
public com.badlogic.gdx.scenes.scene2d.Actor makeActor(com.badlogic.gdx.graphics.g2d.TextureRegion tr, com.badlogic.gdx.graphics.Color color)Converts a TextureRegion into an Image, or if the argument s is null, creates an Image of a solid block. Can be used for preparing images for animation effects. Stretches the TextureRegion to match a single cell's dimensions.- Parameters:
tr
- a TextureRegion to make into an Actor, which can be null for a solid block.color
- a Color to tint tr with.- Returns:
- the Actor, with no position set.
-
makeActor
public com.badlogic.gdx.scenes.scene2d.Actor makeActor(com.badlogic.gdx.graphics.g2d.TextureRegion tr, com.badlogic.gdx.graphics.Color color, float width, float height)Converts a TextureRegion into an Image, or if the argument s is null, creates an Image of a solid block. Can be used for preparing images for animation effects. Ensures the returned Image has the given width and height.- Parameters:
tr
- a TextureRegion to make into an Actor, which can be null for a solid block.color
- a Color to tint tr with.- Returns:
- the Actor, with no position set.
-
getSolid
Returns a solid block of white, 1x1 pixel in size; can be drawn at other sizes by Batch.- Returns:
- a white 1x1 pixel Texture.
-
glyph
public TextCellFactory.Glyph glyph(char shown, com.badlogic.gdx.graphics.Color color, float x, float y)Gets a Glyph with the given char to show, libGDX Color, and position as x and y in world coordinates. Glyph is a kind of scene2d Actor that uses this TextCellFactory to handle its rendering instead of delegating that to the Label class from scene2d.ui.- Parameters:
shown
- char to show; if this is the char with codepoint 0, then this will show a solid blockcolor
- the color as a libGDX Color; can also be an SColor or some other subclass of Colorx
- the x position of the Glyph in world coordinates, as would be passed to draw()y
- the y position of the Glyph in world coordinates, as would be passed to draw()- Returns:
- a new Glyph that will use the specified char, color, and position
-
glyph
Gets a Glyph with the given char to show, color as a packed float, and position as x and y in world coordinates. Glyph is a kind of scene2d Actor that uses this TextCellFactory to handle its rendering instead of delegating that to the Label class from scene2d.ui.- Parameters:
shown
- char to show; if this is the char with codepoint 0, then this will show a solid blockencodedColor
- the encoded color as a float, as produced byColor.toFloatBits()
x
- the x position of the Glyph in world coordinates, as would be passed to draw()y
- the y position of the Glyph in world coordinates, as would be passed to draw()- Returns:
- a new Glyph that will use the specified char, color, and position
-
isMultiDistanceField
-
isDistanceField
-
getDistanceFieldScaleX
-
getDistanceFieldScaleY
-
getSmoothingMultiplier
If this uses a distance field font, the smoothing multiplier affects how crisp or blurry lines are, with higher numbers generally resulting in more crisp fonts, but numbers that are too high cause jagged aliasing. This starts at 1.2f, usually (DefaultResources
notes when a different value is used).- Returns:
- the current smoothing multiplier as a float, which starts at 1.2f for most fonts
-
setSmoothingMultiplier
If this uses a distance field font, the smoothing multiplier affects how crisp or blurry lines are, with higher numbers generally resulting in more crisp fonts, but numbers that are too high cause jagged aliasing. Before this is called, the smoothing multiplier is usually 1.2f;DefaultResources
notes when other values are used.- Parameters:
smoothingMultiplier
- the new value for the smoothing multiplier as a float; should be fairly close to 1f.- Returns:
- this for chaining
-
configureShader
If using a distance field font, you MUST call this at some point while the batch has begun, or use code that calls it for you (which is now much of SquidLib). A typical point to call it is in the "void draw(Batch batch, float parentAlpha)" method or an overriding method for a Scene2D class. You should call configureShader rarely, typically only a few times per frame if there are no images to render, and this means the logical place to call it is in the outermost Group that contains any SquidPanel objects or other widgets. If you have multipleTextCellFactory objects, each one needs to have configureShader called before it is used to draw.
SquidLayers, SparseLayers, SubcellLayers, SquidPanel, TextPanel, and ImageSquidPanel already call this method in their draw overrides, so you don't need to call this manually if you use any of those. None of those classes change the shader after they set it for their uses, so you may need to set the shader on your Batch to null to revert to the default shader if you need to draw full-color art.
If you don't use a distance field font, you don't need to call this, but calling it won't cause problems.- Parameters:
batch
- the Batch, such as aFilterBatch
, to configure to render distance field fonts if necessary.
-
dispose
Releases all resources of this object.- Specified by:
dispose
in interfacecom.badlogic.gdx.utils.Disposable
-
getDescent
Gets the descent of this TextCellFactory's BitmapFont, which may be useful for layout outside this class.- Returns:
- the descent of the BitmapFont this object uses
-
getDirectionGlyph
-
setDirectionGlyph
-
addSwap
Adds a pair of Strings (typically both with length 1) as a replacement pair, so when the find String is requested to be drawn, the replace String is used instead. Swaps are used when drawing text in each cell in SquidPanel and related classes, so Strings longer than 1 char are effectively disregarded beyond the first char.
This can be useful when you want to use certain defaults in squidlib-util's dungeon generation, like '~' for deep water, but not others, like ',' for shallow water, and would rather have a glyph of your choice replace something that would be drawn. Replacements will not be chained; that is, if youaddSwap("^", ",")
and alsoaddSwap(",", ":")
, then a requested '^' will be drawn as ',', not ':', but a requested ',' will be drawn as ':' (only one swap will be performed). Typically you want a different TextCellFactory for UI elements that use swapping, like a top-down char-based map, and elements that should not, like those that display normal text.- Parameters:
find
- the requested String that will be changedreplace
- the replacement String that will be used in place of find- Returns:
- this for chaining
-
addSwap
Adds a pair of chars as a replacement pair, so when the find char is requested to be drawn, the replace char is used instead.
This can be useful when you want to use certain defaults in squidlib-util's dungeon generation, like '~' for deep water, but not others, like ',' for shallow water, and would rather have a glyph of your choice replace something that would be drawn. Replacements will not be chained; that is, if youaddSwap('^', ',')
and alsoaddSwap(',', ':')
, then a requested '^' will be drawn as ',', not ':', but a requested ',' will be drawn as ':' (only one swap will be performed). Typically you want a different TextCellFactory for UI elements that use swapping, like a top-down char-based map, and elements that should not, like those that display normal text.- Parameters:
find
- the requested char that will be changed (converted to a length-1 String)replace
- the replacement char that will be used in place of find (converted to a length-1 String)- Returns:
- this for chaining
-
removeSwap
Removes the replacement pair, if present, that searches for the given key, find. Swaps are used when drawing text in each cell in SquidPanel and related classes, so Strings longer than 1 char are effectively disregarded beyond the first char.
This can be useful when you want to use certain defaults in squidlib-util's dungeon generation, like '~' for deep water, but not others, like ',' for shallow water, and would rather have a glyph of your choice replace something that would be drawn. Replacements will not be chained; that is, if youaddSwap('^', ',')
and alsoaddSwap(',', ':')
, then a requested '^' will be drawn as ',', not ':', but a requested ',' will be drawn as ':' (only one swap will be performed). Typically you want a different TextCellFactory for UI elements that use swapping, like a top-down char-based map, and elements that should not, like those that display normal text.- Parameters:
find
- the String that would be changed in the replacement pair- Returns:
- this for chaining
-
removeSwap
Removes the replacement pair, if present, that searches for the given key, find.
This can be useful when you want to use certain defaults in squidlib-util's dungeon generation, like '~' for deep water, but not others, like ',' for shallow water, and would rather have a glyph of your choice replace something that would be drawn. Replacements will not be chained; that is, if youaddSwap('^', ',')
and alsoaddSwap(',', ':')
, then a requested '^' will be drawn as ',', not ':', but a requested ',' will be drawn as ':' (only one swap will be performed). Typically you want a different TextCellFactory for UI elements that use swapping, like a top-down char-based map, and elements that should not, like those that display normal text.- Returns:
- this for chaining
-
getAllSwaps
Gets the current mapping of "swaps", or replacement pairs, to replace keys requested for drawing with their values in theCharCharMap
. CharCharMap is a class from RegExodus (a dependency of squidlib-util that is used for text matching and Unicode support), which is used here to avoid making yet another primitive-backed collection class.
This can be useful when you want to use certain defaults in squidlib-util's dungeon generation, like '~' for deep water, but not others, like ',' for shallow water, and would rather have a glyph of your choice replace something that would be drawn. Replacements will not be chained; that is, if youaddSwap('^', ',')
and alsoaddSwap(',', ':')
, then a requested '^' will be drawn as ',', not ':', but a requested ',' will be drawn as ':' (only one swap will be performed). Typically you want a different TextCellFactory for UI elements that use swapping, like a top-down char-based map, and elements that should not, like those that display normal text.- Returns:
- the mapping of replacement pairs
-
setAllSwaps
Sets the mapping of replacement pairs to a different one as a Map of Character keys to String values.
This can be useful when you want to use certain defaults in squidlib-util's dungeon generation, like '~' for deep water, but not others, like ',' for shallow water, and would rather have a glyph of your choice replace something that would be drawn. Replacements will not be chained; that is, if youaddSwap('^', ',')
and alsoaddSwap(',', ':')
, then a requested '^' will be drawn as ',', not ':', but a requested ',' will be drawn as ':' (only one swap will be performed). Typically you want a different TextCellFactory for UI elements that use swapping, like a top-down char-based map, and elements that should not, like those that display normal text.- Parameters:
swaps
- the Map of replacement pairs; keys requested for drawing will be replaced with their values- Returns:
- this for chaining
-
addSwaps
Appends to the mapping of replacement pairs, adding or replacing any entries in the current mapping with the entries in a Map of Character keys to String values.
This can be useful when you want to use certain defaults in squidlib-util's dungeon generation, like '~' for deep water, but not others, like ',' for shallow water, and would rather have a glyph of your choice replace something that would be drawn. Replacements will not be chained; that is, if youaddSwap('^', ',')
and alsoaddSwap(',', ':')
, then a requested '^' will be drawn as ',', not ':', but a requested ',' will be drawn as ':' (only one swap will be performed). Typically you want a different TextCellFactory for UI elements that use swapping, like a top-down char-based map, and elements that should not, like those that display normal text.- Parameters:
swaps
- the Map of replacement pairs to add; keys requested for drawing will be replaced with their values- Returns:
- this for chaining
-
clearSwaps
Clears all replacement pairs this has been told to swap.
This can be useful when you want to use certain defaults in squidlib-util's dungeon generation, like '~' for deep water, but not others, like ',' for shallow water, and would rather have a glyph of your choice replace something that would be drawn. Replacements will not be chained; that is, if youaddSwap('^', ',')
and alsoaddSwap(',', ':')
, then a requested '^' will be drawn as ',', not ':', but a requested ',' will be drawn as ':' (only one swap will be performed). Typically you want a different TextCellFactory for UI elements that use swapping, like a top-down char-based map, and elements that should not, like those that display normal text.- Returns:
- this for chaining
-
setStyle
Not implemented in this class; in subclasses that do, this should change the currently-used font style, such as from regular to italic or bold. Calling this method on a TextCellFactory does nothing, but won't cause problems.- Parameters:
style
- an int, typically a constant in a class that implements this, that determines what style to use.
-