Class TextObject
java.lang.Object
com.catsoftware.engine.prism.draw.TextObject
- All Implemented Interfaces:
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
ConstructorsConstructorDescriptionTextObject(String t, int x, int y, Font f, Color c, float a) Creates a new text object. -
Method Summary
Modifier and TypeMethodDescriptionbooleanChecks if a point is inside/on this object.voiddraw(Graphics2D g) Renders this object onto a graphics context.voidfill(Graphics2D g, Color fillColor) Fills this object with the specified color.floatgetAlpha()Returns the opacity level.Returns the bounding rectangle of this object.getColor()Returns the text color.getFont()Returns the font.doubleReturns the current rotation angle.getText()Returns the text content.intgetX()Returns the X coordinate.intgetY()Returns the Y coordinate.booleanChecks if this object has a gradient fill.voidmoveBy(int dx, int dy) Moves this object by the specified delta.voidRemoves gradient fill from this object.voidresize(double scaleX, double scaleY) Scales this object by the given factors.voidresizeAbsolute(int newWidth, int newHeight) Resizes this object to absolute dimensions.voidrotate(double delta) Rotates this object by the specified delta.voidsetAlpha(float alpha) Sets the opacity level.voidSets the text color.voidSets the font.voidsetGradient(Color color1, Color color2, boolean horizontal) Sets a gradient (not supported for text - falls back to solid color).voidsetRotation(double degrees) Sets the rotation angle of this object.voidSets the text content.
-
Constructor Details
-
TextObject
Creates a new text object.- Parameters:
t- The text contentx- The X coordinate (baseline position)y- The Y coordinate (baseline position)f- The font to usec- The text colora- The opacity level (0.0 - 1.0)
-
-
Method Details
-
draw
Description copied from interface:DrawableObjectRenders this object onto a graphics context.- Specified by:
drawin interfaceDrawableObject- Parameters:
g- The graphics context to draw on
-
contains
Description copied from interface:DrawableObjectChecks if a point is inside/on this object. Used for selection and hit testing.- Specified by:
containsin interfaceDrawableObject- 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:DrawableObjectMoves this object by the specified delta.- Specified by:
moveByin interfaceDrawableObject- Parameters:
dx- Horizontal offsetdy- Vertical offset
-
getBounds
Description copied from interface:DrawableObjectReturns the bounding rectangle of this object.- Specified by:
getBoundsin interfaceDrawableObject- Returns:
- The bounding box
-
resize
public void resize(double scaleX, double scaleY) Description copied from interface:DrawableObjectScales this object by the given factors.- Specified by:
resizein interfaceDrawableObject- Parameters:
scaleX- Horizontal scale factorscaleY- Vertical scale factor
-
resizeAbsolute
public void resizeAbsolute(int newWidth, int newHeight) Description copied from interface:DrawableObjectResizes this object to absolute dimensions.- Specified by:
resizeAbsolutein interfaceDrawableObject- Parameters:
newWidth- New width in pixelsnewHeight- New height in pixels
-
fill
Description copied from interface:DrawableObjectFills this object with the specified color.- Specified by:
fillin interfaceDrawableObject- Parameters:
g- Graphics context (may be null for vector fills)fillColor- The color to fill with
-
setColor
Sets the text color.- Parameters:
color- The new color
-
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
Returns the font.- Returns:
- The current font
-
getColor
Returns the text color.- Returns:
- The current color
-
setText
Sets the text content.- Parameters:
text- The new text
-
setFont
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:DrawableObjectSets the rotation angle of this object.- Specified by:
setRotationin interfaceDrawableObject- Parameters:
degrees- Rotation angle in degrees
-
getRotation
public double getRotation()Description copied from interface:DrawableObjectReturns the current rotation angle.- Specified by:
getRotationin interfaceDrawableObject- Returns:
- Rotation angle in degrees
-
rotate
public void rotate(double delta) Description copied from interface:DrawableObjectRotates this object by the specified delta.- Specified by:
rotatein interfaceDrawableObject- Parameters:
delta- Degrees to add to current rotation
-
setGradient
Sets a gradient (not supported for text - falls back to solid color).- Specified by:
setGradientin interfaceDrawableObject- Parameters:
color1- Start color (ignored)color2- End color (ignored)horizontal- Direction (ignored)
-
hasGradient
public boolean hasGradient()Description copied from interface:DrawableObjectChecks if this object has a gradient fill.- Specified by:
hasGradientin interfaceDrawableObject- Returns:
- true if gradient is enabled
-
removeGradient
public void removeGradient()Description copied from interface:DrawableObjectRemoves gradient fill from this object.- Specified by:
removeGradientin interfaceDrawableObject
-