Class GUIText

java.lang.Object
engine.fontMeshCreator.GUIText

public class GUIText extends Object
Represents a piece of text in the game.
  • Constructor Details

    • GUIText

      public GUIText(String text, float fontSize, org.joml.Vector2f position, float maxLineLength, boolean centered)
      Creates a new text, loads the text's quads into a VAO, and adds the text to the screen.
      Parameters:
      text - - the text.
      fontSize - - the font size of the text, where a font size of 1 is the default size.
      position - - the position on the screen where the top left corner of the text should be rendered. The top left corner of the screen is (0, 0) and the bottom right is (1, 1).
      maxLineLength - - basically the width of the virtual page in terms of screen width (1 is full screen width, 0.5 is half the width of the screen, etc.) Text cannot go off the edge of the page, so if the text is longer than this length it will go onto the next line. When text is centered it is centered into the middle of the line, based on this line length value.
      centered - - whether the text should be centered or not.
  • Method Details

    • remove

      public void remove()
      Remove the text from the screen.
    • getFont

      public FontType getFont()
      Returns:
      The font used by this text.
    • setColour

      public void setColour(float r, float g, float b)
      Set the colour of the text.
      Parameters:
      r - - red value, between 0 and 1.
      g - - green value, between 0 and 1.
      b - - blue value, between 0 and 1.
    • getColour

      public org.joml.Vector3f getColour()
      Returns:
      the colour of the text.
    • getNumberOfLines

      public int getNumberOfLines()
      Returns:
      The number of lines of text. This is determined when the text is loaded, based on the length of the text and the max line length that is set.
    • getPosition

      public org.joml.Vector2f getPosition()
      Returns:
      The position of the top-left corner of the text in screen-space. (0, 0) is the top left corner of the screen, (1, 1) is the bottom right.
    • getMesh

      public int getMesh()
      Returns:
      the ID of the text's VAO, which contains all the vertex data for the quads on which the text will be rendered.
    • setMeshInfo

      public void setMeshInfo(int vao, int verticesCount)
      Set the VAO and vertex count for this text.
      Parameters:
      vao - - the VAO containing all the vertex data for the quads on which the text will be rendered.
      verticesCount - - the total number of vertices in all of the quads.
    • getVertexCount

      public int getVertexCount()
      Returns:
      The total number of vertices of all the text's quads.
    • getFontSize

      protected float getFontSize()
      Returns:
      the font size of the text (a font size of 1 is normal).
    • setNumberOfLines

      protected void setNumberOfLines(int number)
      Sets the number of lines that this text covers (method used only in loading).
      Parameters:
      number -
    • isCentered

      protected boolean isCentered()
      Returns:
      true if the text should be centered.
    • getMaxLineSize

      protected float getMaxLineSize()
      Returns:
      The maximum length of a line of this text.
    • getTextString

      public String getTextString()
      Returns:
      The string of text.
    • setTextString

      public void setTextString(String textString)