Class BMText

All Implemented Interfaces:
Pickable, Hintable, Renderable, Savable
Direct Known Subclasses:
BasicText

public class BMText extends Mesh
Text spatial which uses textures generated by BMFont
  • Field Details

    • _font

      protected BMFont _font
    • _textString

      protected String _textString
    • _fontScale

      protected double _fontScale
    • _autoRotate

      protected boolean _autoRotate
    • _lines

      protected int _lines
    • _size

      protected final Vector2 _size
    • _lineWidths

      protected float[] _lineWidths
    • _textClr

      protected ColorRGBA _textClr
    • _tempClr

      protected ColorRGBA _tempClr
    • _listeners

      protected final List<BMTextChangeListener> _listeners
    • _autoScale

      protected BMText.AutoScale _autoScale
    • _autoFade

      protected BMText.AutoFade _autoFade
    • _fixedPixelAlphaThresh

      protected int _fixedPixelAlphaThresh
    • _screenSizeAlphaFalloff

      protected float _screenSizeAlphaFalloff
    • _distanceAlphaRange

      protected final Vector2 _distanceAlphaRange
    • _useBlend

      protected boolean _useBlend
    • _justify

      protected BMText.Justify _justify
    • _spacing

      protected int _spacing
    • _align

      protected BMText.Align _align
    • _alignOffset

      protected final Vector2 _alignOffset
    • _fixedOffset

      protected final Vector2 _fixedOffset
    • _look

      protected final Vector3 _look
    • _left

      protected final Vector3 _left
    • _rot

      protected final Matrix3 _rot
  • Constructor Details

    • BMText

      protected BMText()
    • BMText

      public BMText(String sName, String text, BMFont font)
      Parameters:
      sName - the spatial name
      text - the text to render
      font - the font
    • BMText

      public BMText(String sName, String text, BMFont font, BMText.Align align)
    • BMText

      public BMText(String sName, String text, BMFont font, BMText.Align align, BMText.Justify justify)
    • BMText

      public BMText(String sName, String text, BMFont font, BMText.Align align, BMText.Justify justify, boolean useBlend)
      Parameters:
      sName - the spatial name
      text - the text to render.
      font - the font
      align - the alignment
      justify - the justification
      useBlend - if true: use alpha blending and use transparent render bucket, else if false: alpha test only and use opaque render bucket
  • Method Details

    • initSavable

      public static BMText initSavable()
    • setTextColor

      public void setTextColor(ReadOnlyColorRGBA clr)
    • setTextColor

      public void setTextColor(float r, float g, float b, float a)
    • setFontScale

      public void setFontScale(double scale)
      If AutoScale is enabled, this scale parameter acts as a bias. Setting the scale to 0.95 will sharpen the font and increase readability a bit if you're using a bilinear min filter on the texture. When AutoScale is disabled, this scales the font to world units, e.g. setScale(1) would make the font characters approximately 1 world unit in size, regardless of the font point size.
      Parameters:
      scale - the scale
    • getFontScale

      public double getFontScale()
    • setAutoScale

      public void setAutoScale(BMText.AutoScale autoScale)
      Set scaling policy
      Parameters:
      autoScale - the scale policy to set
    • getAutoScale

      public BMText.AutoScale getAutoScale()
    • setAutoFade

      public void setAutoFade(BMText.AutoFade autoFade)
    • getAutoFade

      public BMText.AutoFade getAutoFade()
    • setAutoFadeFixedPixelSize

      public void setAutoFadeFixedPixelSize(int pixelSize)
    • getAutoFadeFixedPixelSize

      public int getAutoFadeFixedPixelSize()
    • setAutoFadeFalloff

      public void setAutoFadeFalloff(float factor)
      alpha falloff factor used when FixedPixelSize or CapScreenSize is used. Can be any positive value; useful range is ~ 0-2
      • 0 = transparent instantaneously
      • 1 = transparent when approximately 1/2 size
      Parameters:
      factor - the fall-off factor to set
    • setAutoFadeDistanceRange

      public void setAutoFadeDistanceRange(double nearOpaque, double farTransparent)
      Parameters:
      nearOpaque - text is completely opaque when distance between camera and text is less than this value
      farTransparent - text is completely transparent when distance between camera and text is greater than this value
    • setAutoRotate

      public void setAutoRotate(boolean doAutoTransform)
      automatically rotate test to face the camera
      Parameters:
      doAutoTransform - true if the automatic rotation is enabled
    • getAutoRotate

      public boolean getAutoRotate()
    • draw

      public void draw(Renderer r)
      Description copied from class: Spatial
      draw abstract method that handles drawing data to the renderer if it is geometry and passing the call to it's children if it is a node.
      Overrides:
      draw in class Mesh
      Parameters:
      r - the renderer used for display.
    • correctTransform

      public void correctTransform(Camera cam)
      Parameters:
      cam - the camera
    • updateScaleAndAlpha

      public void updateScaleAndAlpha(Camera cam, Renderer r)
      Update the text's scale
      Parameters:
      cam - the camera
      r - the renderer
    • screenSizeCapAlphaFade

      protected void screenSizeCapAlphaFade(double capSize, double depthScale, float alphaFallof)
      Set transparency based on native screen size.
      Parameters:
      capSize - 1/(font point size)
      depthScale - the depth scale
      alphaFallof - the alpha fall-off
    • distanceAlphaFade

      protected void distanceAlphaFade(ReadOnlyVector2 range, double distance)
      Set transparency based on distance from camera to text. if (distance < range.x) then opaque, if (distance > range.y) then transparent, else lerp
      Parameters:
      range - the range
      distance - the distance
    • getWidth

      public float getWidth()
      get width in world units
      Returns:
      the width in world units
    • getHeight

      public float getHeight()
      get height in world units
      Returns:
      the height in world units
    • addToLineSizes

      protected void addToLineSizes(float sizeX, int lineIndex)
    • calculateSize

      protected void calculateSize(String text)
      Parameters:
      text - the text to render
    • calculateAlignmentOffset

      protected void calculateAlignmentOffset()
    • checkBuffers

      protected void checkBuffers(String text)
      Check whether buffers have sufficient capacity to hold current string values; if not, increase capacity and set the limit.
      Parameters:
      text - the text to render
    • getJustificationXOffset

      protected float getJustificationXOffset(int lineIndex)
    • getFont

      public BMFont getFont()
    • setFont

      public void setFont(BMFont font)
    • setUseBlend

      public void setUseBlend(boolean useBlend)
      Parameters:
      useBlend - if true: use alpha blending and use transparent render bucket, else if false: alpha test only and use opaque render bucket
    • getUseBlend

      public boolean getUseBlend()
    • setText

      public void setText(String text)
      Set text string and recreate geometry
      Parameters:
      text - the text to render
    • getText

      public String getText()
    • setAlign

      public void setAlign(BMText.Align align)
      Parameters:
      align - the alignment
    • getAlign

      public BMText.Align getAlign()
    • setJustify

      public void setJustify(BMText.Justify justify)
    • getJustify

      public BMText.Justify getJustify()
    • setFixedOffset

      public void setFixedOffset(double x, double y)
      set a fixed offset from the alignment center of rotation IN FONT UNITS
      Parameters:
      x - the x value of the offset
      y - the y value of the offset
    • setFixedOffset

      public void setFixedOffset(ReadOnlyVector2 offset)
      set a fixed offset from the alignment center of rotation IN FONT UNITS
      Parameters:
      offset - the offset
    • getLineCount

      public int getLineCount()
    • getFixedOffset

      public ReadOnlyVector2 getFixedOffset()
    • getSize

      public ReadOnlyVector2 getSize()
    • addChangeListener

      public void addChangeListener(BMTextChangeListener listener)
    • removeChangeListener

      public boolean removeChangeListener(BMTextChangeListener listener)
    • makeCopy

      public BMText makeCopy(boolean shareGeometricData)
      Description copied from class: Spatial
      Create a copy of this spatial.
      Overrides:
      makeCopy in class Mesh
      Parameters:
      shareGeometricData - if true, reuse any data fields describing the geometric shape of the spatial, as applicable.
      Returns:
      the copy as described.