Class LazyFont.DrawableString
- Enclosing class:
- LazyFont
LazyFont for example usage.- Since:
- 2.3
- Author:
- LazyWizard
-
Method Summary
Modifier and TypeMethodDescriptionAdds additional text to the end of the current text.Adds a colored substring to the end of the current text.appendIndented(String text, int indent) Adds additional text to the end of the current text, with indentation.appendIndented(String text, Color color, int indent) Adds a colored substring to the end of the current text, with indentation.voiddispose()Cleans up the underlying OpenGL resources of thisLazyFont.DrawableString.voiddraw(float x, float y) Renders the text area at the specified coordinates.voidRenders the text area at the specified coordinates.voiddrawAtAngle(float x, float y, float angle) Renders the text area at the specified coordinates with the specified angle.voiddrawAtAngle(Vector2f location, float angle) Renders the text area at the specified coordinates with the specified angle.Returns which side of the text area the text will be aligned with.Returns the current anchor (origin when drawing) for thisLazyFont.DrawableString.Returns the default color of drawn text.intReturns the blend destination factor used by glBlendFunc() when rendering this block of text.intReturns the blend source factor used by glBlendFunc() when rendering this block of text.getFont()Returns a reference to theLazyFontused to create thisLazyFont.DrawableString.floatReturns the font size text will be drawn at.floatReturns the height of the rendered text area.floatReturns the maximum height of the area that this text will be rendered within.floatReturns the maximum width of the area that this text will be rendered within.booleanReturns whether bounds drawing is enabled.getText()Returns the raw text of thisLazyFont.DrawableString, before any word-wrapping is applied.floatgetWidth()Returns the width of the rendered text area.booleanWhether this object's underlying OpenGL resources have been cleaned up - attempting to render after disposal will cause aRuntimeException!booleanReturns whether a method has been performed since the last draw call that will trigger a rebuild.voidsetAlignment(LazyFont.TextAlignment alignment) Sets which side of the text area the text will be aligned with.voidsetAnchor(LazyFont.TextAnchor anchor) Sets the anchor (origin when drawing) for thisLazyFont.DrawableString.voidsetBaseColor(Color color) Sets the default color of drawn text.voidsetBlendDest(int blendDest) Sets the blend destination factor used by glBlendFunc() when rendering this block of text.voidsetBlendSrc(int blendSrc) Sets the blend source factor used by glBlendFunc() when rendering this block of text.voidsetFontSize(float fontSize) Changes the font size that this text will be rendered at.voidsetMaxHeight(float maxHeight) Changes the maximum height of the area that this text will be rendered within.voidsetMaxWidth(float maxWidth) Changes the maximum width of the area that this text will be rendered within.voidsetRenderDebugBounds(boolean renderDebugBounds) Sets whether bounds drawing is enabled.voidReplaces all text in theLazyFont.DrawableStringwith the enteredString.voidTriggers a rebuild of the native GPU buffers if needed.
-
Method Details
-
getFont
Returns a reference to theLazyFontused to create thisLazyFont.DrawableString.- Returns:
- The font used to create this
LazyFont.DrawableString. - Since:
- 2.3
-
getWidth
public float getWidth()Returns the width of the rendered text area. This is not the same asgetMaxWidth()- this only considers the area used by the text.- Returns:
- The width of the text area to be rendered.
- Since:
- 2.3
-
getHeight
public float getHeight()Returns the height of the rendered text area. This is not the same asgetMaxHeight()- this only considers the area used by the text.- Returns:
- The height of the text area to be rendered.
- Since:
- 2.3
-
getFontSize
public float getFontSize()Returns the font size text will be drawn at.- Returns:
- The font size of this
LazyFont.DrawableString. - Since:
- 2.3
-
setFontSize
public void setFontSize(float fontSize) Changes the font size that this text will be rendered at.Changing the font size will necessitate a full rebuild of the
LazyFont.DrawableStringthe next time you attempt to draw or measure the text.- Parameters:
fontSize- The new font size to render at.- Since:
- 2.3
-
getMaxWidth
public float getMaxWidth()Returns the maximum width of the area that this text will be rendered within.- Returns:
- The maximum width of the text area. Text will wrapped at the last word that fit within this area.
- Since:
- 2.3
-
setMaxWidth
public void setMaxWidth(float maxWidth) Changes the maximum width of the area that this text will be rendered within.Changing the text area constraints will necessitate a full rebuild of the
LazyFont.DrawableStringthe next time you attempt to draw or measure the text.- Parameters:
maxWidth- The nex maximum width of the text area. Text will be wrapped at the last word that fit within this area.- Since:
- 2.3
-
getMaxHeight
public float getMaxHeight()Returns the maximum height of the area that this text will be rendered within.- Returns:
- The maximum height of the text area. Further text will be discarded once this limit is reached.
- Since:
- 2.3
-
setMaxHeight
public void setMaxHeight(float maxHeight) Changes the maximum height of the area that this text will be rendered within.Changing the text area constraints will necessitate a full rebuild of the
LazyFont.DrawableStringthe next time you attempt to draw or measure the text.- Parameters:
maxHeight- The nex maximum height of the text area. Further text will be discarded once this limit is reached.- Since:
- 2.3
-
getAnchor
Returns the current anchor (origin when drawing) for thisLazyFont.DrawableString.- Returns:
- The current anchor (origin of drawing) for this
LazyFont.DrawableString. - Since:
- 2.7
- See Also:
-
setAnchor
Sets the anchor (origin when drawing) for thisLazyFont.DrawableString.- Parameters:
anchor- The new anchor (origin of drawing) for thisLazyFont.DrawableString.- Since:
- 2.7
- See Also:
-
getAlignment
Returns which side of the text area the text will be aligned with.- Returns:
- Which side of the text area to align text to.
- Since:
- 2.7
- See Also:
-
setAlignment
Sets which side of the text area the text will be aligned with.- Parameters:
alignment- Which side of the text area to align text to.- Since:
- 2.7
- See Also:
-
getBaseColor
Returns the default color of drawn text.- Returns:
- The color text will be drawn as if not overridden in
append(String, Color). - Since:
- 2.7
-
setBaseColor
Sets the default color of drawn text.- Parameters:
color- The color text will be drawn as if not overridden inappend(String, Color).- Since:
- 2.7
-
getBlendDest
public int getBlendDest()Returns the blend destination factor used by glBlendFunc() when rendering this block of text. If you don't know what this means, you can ignore it. The defaults are fine in most situations.- Returns:
- The blend destination factor, by default
GL11.GL_ONE_MINUS_SRC_ALPHA. - Since:
- 2.6
-
setBlendDest
public void setBlendDest(int blendDest) Sets the blend destination factor used by glBlendFunc() when rendering this block of text. If you don't know what this means, you can ignore it. The defaults are fine in most situations.- Parameters:
blendDest- The blend destination factor to use when drawing text.- Since:
- 2.6
-
getBlendSrc
public int getBlendSrc()Returns the blend source factor used by glBlendFunc() when rendering this block of text. If you don't know what this means, you can ignore it. The defaults are fine in most situations.- Returns:
- The blend source factor, by default
GL11.GL_ONE. - Since:
- 2.6
-
setBlendSrc
public void setBlendSrc(int blendSrc) Sets the blend source factor used by glBlendFunc() when rendering this block of text. If you don't know what this means, you can ignore it. The defaults are fine in most situations.- Parameters:
blendSrc- The blend source factor to use when drawing text.- Since:
- 2.6
-
getRenderDebugBounds
public boolean getRenderDebugBounds()Returns whether bounds drawing is enabled. Used to visually show the size of a block of text for debugging/placement/resizing purposes.- Returns:
trueif bounds rendering is enabled,falseotherwise.- Since:
- 2.6
-
setRenderDebugBounds
public void setRenderDebugBounds(boolean renderDebugBounds) Sets whether bounds drawing is enabled. Used to visually show the size of a block of text for debugging/placement/resizing purposes.- Parameters:
renderDebugBounds- Whether to enable bounds drawing.- Since:
- 2.6
-
isRebuildNeeded
public boolean isRebuildNeeded()Returns whether a method has been performed since the last draw call that will trigger a rebuild. Most users will never need to call this.- Returns:
- {code true} if the next draw call will trigger a rebuild,
falseotherwise. - Since:
- 2.7
-
triggerRebuildIfNeeded
public void triggerRebuildIfNeeded()Triggers a rebuild of the native GPU buffers if needed. The only time this is necessary is if you're callinggetWidth()orgetHeight()betweenGL11.glBegin(int)andGL11.glEnd()on aLazyFont.DrawableStringthat needs to be rebuilt, as those methods trigger a rebuild which will fail if called inside those two methods. CallingtriggerRebuildIfNeeded()beforeGL11.glBegin(int)will solve this problem.- Since:
- 2.7
-
getText
Returns the raw text of thisLazyFont.DrawableString, before any word-wrapping is applied. Performance note: due to the underlying text being stored in aStringBuilder, a newStringwill be built every time this method is called.- Returns:
- The raw text of this
LazyFont.DrawableString(without word-wrapping applied). - Since:
- 2.3
- See Also:
-
setText
Replaces all text in theLazyFont.DrawableStringwith the enteredString.Changing a
LazyFont.DrawableString's text will necessitate a full rebuild of its contents the next time you attempt to draw or measure the text.- Parameters:
text- TheStringto set thisLazyFont.DrawableString's contents to.- Since:
- 2.3
-
append
Adds additional text to the end of the current text.Changing a
LazyFont.DrawableString's text will necessitate a full rebuild of its contents the next time you attempt to draw or measure the text.- Parameters:
text- The text to add to theLazyFont.DrawableString.- Returns:
- This
LazyFont.DrawableString, for easier chaining of append calls. - Since:
- 2.6
-
append
Adds a colored substring to the end of the current text. Only this substring will use the given color, and all further normally appended text will use the color returned bygetBaseColor().Changing a
LazyFont.DrawableString's text will necessitate a full rebuild of its contents the next time you attempt to draw or measure the text.- Parameters:
text- The text to add to theLazyFont.DrawableString.color- The color this substring of text should appear as. Existing text, as well as following append calls, will use their own color.- Returns:
- This
LazyFont.DrawableString, for easier chaining of append calls. - Since:
- 2.6
-
appendIndented
Adds additional text to the end of the current text, with indentation.Changing a
LazyFont.DrawableString's text will necessitate a full rebuild of its contents the next time you attempt to draw or measure the text.- Parameters:
text- The text to add to theLazyFont.DrawableString.indent- All lines will be prepended with this number of blank spaces.- Returns:
- This
LazyFont.DrawableString, for easier chaining of append calls. - Since:
- 2.6
-
appendIndented
Adds a colored substring to the end of the current text, with indentation. Only this substring will use the given color, and all further normally appended text will use the color returned bygetBaseColor().Changing a
LazyFont.DrawableString's text will necessitate a full rebuild of its contents the next time you attempt to draw or measure the text.- Parameters:
text- The text to add to theLazyFont.DrawableString.indent- All lines will be prepended with this number of blank spaces.color- The color this substring of text should appear as. Existing text, as well as following append calls, will use their own color.- Returns:
- This
LazyFont.DrawableString, for easier chaining of append calls. - Since:
- 2.6
-
draw
public void draw(float x, float y) Renders the text area at the specified coordinates. This method must be called once per frame.You can render the same block of text in multiple places. The OpenGL data is stored in a buffer on your GPU, so performance should not be an issue (provided the underlying data hasn't changed, necessitating a rebuild).
- Parameters:
x- The X coordinate to draw at.y- The Y coordinate to draw at.- Since:
- 2.3
-
draw
Renders the text area at the specified coordinates. This method must be called once per frame.You can render the same block of text in multiple places. The OpenGL data is stored in a buffer on your GPU, so performance should not be an issue (provided the underlying data hasn't changed, necessitating a rebuild).
- Parameters:
location- The coordinates to draw at.- Since:
- 2.3
-
drawAtAngle
public void drawAtAngle(float x, float y, float angle) Renders the text area at the specified coordinates with the specified angle. This method must be called once per frame.You can render the same block of text in multiple places. The OpenGL data is stored in a buffer on your GPU, so performance should not be an issue (provided the underlying data hasn't changed, necessitating a rebuild).
- Parameters:
x- The X coordinate to draw at.y- The Y coordinate to draw at.angle- The angle to draw at, in degrees.- Since:
- 2.3
-
drawAtAngle
Renders the text area at the specified coordinates with the specified angle. This method must be called once per frame.You can render the same block of text in multiple places. The OpenGL data is stored in a buffer on your GPU, so performance should not be an issue (provided the underlying data hasn't changed, necessitating a rebuild).
- Parameters:
location- The coordinates to draw at.angle- The angle to draw at, in degrees.- Since:
- 2.3
-
isDisposed
public boolean isDisposed()Whether this object's underlying OpenGL resources have been cleaned up - attempting to render after disposal will cause aRuntimeException!- Returns:
trueifdispose()has been called;falseotherwise.- Since:
- 2.3
-
dispose
public void dispose()Cleans up the underlying OpenGL resources of thisLazyFont.DrawableString. Calling any draw() method after this will cause aRuntimeException.Calling this method is optional. However, there are a limited number of buffers available, so if you are creating many thousands of
LazyFont.DrawableStrings you will need to call this when done with each to prevent the pool from being exhausted before the garbage collector can get around to cleaning them up for you.- Since:
- 2.3
-