Class GUIFont

java.lang.Object
com.blackrook.gui.GUIFont
All Implemented Interfaces:
GUIFontType

public class GUIFont extends Object implements GUIFontType
GUI font for GUIText objects. Basically a texture-coordinate and size lookup for rendering character meshes.
Author:
Matthew Tropiano
  • Field Details

  • Constructor Details

    • GUIFont

      public GUIFont(String texture)
      Creates an GUIFont from a texture.
      Parameters:
      texture - the texture.
    • GUIFont

      public GUIFont(String name, String texture)
      Creates an GUIFont from a texture.
      Parameters:
      name - the name of the font.
      texture - the texture.
  • Method Details

    • getName

      public String getName()
      Specified by:
      getName in interface GUIFontType
      Returns:
      the name of this font.
    • setName

      public void setName(String name)
      Sets the name of this font.
      Parameters:
      name - the name of the font.
    • getTexture

      public String getTexture()
      Specified by:
      getTexture in interface GUIFontType
      Returns:
      the texture to use for this mapping.
    • setTexture

      public void setTexture(String texture)
      Sets the texture to use for this mapping.
      Parameters:
      texture - the texture name.
    • setDefaultChar

      public void setDefaultChar(float s0, float t0, float s1, float t1, float width, float height, float advance, float xofs, float yofs)
      Sets the default character.
      Parameters:
      s0 - the starting texture coordinate, s-axis.
      t0 - the starting texture coordinate, t-axis.
      s1 - the ending texture coordinate, s-axis.
      t1 - the ending texture coordinate, t-axis.
      width - the width ratio scalar for this character. The final width of the character is the font size times this scalar.
      height - the height ratio scalar for this character. The final height of the character is the font size times this scalar.
      advance - the advance ratio scalar for this character, or how much to advance the cursor after this is placed. The advance of the character is the font size times this scalar.
      xofs - the x-offset amount scalar to adjust the cursor for painting this character. The amount of adjustment is the font size times this scalar.
      yofs - the y-offset amount scalar to adjust the cursor for painting this character. The amount of adjustment is the font size times this scalar.
    • addChar

      public void addChar(char c, float s0, float t0, float s1, float t1, float width, float height, float advance, float xofs, float yofs)
      Adds a character to the map.
      Parameters:
      c - the character to add to the map.
      s0 - the starting texture coordinate, s-axis.
      t0 - the starting texture coordinate, t-axis.
      s1 - the ending texture coordinate, s-axis.
      t1 - the ending texture coordinate, t-axis.
      width - the width ratio scalar for this character. The final width of the character is the font size times this scalar.
      height - the height ratio scalar for this character. The final height of the character is the font size times this scalar.
      advance - how much to move the cursor for the next cursor rendering.
      xofs - the x-offset amount scalar to adjust the cursor for painting this character. The amount of adjustment is the font size times this scalar.
      yofs - the y-offset amount scalar to adjust the cursor for painting this character. The amount of adjustment is the font size times this scalar.
    • getChar

      public GUIFontType.FontChar getChar(char c)
      Description copied from interface: GUIFontType
      Gets a character's definition from the map.
      Specified by:
      getChar in interface GUIFontType
      Parameters:
      c - the character to retrieve from the map.
      Returns:
      the font map linked to this character. May return the default map if it isn't in the map.
    • removeChar

      public boolean removeChar(char c)
      Removes a character from the map.
      Parameters:
      c - the character to remove from the map.
      Returns:
      true if the definition was removed, false otherwise.
    • getDirectionality

      public GUIFontType.Directionality getDirectionality()
      Specified by:
      getDirectionality in interface GUIFontType
      Returns:
      this font's directionality.
    • setDirectionality

      public void setDirectionality(GUIFontType.Directionality directionality)
      Sets this font's directionality.
      Parameters:
      directionality - the lettering directionality.
    • makeMonospaceFont

      public static GUIFont makeMonospaceFont(String name, String texture, int charsPerRow)
      Creates a monospace font that maps the first series of unicode characters from a specified character set distributed evenly across a single texture, left to right, top to bottom.

      This assumes an "ASCII" alphabet starting from 0x00.

      The distribution is square-wise, affected by the parameters charsPerRow and alphabet.

      If charsPerRow is 3, the divisions are:

      Divisions
      012
      345
      678

      If charsPerRow is 4 but alphabet.length() is 15, the divisions are:

      Divisions
      0123
      4567
      891011
      121314 

      If charsPerRow is 4 but alphabet.length() is 11, the divisions are:

      Divisions
      0123
      4567
      8910 
          
      Parameters:
      name - the name of the font.
      texture - the name of the texture.
      charsPerRow - the amount of characters per row.
      Returns:
      a new font.
    • makeMonospaceFont

      public static GUIFont makeMonospaceFont(String name, String texture, int charsPerRow, String alphabet)
      Creates a monospace font that maps the first series of unicode characters from a specified character set distributed evenly across a single texture, left to right, top to bottom.

      The distribution is square-wise, affected by the parameters charsPerRow and alphabet.

      If charsPerRow is 3, the divisions are:

      Divisions
      012
      345
      678

      If charsPerRow is 4 but alphabet.length() is 15, the divisions are:

      Divisions
      0123
      4567
      891011
      121314 

      If charsPerRow is 4 but alphabet.length() is 11, the divisions are:

      Divisions
      0123
      4567
      8910 
          
      Parameters:
      name - the name of the font.
      texture - the name of the texture.
      charsPerRow - the amount of characters per row.
      alphabet - the texture increment for each character and row.
      Returns:
      a new font.
    • readBMFont

      public static GUIFont readBMFont(File file, String texture) throws IOException
      Reads in XML-Formatted BM Font (http://www.angelcode.com/products/bmfont/) generated metadata and creates an GUIFont using the data.
      Parameters:
      file - the file that holds the XML data.
      texture - the texture used for this font.
      Returns:
      the created font.
      Throws:
      IOException - if a read error happens.
    • readBMFont

      public static GUIFont readBMFont(InputStream in, String texture) throws IOException
      Reads in XML-Formatted BM Font (http://www.angelcode.com/products/bmfont/) generated metadata and creates an GUIFont using the data.
      Parameters:
      in - the input stream for the XML data.
      texture - the texture used for this font.
      Returns:
      the created font.
      Throws:
      IOException - if a read error happens.