Class TextFieldEntity

java.lang.Object
org.boxutil.base.BaseRenderData
org.boxutil.units.standard.entity.TextFieldEntity
All Implemented Interfaces:
RenderDataAPI

public class TextFieldEntity extends BaseRenderData
Put in to rendering manage is not required, can direct creating and use it.

Recommend put in to the highest layer if you use rendering manage.

Only draws color and emissive to framebuffer color attachment.

Loading font info or submit string will both cost some time, usual should to preload it.

Anchor at top-left of text field.

Remember to register your font texture at settings.json, or load texture by TextureManager and set it later.

Use RESERVED_SYMBOL for create empty character (will not display anything), if you will display a dynamic value or text such as flux value.

One of the ways for how to change the text content in existed TextData:

 
 TextFieldEntity text;
 final var data = text.getTextDataList().get(0); // if the text content was in the index 0
 data.setText("another text");
 data.setColor(Color.RED);
 // and then call submit
 
 
  • Field Details

    • RESERVED_SYMBOL

      public static final char RESERVED_SYMBOL
      See Also:
    • LINE_FEED_SYMBOL

      public static final char LINE_FEED_SYMBOL
      See Also:
    • NOT_FOUND_SYMBOL

      public static final char NOT_FOUND_SYMBOL
      See Also:
    • _DEFAULT_PAD

      protected static final byte _DEFAULT_PAD
      See Also:
    • _VBO_SHORT_COUNT

      protected static final byte _VBO_SHORT_COUNT
      See Also:
    • _MAX_FONT_MAP

      protected static final byte _MAX_FONT_MAP
      See Also:
    • _textFieldID

      protected final int _textFieldID
    • _textFieldVBO

      protected final int _textFieldVBO
    • _isValid

      protected volatile boolean _isValid
    • fontMapList

      protected FontMapData[] fontMapList
    • textDataRefreshState

      protected final int[] textDataRefreshState
    • textStateAfterSubmit

      protected final float[] textStateAfterSubmit
    • _lastTextDataList

      protected List<TextFieldEntity.TextData> _lastTextDataList
    • _lastTextDataState

      protected List<org.lwjgl.util.vector.Vector4f> _lastTextDataState
    • _submitFeedback

      protected TextSubmitFeedbackAPI _submitFeedback
    • state

      protected final float[] state
    • stateB

      protected final boolean[] stateB
    • alignment

      protected TextFieldEntity.Alignment alignment
    • bindTextureBuf

      protected final IntBuffer bindTextureBuf
  • Constructor Details

    • TextFieldEntity

      public TextFieldEntity(boolean dynamicRefresh)
    • TextFieldEntity

      public TextFieldEntity()
    • TextFieldEntity

      public TextFieldEntity(@NotNull FontMapData map, boolean dynamicRefresh)
    • TextFieldEntity

      public TextFieldEntity(@NotNull FontMapData map)
    • TextFieldEntity

      public TextFieldEntity(@NotNull String fontPath, boolean dynamicRefresh)
    • TextFieldEntity

      public TextFieldEntity(@NotNull String fontPath)
  • Method Details

    • _StatePackageStack

      protected int _StatePackageStack()
      Overrides:
      _StatePackageStack in class BaseRenderData
    • initResourceLayout

      protected void initResourceLayout()
    • getFontFieldID

      public int getFontFieldID()
    • getFontFieldVBO

      public int getFontFieldVBO()
    • isValid

      public boolean isValid()
    • getFontMapArray

      public FontMapData[] getFontMapArray()
    • setFontMap

      public void setFontMap(@NotNull FontMapData map)
      Apply for the first map.
      Parameters:
      map - all the font height (or font size) should be near or equal.
    • setFontMap

      public void setFontMap(@NotNull FontMapData map, byte index)
      Can use at most four maps.
      Parameters:
      map - all the font height (or font size) should be near or equal.
    • setFontMap

      public void setFontMap(@NotNull String fontPath, byte index)
      Can use at most four maps.
      Parameters:
      fontPath - all the font height (or font size) should be near or equal.
    • _deleteExc

      protected void _deleteExc()
      Overrides:
      _deleteExc in class BaseRenderData
    • putShaderTextures

      public void putShaderTextures()
    • glDraw

      public void glDraw()
      Specified by:
      glDraw in interface RenderDataAPI
      Overrides:
      glDraw in class BaseRenderData
    • directDraw

      public void directDraw()
      You can directly call it when need display the text.

      And must call BaseRenderData.delete() if unneeded.

    • directDrawDetachedBegin

      public static int directDrawDetachedBegin()
      For anyone wanna made custom text rendering plugin.
      Returns:
      send to directDrawDetachedEnd(int)
    • directDrawDetachedProcess

      public void directDrawDetachedProcess()
    • directDrawDetachedEnd

      public static void directDrawDetachedEnd(int valueFromBeginReturns)
    • _resetExc

      protected void _resetExc()
      Overrides:
      _resetExc in class BaseRenderData
    • reset

      public void reset()
      Excludes text data.
      Specified by:
      reset in interface RenderDataAPI
      Overrides:
      reset in class BaseRenderData
    • resetText

      public void resetText()
    • createTextData

      protected TextFieldEntity.TextData createTextData(String text, float padding, Color color, boolean invert, boolean italic, boolean underline, boolean strikeout, int fontMapIndex)
    • addText

      public TextFieldEntity.TextData addText(String text, float padding, Color color, boolean invert, boolean italic, boolean underline, boolean strikeout, int fontMapIndex)
      Parameters:
      padding - offset when line feed.
    • addText

      public TextFieldEntity.TextData addText(String text, float padding, int fontMapIndex)
      Parameters:
      padding - offset when line feed.
    • addText

      public TextFieldEntity.TextData addText(String text, Color color, int fontMapIndex)
    • addText

      public TextFieldEntity.TextData addText(String text, int fontMapIndex)
    • replaceTextAtParagraph

      public TextFieldEntity.TextData replaceTextAtParagraph(@NotNull String text, float padding, Color color, boolean invert, boolean italic, boolean underline, boolean strikeout, int fontMapIndex, int paragraphIndex)
      Parameters:
      padding - offset when line feed.
      Returns:
      the text data previously at the specified position.
    • replaceTextAtParagraph

      public TextFieldEntity.TextData replaceTextAtParagraph(@NotNull String text, float padding, int fontMapIndex, int paragraphIndex)
      Parameters:
      padding - offset when line feed.
      Returns:
      the text data previously at the specified position.
    • replaceTextAtParagraph

      public TextFieldEntity.TextData replaceTextAtParagraph(@NotNull String text, int fontMapIndex, int paragraphIndex)
      Returns:
      the text data previously at the specified position.
    • submitText

      public byte submitText()
      Cost 26 Byte of vRAM each character, that if it had 32768 characters will cost 832 KiB of vRAM.

      If insufficient space exists on allocated buffer space, will lose data what the text data is not include in current submit.

      Returns:
      return BoxEnum.STATE_SUCCESS when success.

      return BoxEnum.STATE_FAILED when an empty text data list or refresh count is zero.

      return BoxEnum.STATE_FAILED_OTHER when happened another error.

    • mallocTextData

      public byte mallocTextData(int charNum)
      Optional.

      Just malloc() without any submit call.

      Parameters:
      charNum - must be positive integer.
      Returns:
      return BoxEnum.STATE_SUCCESS when success.

      return BoxEnum.STATE_FAILED when parameter error.

      return BoxEnum.STATE_FAILED_OTHER when happened another error.

    • getSubmitFeedback

      public TextSubmitFeedbackAPI getSubmitFeedback()
    • setSubmitFeedback

      public void setSubmitFeedback(TextSubmitFeedbackAPI plugin)
    • isRefreshRenderingLengthWhenSubmit

      public boolean isRefreshRenderingLengthWhenSubmit()
    • setRefreshRenderingLengthWhenSubmit

      public void setRefreshRenderingLengthWhenSubmit(boolean refresh)
    • isSynchronousSubmit

      public boolean isSynchronousSubmit()
      Default value is false.
    • setSynchronousSubmit

      public void setSynchronousSubmit(boolean sync)
      High performance impact when is synchronized.
    • isMappingModeSubmitData

      public boolean isMappingModeSubmitData()
      Default value is true.
    • setMappingModeSubmitData

      public void setMappingModeSubmitData(boolean mappingMode)
      For some very slight data, use glBufferSubData() may faster.

      Besides, some devices(some ARM SoC) may slower with glMapBufferRange(), decided by the drive how implements it.

      Parameters:
      mappingMode - to controls whether submit use glMapBufferRange(), else use glBufferSubData().
    • getTextDataRefreshIndex

      public int getTextDataRefreshIndex()
    • setTextDataRefreshIndex

      public void setTextDataRefreshIndex(int index)
      Parameters:
      index - Will refresh text data start from the index.
    • setTextDataRefreshSize

      public void setTextDataRefreshSize(int size)
      Parameters:
      size - Will refresh text data count.
    • setTextDataRefreshAllFromCurrentIndex

      public void setTextDataRefreshAllFromCurrentIndex()
    • getTextDataList

      public List<TextFieldEntity.TextData> getTextDataList()
    • getAllocatedValidCharLength

      public int getAllocatedValidCharLength()
    • haveAllocatedValidCharLength

      public boolean haveAllocatedValidCharLength()
    • getValidCharLength

      public int getValidCharLength()
    • isValidRenderingTextField

      public boolean isValidRenderingTextField()
    • setShouldRenderingCharCount

      public void setShouldRenderingCharCount(int charNum)
    • getAlignment

      public TextFieldEntity.Alignment getAlignment()
    • setAlignment

      public void setAlignment(TextFieldEntity.Alignment alignment)
    • getFontWidthSpace

      public float getFontWidthSpace()
    • getFontHeightSpace

      public float getFontHeightSpace()
    • getTextFieldWidth

      public float getTextFieldWidth()
    • getTextFieldHeight

      public float getTextFieldHeight()
    • setFontWidthSpace

      public void setFontWidthSpace(float space)
      Parameters:
      space - interval to previous font.
    • setFontHeightSpace

      public void setFontHeightSpace(float space)
      Parameters:
      space - line interval to previous line of same(only) text data.
    • setFontSpace

      public void setFontSpace(float width, float height)
    • setFieldWidth

      public void setFieldWidth(float width)
    • setFieldHeight

      public void setFieldHeight(float height)
    • setFieldSize

      public void setFieldSize(float width, float height)
    • getCurrentVisualWidth

      public float getCurrentVisualWidth()
      After called submitText().

      But only counts for last submit call, not for the entity.

    • getCurrentVisualHeight

      public float getCurrentVisualHeight()
      After called submitText().
    • getCurrentItalicFactor

      public float getCurrentItalicFactor()
    • setItalicFactor

      public void setItalicFactor(float angle)
      Parameters:
      angle - range at [-90, 90].
    • setItalicFactorDirect

      public void setItalicFactorDirect(float value)
      Parameters:
      value - value of sin, and angle range at [-90, 90].
    • setDefaultItalicFactor

      public void setDefaultItalicFactor()
    • getGlobalColorArray

      public float[] getGlobalColorArray()
    • getGlobalColorC

      public Color getGlobalColorC()
    • getGlobalColor

      public org.lwjgl.util.vector.Vector4f getGlobalColor()
    • getGlobalColorAlpha

      public float getGlobalColorAlpha()
    • getGlobalColorAlphaI

      public int getGlobalColorAlphaI()
    • setGlobalColor

      public void setGlobalColor(float r, float g, float b, float a)
    • setGlobalColor

      public void setGlobalColor(org.lwjgl.util.vector.Vector4f color)
    • setGlobalColor

      public void setGlobalColor(Color color)
    • getBloomColorArray

      public float[] getBloomColorArray()
    • getBloomColorC

      public Color getBloomColorC()
    • getBloomColor

      public org.lwjgl.util.vector.Vector4f getBloomColor()
    • getBloomStrength

      public float getBloomStrength()
    • setBloomColor

      public void setBloomColor(float r, float g, float b, float a)
      Parameters:
      a - bloom strength
    • setBloomColor

      public void setBloomColor(org.lwjgl.util.vector.Vector4f color)
    • setBloomColor

      public void setBloomColor(Color color)
    • setBloomColorStrength

      public void setBloomColorStrength(float strength)
    • isBlendBloomColor

      public boolean isBlendBloomColor()
    • setBlendBloomColor

      public void setBlendBloomColor(boolean blend)
      Parameters:
      blend - the bloom color is bloom color blend in font color when true, use bloom color when false.
    • submitEntityData

      public void submitEntityData()
      Description copied from class: BaseRenderData
      Without matrix data or timer settings.
      Specified by:
      submitEntityData in interface RenderDataAPI
      Overrides:
      submitEntityData in class BaseRenderData
    • entityType

      public Object entityType()
      Specified by:
      entityType in interface RenderDataAPI
      Overrides:
      entityType in class BaseRenderData