Class GUIFont
java.lang.Object
com.blackrook.gui.GUIFont
- All Implemented Interfaces:
GUIFontType
GUI font for GUIText objects. Basically a texture-coordinate and size lookup for
rendering character meshes.
- Author:
- Matthew Tropiano
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface GUIFontType
GUIFontType.Directionality, GUIFontType.FontChar -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected GUIFontType.FontCharDefault character to return if the character is not in the map.protected GUIFontType.DirectionalityType of directionality to use.protected SortedMap<Character, GUIFontType.FontChar> HashMap for the font map.protected StringName of the font.protected StringTexture name for this font. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddChar(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.getChar(char c) Gets a character's definition from the map.getName()static GUIFontmakeMonospaceFont(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.static GUIFontmakeMonospaceFont(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.static GUIFontreadBMFont(File file, String texture) Reads in XML-Formatted BM Font (http://www.angelcode.com/products/bmfont/) generated metadata and creates an GUIFont using the data.static GUIFontreadBMFont(InputStream in, String texture) Reads in XML-Formatted BM Font (http://www.angelcode.com/products/bmfont/) generated metadata and creates an GUIFont using the data.booleanremoveChar(char c) Removes a character from the map.voidsetDefaultChar(float s0, float t0, float s1, float t1, float width, float height, float advance, float xofs, float yofs) Sets the default character.voidsetDirectionality(GUIFontType.Directionality directionality) Sets this font's directionality.voidSets the name of this font.voidsetTexture(String texture) Sets the texture to use for this mapping.
-
Field Details
-
name
Name of the font. -
texture
Texture name for this font. -
fontMap
HashMap for the font map. -
defaultChar
Default character to return if the character is not in the map. -
directionality
Type of directionality to use.
-
-
Constructor Details
-
GUIFont
Creates an GUIFont from a texture.- Parameters:
texture- the texture.
-
GUIFont
-
-
Method Details
-
getName
- Specified by:
getNamein interfaceGUIFontType- Returns:
- the name of this font.
-
setName
Sets the name of this font.- Parameters:
name- the name of the font.
-
getTexture
- Specified by:
getTexturein interfaceGUIFontType- Returns:
- the texture to use for this mapping.
-
setTexture
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
Description copied from interface:GUIFontTypeGets a character's definition from the map.- Specified by:
getCharin interfaceGUIFontType- 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
- Specified by:
getDirectionalityin interfaceGUIFontType- Returns:
- this font's directionality.
-
setDirectionality
Sets this font's directionality.- Parameters:
directionality- the lettering directionality.
-
makeMonospaceFont
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
charsPerRowandalphabet.If
charsPerRowis 3, the divisions are:Divisions 0 1 2 3 4 5 6 7 8 If
charsPerRowis 4 butalphabet.length() is 15, the divisions are:Divisions 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 If
charsPerRowis 4 butalphabet.length() is 11, the divisions are:Divisions 0 1 2 3 4 5 6 7 8 9 10 - 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
charsPerRowandalphabet.If
charsPerRowis 3, the divisions are:Divisions 0 1 2 3 4 5 6 7 8 If
charsPerRowis 4 butalphabet.length() is 15, the divisions are:Divisions 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 If
charsPerRowis 4 butalphabet.length() is 11, the divisions are:Divisions 0 1 2 3 4 5 6 7 8 9 10 - 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
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
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.
-