Class TextObject

java.lang.Object
com.catsoftware.engine.prism.draw.TextObject
All Implemented Interfaces:
DrawableObject, Serializable

public class TextObject extends Object implements DrawableObject, Serializable
A text object that can be drawn on the canvas. Supports custom fonts, colors, opacity, rotation, and resizing.
Since:
Prism B1
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    TextObject(String t, int x, int y, Font f, Color c, float a)
    Creates a new text object.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Checks if a point is inside/on this object.
    void
    Renders this object onto a graphics context.
    void
    fill(Graphics2D g, Color fillColor)
    Fills this object with the specified color.
    float
    Returns the opacity level.
    Returns the bounding rectangle of this object.
    Returns the text color.
    Returns the font.
    double
    Returns the current rotation angle.
    Returns the text content.
    int
    Returns the X coordinate.
    int
    Returns the Y coordinate.
    boolean
    Checks if this object has a gradient fill.
    void
    moveBy(int dx, int dy)
    Moves this object by the specified delta.
    void
    Removes gradient fill from this object.
    void
    resize(double scaleX, double scaleY)
    Scales this object by the given factors.
    void
    resizeAbsolute(int newWidth, int newHeight)
    Resizes this object to absolute dimensions.
    void
    rotate(double delta)
    Rotates this object by the specified delta.
    void
    setAlpha(float alpha)
    Sets the opacity level.
    void
    setColor(Color color)
    Sets the text color.
    void
    setFont(Font font)
    Sets the font.
    void
    setGradient(Color color1, Color color2, boolean horizontal)
    Sets a gradient (not supported for text - falls back to solid color).
    void
    setRotation(double degrees)
    Sets the rotation angle of this object.
    void
    Sets the text content.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • TextObject

      public TextObject(String t, int x, int y, Font f, Color c, float a)
      Creates a new text object.
      Parameters:
      t - The text content
      x - The X coordinate (baseline position)
      y - The Y coordinate (baseline position)
      f - The font to use
      c - The text color
      a - The opacity level (0.0 - 1.0)
  • Method Details

    • draw

      public void draw(Graphics2D g)
      Description copied from interface: DrawableObject
      Renders this object onto a graphics context.
      Specified by:
      draw in interface DrawableObject
      Parameters:
      g - The graphics context to draw on
    • contains

      public boolean contains(Point p)
      Description copied from interface: DrawableObject
      Checks if a point is inside/on this object. Used for selection and hit testing.
      Specified by:
      contains in interface DrawableObject
      Parameters:
      p - The point to check
      Returns:
      true if point is inside/on this object
    • moveBy

      public void moveBy(int dx, int dy)
      Description copied from interface: DrawableObject
      Moves this object by the specified delta.
      Specified by:
      moveBy in interface DrawableObject
      Parameters:
      dx - Horizontal offset
      dy - Vertical offset
    • getBounds

      public Rectangle getBounds()
      Description copied from interface: DrawableObject
      Returns the bounding rectangle of this object.
      Specified by:
      getBounds in interface DrawableObject
      Returns:
      The bounding box
    • resize

      public void resize(double scaleX, double scaleY)
      Description copied from interface: DrawableObject
      Scales this object by the given factors.
      Specified by:
      resize in interface DrawableObject
      Parameters:
      scaleX - Horizontal scale factor
      scaleY - Vertical scale factor
    • resizeAbsolute

      public void resizeAbsolute(int newWidth, int newHeight)
      Description copied from interface: DrawableObject
      Resizes this object to absolute dimensions.
      Specified by:
      resizeAbsolute in interface DrawableObject
      Parameters:
      newWidth - New width in pixels
      newHeight - New height in pixels
    • fill

      public void fill(Graphics2D g, Color fillColor)
      Description copied from interface: DrawableObject
      Fills this object with the specified color.
      Specified by:
      fill in interface DrawableObject
      Parameters:
      g - Graphics context (may be null for vector fills)
      fillColor - The color to fill with
    • setColor

      public void setColor(Color color)
      Sets the text color.
      Parameters:
      color - The new color
    • getText

      public String getText()
      Returns the text content.
      Returns:
      The text
    • getX

      public int getX()
      Returns the X coordinate.
      Returns:
      The X coordinate
    • getY

      public int getY()
      Returns the Y coordinate.
      Returns:
      The Y coordinate
    • getFont

      public Font getFont()
      Returns the font.
      Returns:
      The current font
    • getColor

      public Color getColor()
      Returns the text color.
      Returns:
      The current color
    • setText

      public void setText(String text)
      Sets the text content.
      Parameters:
      text - The new text
    • setFont

      public void setFont(Font font)
      Sets the font.
      Parameters:
      font - The new font
    • setAlpha

      public void setAlpha(float alpha)
      Sets the opacity level.
      Parameters:
      alpha - Value between 0.1 and 1.0
    • getAlpha

      public float getAlpha()
      Returns the opacity level.
      Returns:
      The current alpha value
    • setRotation

      public void setRotation(double degrees)
      Description copied from interface: DrawableObject
      Sets the rotation angle of this object.
      Specified by:
      setRotation in interface DrawableObject
      Parameters:
      degrees - Rotation angle in degrees
    • getRotation

      public double getRotation()
      Description copied from interface: DrawableObject
      Returns the current rotation angle.
      Specified by:
      getRotation in interface DrawableObject
      Returns:
      Rotation angle in degrees
    • rotate

      public void rotate(double delta)
      Description copied from interface: DrawableObject
      Rotates this object by the specified delta.
      Specified by:
      rotate in interface DrawableObject
      Parameters:
      delta - Degrees to add to current rotation
    • setGradient

      public void setGradient(Color color1, Color color2, boolean horizontal)
      Sets a gradient (not supported for text - falls back to solid color).
      Specified by:
      setGradient in interface DrawableObject
      Parameters:
      color1 - Start color (ignored)
      color2 - End color (ignored)
      horizontal - Direction (ignored)
    • hasGradient

      public boolean hasGradient()
      Description copied from interface: DrawableObject
      Checks if this object has a gradient fill.
      Specified by:
      hasGradient in interface DrawableObject
      Returns:
      true if gradient is enabled
    • removeGradient

      public void removeGradient()
      Description copied from interface: DrawableObject
      Removes gradient fill from this object.
      Specified by:
      removeGradient in interface DrawableObject