Class TextObject
java.lang.Object
com.iragui.objects.GUIObject
com.iragui.objects.TextObject
A GUI object that renders text as a texture and displays it in OpenGL.
This class creates a BufferedImage
, rasterizes the text with a given
Font
, Color
, and background, and uploads it as an OpenGL
texture. The text can be updated dynamically, and it will automatically
regenerate the texture when changed.
Features include:
- Support for anti-aliased text rendering
- Support for both RGB and RGBA textures
- Automatic recalculation of text width when the string changes
- Ability to revert to the original text
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Creates or updates the texture with the current text, font, and colors.getFont()
int
getText()
int
int
getTextWidth
(String text) Returns the width of a specific string in pixels.boolean
void
Reverts the text back to its original value.void
sendKey
(int key, int action) Handles key input events.void
sendMouseButton
(long window, int button, int action, int mods) Handles mouse button input.void
sendMousePos
(long window, double xPos, double yPos) Handles mouse position updates.void
sendMouseScroll
(long window, double xOffset, double yOffset) Handles mouse scroll input.void
Sets the text color and regenerates the texture.void
Sets the font used for rendering text and regenerates the texture.void
Updates the text content and regenerates the texture if changed.void
setTextOverride
(String string) Sets the text and overrides the original text value as well.void
update
(boolean showFrame) Update logic called each frame.Methods inherited from class com.iragui.objects.GUIObject
allowReTexture, destroyObject, focus, getGlPixelInt, getHFlip, getLayer, getLimitX, getLimitY, getMinX, getMinY, getRotation, getScale, getSizeX, getSizeY, getTextureID, getVFlip, getVisible, getWinLimitX, getWinLimitY, getWinMinX, getWinMinY, getX, getY, hide, includesKeyCallback, includesMouseCallback, interactionInVisibleBounds, isDestroyed, isFocused, isNearestFilter, render, resetTextureID, setAll, setAll, setHFlip, setLayer, setLimitX, setLimitY, setMinX, setMinY, setNearestFilter, setPixel, setPreserveTextureIDOverride, setRotation, setScale, setTextureID, setVFlip, setVisible, setWinLimitX, setWinLimitY, setWinMinX, setWinMinY, setX, setY, unfocus, updates
-
Constructor Details
-
TextObject
public TextObject(String name, int layer, GUI gui, int x, int y, boolean nearestFilter, boolean rgba, String text, Font font, Color color, Color bkgColor, boolean antiAliasing) Constructs a newTextObject
.- Parameters:
name
- the name of this objectlayer
- the rendering layergui
- the parent GUIx
- the X positiony
- the Y positionnearestFilter
- whether to use nearest-neighbor filteringrgba
- whether to render as RGBA (true) or RGB (false)text
- the text string to displayfont
- the font used for renderingcolor
- the foreground color of the textbkgColor
- the background colorantiAliasing
- whether to enable text anti-aliasing
-
-
Method Details
-
setText
Updates the text content and regenerates the texture if changed.- Parameters:
text
- the new text string
-
getTextWidth
public int getTextWidth()- Returns:
- the width of the current text in pixels
-
getTextWidth
Returns the width of a specific string in pixels.- Parameters:
text
- the string to measure- Returns:
- the pixel width of the given string
-
setFont
Sets the font used for rendering text and regenerates the texture.- Parameters:
font
- the new font
-
createTexture
public void createTexture()Creates or updates the texture with the current text, font, and colors. Handles both RGB and RGBA modes. -
update
-
sendKey
-
sendMousePos
public void sendMousePos(long window, double xPos, double yPos) Description copied from class:GUIObject
Handles mouse position updates.- Specified by:
sendMousePos
in classGUIObject
-
sendMouseButton
public void sendMouseButton(long window, int button, int action, int mods) Description copied from class:GUIObject
Handles mouse button input.- Specified by:
sendMouseButton
in classGUIObject
-
sendMouseScroll
public void sendMouseScroll(long window, double xOffset, double yOffset) Description copied from class:GUIObject
Handles mouse scroll input.- Specified by:
sendMouseScroll
in classGUIObject
-
getText
- Returns:
- the current text string
-
isOriginalText
public boolean isOriginalText()- Returns:
- true if the text matches the original text
-
getOriginalTextWidth
public int getOriginalTextWidth()- Returns:
- the pixel width of the original text
-
revertText
public void revertText()Reverts the text back to its original value. -
setTextOverride
Sets the text and overrides the original text value as well.- Parameters:
string
- the new text string
-
setColor
Sets the text color and regenerates the texture.- Parameters:
color
- the new color
-
getFont
- Returns:
- the current font used for rendering
-