public class FontRenderer extends java.lang.Object implements IResourceManagerReloadListener
Modifier and Type | Field and Description |
---|---|
protected int[] |
charWidth
Array of width of all the characters in default.png
|
int |
FONT_HEIGHT
the height in pixels of default text
|
java.util.Random |
fontRandom |
protected byte[] |
glyphWidth
Array of the start/end column (in upper/lower nibble) for every glyph in the /font directory.
|
protected ResourceLocation |
locationFontTexture |
protected float |
posX
Current X coordinate at which to draw the next character.
|
protected float |
posY
Current Y coordinate at which to draw the next character.
|
Constructor and Description |
---|
FontRenderer(GameSettings gameSettingsIn,
ResourceLocation location,
TextureManager textureManagerIn,
boolean unicode) |
Modifier and Type | Method and Description |
---|---|
protected void |
bindTexture(ResourceLocation location) |
protected void |
doDraw(float f) |
void |
drawSplitString(java.lang.String str,
int x,
int y,
int wrapWidth,
int textColor)
Splits and draws a String with wordwrap (maximum length is parameter k)
|
int |
drawString(java.lang.String text,
float x,
float y,
int color,
boolean dropShadow)
Draws the specified string.
|
int |
drawString(java.lang.String text,
int x,
int y,
int color)
Draws the specified string.
|
int |
drawStringWithShadow(java.lang.String text,
float x,
float y,
int color)
Draws the specified string with a shadow.
|
protected void |
enableAlpha() |
boolean |
getBidiFlag()
Get bidiFlag that controls if the Unicode Bidirectional Algorithm should be run before rendering any string
|
int |
getCharWidth(char character)
Returns the width of this character as rendered.
|
int |
getColorCode(char character) |
static java.lang.String |
getFormatFromString(java.lang.String text)
Digests a string for nonprinting formatting characters then returns a string containing only that formatting.
|
protected IResource |
getResource(ResourceLocation location) |
int |
getStringWidth(java.lang.String text)
Returns the width of this string.
|
boolean |
getUnicodeFlag()
Get unicodeFlag controlling whether strings should be rendered with Unicode fonts instead of the default.png
font.
|
int |
getWordWrappedHeight(java.lang.String str,
int maxLength)
Returns the height (in pixels) of the given string if it is wordwrapped to the given max width.
|
java.util.List<java.lang.String> |
listFormattedStringToWidth(java.lang.String str,
int wrapWidth)
Breaks a string into a list of pieces where the width of each line is always less than or equal to the provided
width.
|
void |
onResourceManagerReload(IResourceManager resourceManager) |
protected float |
renderDefaultChar(int ch,
boolean italic)
Render a single character with the default.png font at current (posX,posY) location...
|
protected float |
renderUnicodeChar(char ch,
boolean italic)
Render a single Unicode character at current (posX,posY) location using one of the /font/glyph_XX.png files...
|
void |
setBidiFlag(boolean bidiFlagIn)
Set bidiFlag to control if the Unicode Bidirectional Algorithm should be run before rendering any string.
|
protected void |
setColor(float r,
float g,
float b,
float a) |
void |
setUnicodeFlag(boolean unicodeFlagIn)
Set unicodeFlag controlling whether strings should be rendered with Unicode fonts instead of the default.png
font.
|
java.lang.String |
trimStringToWidth(java.lang.String text,
int width)
Trims a string to fit a specified Width.
|
java.lang.String |
trimStringToWidth(java.lang.String text,
int width,
boolean reverse)
Trims a string to a specified width, optionally starting from the end and working backwards.
|
protected final int[] charWidth
public int FONT_HEIGHT
public java.util.Random fontRandom
protected final byte[] glyphWidth
protected final ResourceLocation locationFontTexture
protected float posX
protected float posY
public FontRenderer(GameSettings gameSettingsIn, ResourceLocation location, TextureManager textureManagerIn, boolean unicode)
public void onResourceManagerReload(IResourceManager resourceManager)
onResourceManagerReload
in interface IResourceManagerReloadListener
protected float renderDefaultChar(int ch, boolean italic)
protected float renderUnicodeChar(char ch, boolean italic)
public int drawStringWithShadow(java.lang.String text, float x, float y, int color)
public int drawString(java.lang.String text, int x, int y, int color)
public int drawString(java.lang.String text, float x, float y, int color, boolean dropShadow)
protected void doDraw(float f)
public int getStringWidth(java.lang.String text)
public int getCharWidth(char character)
public java.lang.String trimStringToWidth(java.lang.String text, int width)
text
- The text to trimwidth
- The width to trim to (in pixels)public java.lang.String trimStringToWidth(java.lang.String text, int width, boolean reverse)
getCharWidth(char)
returns 6
for all of the characters in
0123456789
on the current resource pack)
trimStringToWidth("0123456789", 1, false)
trimStringToWidth("0123456789", 6, false)
trimStringToWidth("0123456789", 29, false)
trimStringToWidth("0123456789", 30, false)
trimStringToWidth("0123456789", 9001, false)
trimStringToWidth("0123456789", 1, true)
trimStringToWidth("0123456789", 6, true)
trimStringToWidth("0123456789", 29, true)
trimStringToWidth("0123456789", 30, true)
trimStringToWidth("0123456789", 9001, true)
text
- The text to trimwidth
- The width to trim to (in pixels)reverse
- If true, starts from the end of the string and works backwords, rather than starting from the
start and working forwards. Even if true, the final string will be in the correct order.public void drawSplitString(java.lang.String str, int x, int y, int wrapWidth, int textColor)
public int getWordWrappedHeight(java.lang.String str, int maxLength)
public void setUnicodeFlag(boolean unicodeFlagIn)
public boolean getUnicodeFlag()
public void setBidiFlag(boolean bidiFlagIn)
public java.util.List<java.lang.String> listFormattedStringToWidth(java.lang.String str, int wrapWidth)
public static java.lang.String getFormatFromString(java.lang.String text)
public boolean getBidiFlag()
protected void setColor(float r, float g, float b, float a)
protected void enableAlpha()
protected void bindTexture(ResourceLocation location)
protected IResource getResource(ResourceLocation location) throws java.io.IOException
java.io.IOException
public int getColorCode(char character)