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
    The AssetManager 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 in DefaultResources.
    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 given AssetManager 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 be actualCellWidth by actualCellHeight 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 be actualCellWidth divided by xSubCells by actualCellHeight divided by ySubCells 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 the BitmapFont 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 the CharCharMap.
    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 to initBySize().
    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 by SquidColorCenter.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 calling initBySize(), but doesn't create new ShaderPrograms or other objects if this has already been initialized.
    TextCellFactory resetSize​(float newWidth, float newHeight)
    Acts like calling width(float), height(float), and initBySize() 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.

    Methods inherited from class java.lang.Object

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

  • 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

      public TextCellFactory​(com.badlogic.gdx.assets.AssetManager assetManager)
      A default valued factory that uses the given AssetManager to load the font file. Use this constructor if you are likely to load the same font over and over (recall that, without an AssetManager, each instance of TextCellFactory 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

      public int 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, use initBySize().
      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, use resetSize(), 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 calling initBySize(), 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

      public TextCellFactory resetSize​(float newWidth, float newHeight)
      Acts like calling width(float), height(float), and initBySize() 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 pixels
      newHeight - the new height of a single cell, as a float that usually corresponds to pixels
      Returns:
      this for chaining
    • initVerbatim

      Identical to initBySize().
      Returns:
      this for method chaining
      See Also:
      The docs for initBySize() apply here.
    • font

      public com.badlogic.gdx.graphics.g2d.BitmapFont font()
      Returns the BitmapFont used by this factory.
      Returns:
      the BitmapFont this uses
    • font

      public TextCellFactory font​(String fontpath)
      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): "Rogue-Zodiac-12x24.fnt", which is easily accessed by the field DefaultResources.narrowNameLarge , can also be set using TextCellFactory.defaultNarrowFont() instead of font(). "Zodiac-Square-12x12.fnt", also accessible as DefaultResources.squareName , can be set using TextCellFactory.defaultSquareFont() instead of font(). "Inconsolata-LGC-12x24.fnt", also accessible as DefaultResources.smoothNameLarge , can be set using TextCellFactory.defaultFont() instead of font(). All three of these alternatives will cache the BitmapFont if the same one is requested later, but this font() method will not.
      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

      public TextCellFactory font​(com.badlogic.gdx.graphics.g2d.BitmapFont bitmapFont)
      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 as DefaultResources.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): "Rogue-Zodiac-12x24.fnt", which is easily accessed by the method DefaultResources.getLargeNarrowFont() , can also be set using TextCellFactory.defaultNarrowFont() instead of font(). "Zodiac-Square-12x12.fnt", also accessible with DefaultResources.getDefaultFont() , can be set using TextCellFactory.defaultSquareFont() instead of font(). "Inconsolata-LGC-12x24.fnt", also accessible with DefaultResources.getLargeSmoothFont() , can be set using TextCellFactory.defaultFont() instead of font(). All three of these alternatives will cache the BitmapFont if the same one is requested later, but this font() method will not.
      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

      public 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. 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

      public TextCellFactory fontMultiDistanceField​(String fontPath, String texturePath)
      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 to font(String) or fontDistanceField(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

      public float width()
      Returns the width of a single cell.
      Returns:
      the width
    • width

      public TextCellFactory width​(float 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

      public float height()
      Returns the height of a single cell.
      Returns:
      the height of a single cell
    • height

      public TextCellFactory height​(float 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

      public 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. Clamps at 1 on the lower bound to ensure valid calculations.
      Parameters:
      width - the desired width
      Returns:
      this factory for method chaining
    • tweakHeight

      public 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. Clamps at 1 on the lower bound to ensure valid calculations.
      Parameters:
      height - the desired height
      Returns:
      this factory for method chaining
    • fit

      public String 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

      public TextCellFactory fit​(String 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

      public TextCellFactory addFit​(String fit)
      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

      public boolean 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 public TextCellFactory antialias​(boolean 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

      public TextCellFactory padding​(int 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

      public int leftPadding()
      Returns the padding on the left side.
      Returns:
      amount of padding in pixels
    • leftPadding

      public TextCellFactory leftPadding​(int padding)
      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

      public int rightPadding()
      Returns the padding on the right side.
      Returns:
      amount of padding in pixels
    • rightPadding

      public TextCellFactory rightPadding​(int padding)
      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

      public int topPadding()
      Returns the padding on the top side.
      Returns:
      amount of padding in pixels
    • topPadding

      public TextCellFactory topPadding​(int padding)
      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

      public int bottomPadding()
      Returns the padding on the bottom side.
      Returns:
      amount of padding in pixels
    • bottomPadding

      public TextCellFactory bottomPadding​(int padding)
      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

      public TextCellFactory setColorCenter​(IColorCenter<com.badlogic.gdx.graphics.Color> icc)
      Parameters:
      icc - The color center to use. Should not be null.
      Returns:
      this
      Throws:
      NullPointerException - If icc is null.
    • initialized

      public boolean initialized()
      Returns true if this factory is fully initialized and ready to build text cells.
      Returns:
      true if initialized
    • willFit

      public boolean willFit​(int codepoint)
      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

      public 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.
      Parameters:
      batch - the LibGDX Batch to do the drawing
      s - 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

      public 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. If c is '\0', will draw a solid white block instead.
      Parameters:
      batch - the LibGDX Batch to do the drawing
      c - 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 drawing
      s - 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 value
      g - 0.0f to 1.0f green value
      b - 0.0f to 1.0f blue value
      a - 0.0f to 1.0f alpha value
      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, 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 drawing
      s - 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 color
      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 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 drawing
      s - 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 by Color.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 drawing
      c - the char to draw. Can be '\0' to draw a solid block instead.
      color - the LibGDX Color (or SquidLib SColor) to use, as an object
      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, 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 drawing
      c - the char to draw. Can be '\0' to draw a solid block instead.
      encodedColor - the LibGDX Color to use, converted to float as by Color.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 drawing
      tr - 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 drawing
      tr - the TextureRegion to draw. Can be null to draw a solid block instead.
      r - 0.0 to 0.1 red value
      g - 0.0 to 0.1 green value
      b - 0.0 to 0.1 blue value
      a - 0.0 to 0.1 alpha value
      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, 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 drawing
      tr - 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 color
      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 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 as SColor.floatGet(float, float, float, float), SColor.toFloatBits(), SColor.colorFromFloat(Color, float), and SColor.lerpFloatColors(float, float, float).
      Parameters:
      batch - the LibGDX Batch to do the drawing
      tr - 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 with
      x - 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 drawing
      tr - 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 drawing
      tr - the TextureRegion to draw. Can be null to draw a solid block instead.
      r - 0.0 to 0.1 red value
      g - 0.0 to 0.1 green value
      b - 0.0 to 0.1 blue value
      a - 0.0 to 0.1 alpha value
      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, 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 drawing
      tr - 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 color
      x - 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 drawing
      tr - 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 with
      x - 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 be actualCellWidth by actualCellHeight in size, using world units).
      Parameters:
      batch - the LibGDX Batch to do the drawing
      encodedColors - a 2D float array of encoded colors, each usually produced by Color.toFloatBits() or an SColor method
      x - the x-position where this should render the block of many colors
      y - 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 be actualCellWidth divided by xSubCells by actualCellHeight divided by ySubCells 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 drawing
      encodedColors - a 2D float array of encoded colors, each usually produced by Color.toFloatBits() or an SColor method
      x - the x-position where this should render the block of many colors
      y - the y-position where this should render the block of many colors
      xSubCells - how many blocks of color should fit across the span of actualCellWidth, each one float; must not be 0
      ySubCells - how many blocks of color should fit across the span of actualCellHeight, each one float; must not be 0
    • draw

      public 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. This is meant to be used to draw backgrounds that will be stretched by the actualCellWidth and actualCellHeight of this TextCellFactory.
      Oddly, this doesn't seem to be very fast compared to draw(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 modified
      encodedColors - a 2D float array that must be non-null and non-empty, and contains packed colors
    • makeWrappingString

      public 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. 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 second
      loopTime - 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 second
      loopTime - 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

      public 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. 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, like SColor.floatGet(float, float, float, float) or Color.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 by SColor.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 second
      loopTime - 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 second
      loopTime - 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 second
      loopTime - 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 second
      loopTime - 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 second
      loopTime - 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

      public 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.
      Parameters:
      glyph - a char; should probably be visible, so not space or tab
      color - 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 tab
      color - a Color to use for the image; will not change even though ColorChangeImage permits this
      doubleWidth - 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 by SquidColorCenter.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 onceper loopTime 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 tab
      colors - a Collection of Colors to use for the image; the image will cycle through them in order
      loopTime - the amount of time, in seconds, it should take for all colors to be cycled through
      doubleWidth - 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

      public 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.
      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 block
      color - the color as a libGDX Color; can also be an SColor or some other subclass of Color
      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
    • glyph

      public 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. 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 block
      encodedColor - the encoded color as a float, as produced by Color.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

      public boolean isMultiDistanceField()
    • isDistanceField

      public boolean isDistanceField()
    • getDistanceFieldScaleX

      public float getDistanceFieldScaleX()
    • getDistanceFieldScaleY

      public float getDistanceFieldScaleY()
    • getSmoothingMultiplier

      public 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. 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

      public 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. 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

      public 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). 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 a FilterBatch, to configure to render distance field fonts if necessary.
    • dispose

      public void dispose()
      Releases all resources of this object.
      Specified by:
      dispose in interface com.badlogic.gdx.utils.Disposable
    • getDescent

      public float 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

      public char getDirectionGlyph()
    • setDirectionGlyph

      public TextCellFactory setDirectionGlyph​(char directionGlyph)
    • addSwap

      public 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. 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 you addSwap("^", ",") and also addSwap(",", ":"), 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 changed
      replace - the replacement String that will be used in place of find
      Returns:
      this for chaining
    • addSwap

      public 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.
      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 you addSwap('^', ',') and also addSwap(',', ':'), 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

      public TextCellFactory removeSwap​(String find)
      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 you addSwap('^', ',') and also addSwap(',', ':'), 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

      public TextCellFactory removeSwap​(char find)
      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 you addSwap('^', ',') and also addSwap(',', ':'), 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

      public regexodus.ds.CharCharMap getAllSwaps()
      Gets the current mapping of "swaps", or replacement pairs, to replace keys requested for drawing with their values in the CharCharMap. 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 you addSwap('^', ',') and also addSwap(',', ':'), 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 you addSwap('^', ',') and also addSwap(',', ':'), 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 you addSwap('^', ',') and also addSwap(',', ':'), 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 you addSwap('^', ',') and also addSwap(',', ':'), 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

      public 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. 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.