Class TextGraphics

java.lang.Object
ch.epfl.cs107.play.math.Node
ch.epfl.cs107.play.engine.actor.TextGraphics
All Implemented Interfaces:
Graphics, Attachable, Positionable

public class TextGraphics extends Node implements Graphics
Contains information to render a single string, which can be attached to any positionable.
  • Constructor Details

    • TextGraphics

      public TextGraphics(String text, float fontSize, Color fillColor, Color outlineColor, float thickness, boolean bold, boolean italics, Vector anchor, TextAlign.Horizontal hAlign, TextAlign.Vertical vAlign, float alpha, float depth)
      Creates a new text graphics.
      Parameters:
      text - (String): content, not null
      fontSize - (float): size
      fillColor - (Color): fill color, may be null
      outlineColor - (Color): outline color, may be null
      thickness - (float): outline thickness
      bold - (boolean): whether to use bold font
      italics - (boolean): whether to use italics font
      anchor - (Vector): text anchor
      hAlign - (TextAlign.Horizontal): the horizontal alignment
      vAlign - (TextAlign.Vertical): the vertical alignment
      alpha - (float): transparency, between 0 (invisible) and 1 (opaque)
      depth - (float): render priority, lower-values drawn first
    • TextGraphics

      public TextGraphics(String text, float fontSize, Color fillColor, Color outlineColor, float thickness, boolean bold, boolean italics, Vector anchor)
      Creates a new text graphics.
      Parameters:
      text - (String): content, not null
      fontSize - (float): size
      fillColor - (Color): fill color, may be null
      outlineColor - (Color): outline color, may be null
      thickness - (float): outline thickness
      bold - (boolean): whether to use bold font
      italics - (boolean): whether to use italics font
      anchor - (Vector): text anchor
    • TextGraphics

      public TextGraphics(String text, float fontSize, Color fillColor)
      Creates a new text graphics.
      Parameters:
      text - (String): content, not null
      fontSize - (float): size
      fillColor - (Color): fill color, may be null
  • Method Details

    • setText

      public void setText(String text)
      Sets text content.
      Parameters:
      text - (String): content, not null
    • getText

      public String getText()
      Returns:
      (String): text content, not null
    • setFontSize

      public void setFontSize(float fontSize)
      Sets font size.
      Parameters:
      fontSize - (float): size
    • getFontSize

      public float getFontSize()
      Returns:
      (float): font size
    • setFillColor

      public void setFillColor(Color fillColor)
      Sets fill color.
      Parameters:
      fillColor - (Color): color, may be null
    • getFillColor

      public Color getFillColor()
      Returns:
      (Color): fill color, may be null
    • setOutlineColor

      public void setOutlineColor(Color outlineColor)
      Sets outline color.
      Parameters:
      outlineColor - (Color): color, may be null
    • getOutlineColor

      public Color getOutlineColor()
      Returns:
      (Color): outline color, may be null
    • setThickness

      public void setThickness(float thickness)
      Sets outline thickness.
      Parameters:
      thickness - (float): outline thickness
    • getThickness

      public float getThickness()
      Returns:
      (float): outline thickness
    • setFontName

      public void setFontName(String fontName)
      Set the font name
      Parameters:
      fontName - (String): the font name
    • getFontName

      public String getFontName()
      Returns:
      (String): the font name
    • setBold

      public void setBold(boolean bold)
      Sets bold font.
      Parameters:
      bold - (boolean): whether to use bold font
    • isBold

      public boolean isBold()
      Returns:
      (boolean): whether to use bold font
    • setItalics

      public void setItalics(boolean italics)
      Sets italics font.
      Parameters:
      italics - (boolean): whether to use italics font
    • isItalics

      public boolean isItalics()
      Returns:
      (boolean): whether to use italics font
    • setAnchor

      public void setAnchor(Vector anchor)
      Sets text anchor, i.e. how to orient it.
      Parameters:
      anchor - (Vector): text anchor
    • getAnchor

      public Vector getAnchor()
      Returns:
      (Vector): text anchor
    • setAlpha

      public void setAlpha(float alpha)
      Sets transparency.
      Parameters:
      alpha - (float): transparency, between 0 (invisible) and 1 (opaque)
    • getAlpha

      public float getAlpha()
      Returns:
      (float): transparency, between 0 (invisible) and 1 (opaque)
    • setDepth

      public void setDepth(float depth)
      Sets rendering depth.
      Parameters:
      depth - (float): render priority, lower-values drawn first
    • getDepth

      public float getDepth()
      Returns:
      (float): render priority, lower-values drawn first
    • draw

      public void draw(Canvas canvas)
      Description copied from interface: Graphics
      Renders itself on specified canvas.
      Specified by:
      draw in interface Graphics
      Parameters:
      canvas - target, not null