Class LazyFont.DrawableString

Object
DrawableString
Enclosing class:
LazyFont

public class LazyFont.DrawableString extends Object
Represents an efficiently redrawable block of text. See the documentation for LazyFont for example usage.
Since:
2.3
Author:
LazyWizard
  • Method Details

    • getFont

      public LazyFont getFont()
      Returns a reference to the LazyFont used to create this LazyFont.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 as getMaxWidth() - 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 as getMaxHeight() - 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.DrawableString the 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.DrawableString the 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.DrawableString the 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

      public LazyFont.TextAnchor getAnchor()
      Returns the current anchor (origin when drawing) for this LazyFont.DrawableString.
      Returns:
      The current anchor (origin of drawing) for this LazyFont.DrawableString.
      Since:
      2.7
      See Also:
    • setAnchor

      public void setAnchor(LazyFont.TextAnchor anchor)
      Sets the anchor (origin when drawing) for this LazyFont.DrawableString.
      Parameters:
      anchor - The new anchor (origin of drawing) for this LazyFont.DrawableString.
      Since:
      2.7
      See Also:
    • getAlignment

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

      public void setAlignment(LazyFont.TextAlignment alignment)
      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

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

      public void setBaseColor(Color color)
      Sets the default color of drawn text.
      Parameters:
      color - The color text will be drawn as if not overridden in append(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:
      true if bounds rendering is enabled, false otherwise.
      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, false otherwise.
      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 calling getWidth() or getHeight() between GL11.glBegin(int) and GL11.glEnd() on a LazyFont.DrawableString that needs to be rebuilt, as those methods trigger a rebuild which will fail if called inside those two methods. Calling triggerRebuildIfNeeded() before GL11.glBegin(int) will solve this problem.
      Since:
      2.7
    • getText

      public String getText()
      Returns the raw text of this LazyFont.DrawableString, before any word-wrapping is applied. Performance note: due to the underlying text being stored in a StringBuilder, a new String will 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

      public void setText(String text)
      Replaces all text in the LazyFont.DrawableString with the entered String.

      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 String to set this LazyFont.DrawableString's contents to.
      Since:
      2.3
    • append

      public LazyFont.DrawableString append(String text)
      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 the LazyFont.DrawableString.
      Returns:
      This LazyFont.DrawableString, for easier chaining of append calls.
      Since:
      2.6
    • append

      public LazyFont.DrawableString append(String text, Color color)
      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 by getBaseColor().

      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 the LazyFont.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

      public LazyFont.DrawableString appendIndented(String text, int indent)
      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 the LazyFont.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

      public LazyFont.DrawableString appendIndented(String text, Color color, int indent)
      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 by getBaseColor().

      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 the LazyFont.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

      public void draw(Vector2f location)
      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

      public void drawAtAngle(Vector2f location, 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:
      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 a RuntimeException!
      Returns:
      true if dispose() has been called; false otherwise.
      Since:
      2.3
    • dispose

      public void dispose()
      Cleans up the underlying OpenGL resources of this LazyFont.DrawableString. Calling any draw() method after this will cause a RuntimeException.

      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