Class GUIObject
java.lang.Object
com.iragui.objects.GUIObject
- Direct Known Subclasses:
AnimationObject
,ScreenObject
,SubWindowObject
,TextBoxObject
,TextObject
,WrappedBufferedImage
Base class for all objects that can be managed and rendered inside a
GUI
.
A GUIObject
encapsulates its position, size, rendering state, and
input callback registration. It manages its own OpenGL texture, buffer data,
and provides abstract hooks for update and input handling.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final int
Bytes per pixel (3 for RGB, 4 for RGBA).protected int
protected boolean
protected boolean
protected GUI
The parentGUI
managing this object.protected int
The rendering layer index.protected int
Absolute bounds within the object.protected int
Absolute bounds within the object.protected int
Absolute bounds within the object.protected int
Absolute bounds within the object.final String
Unique identifier for this object.protected ByteBuffer
OpenGL pixel buffer storing object texture data.static final int
Pixel format constants.protected final boolean
Whether this object uses RGBA pixel data.static final int
Pixel format constants.protected int
Pixel dimensions of the object.protected int
Pixel dimensions of the object.protected int
protected int
protected boolean
Visibility flag.protected int
Window-constrained bounds.protected int
Window-constrained bounds.protected int
Window-constrained bounds.protected int
Window-constrained bounds.int
Object position in pixels (top-left corner).int
Object position in pixels (top-left corner). -
Constructor Summary
ConstructorsConstructorDescriptionGUIObject
(String name, int layer, GUI gui, int x, int y, int sizeX, int sizeY, boolean nearestFilter, boolean rgba) Simplified constructor with callbacks and updates enabled.GUIObject
(String name, int layer, GUI gui, int x, int y, int sizeX, int sizeY, boolean nearestFilter, boolean rgba, boolean includeKeyCallback, boolean includeMouseCallback, boolean updates) Constructs a new GUI object with full parameter control. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Marks this object as needing re-texturing on next render.void
Destroys this object, releasing GPU resources and unregistering it.void
focus()
Sets this object as focused.int
boolean
getHFlip()
int
getLayer()
int
int
int
getMinX()
int
getMinY()
int
int
getScale()
int
getSizeX()
int
getSizeY()
int
boolean
getVFlip()
boolean
int
int
int
int
int
getX()
int
getY()
void
hide()
Hides this object.boolean
boolean
boolean
interactionInVisibleBounds
(int mX, int mY) Tests whether a point lies within the object's visible interaction bounds.boolean
boolean
boolean
void
render
(long window, int windowWidth, int windowHeight) Renders this object using OpenGL.void
Regenerates a new texture ID and re-uploads pixel data.abstract void
sendKey
(int key, int action) Handles key input events.abstract void
sendMouseButton
(long window, int button, int action, int mods) Handles mouse button input.abstract void
sendMousePos
(long window, double xPos, double yPos) Handles mouse position updates.abstract void
sendMouseScroll
(long window, double xOffset, double yOffset) Handles mouse scroll input.void
setAll
(int x, int y, byte[] p) Replaces the entire pixel buffer with the given byte array.void
setAll
(ByteBuffer p) Replaces the entire pixel buffer with the givenByteBuffer
.void
setHFlip
(boolean flip) Sets horizontal flip.void
setLayer
(int layer) Sets the rendering layer and updates parent GUI ordering.void
setLimitX
(int x) void
setLimitY
(int y) void
setMinX
(int x) void
setMinY
(int y) void
setNearestFilter
(boolean nearestFilter) Sets nearest-neighbor filtering mode.void
setPixel
(int x, int y, byte[] p) Sets a single pixel in the buffer.void
setPreserveTextureIDOverride
(boolean bool) Sets whether to prevent automatic deletion/regeneration of texture IDs.void
setRotation
(int rotation) Sets rotation in 90° increments.void
setScale
(int scale) Sets the rendering scale of this object.void
setTextureID
(int textureID) Sets the OpenGL texture ID manually.void
setVFlip
(boolean flip) Sets vertical flip.void
Makes this object visible.void
setWinLimitX
(int x) void
setWinLimitY
(int y) void
setWinMinX
(int x) void
setWinMinY
(int y) void
setX
(int x) Sets the X position in pixels.void
setY
(int y) Sets the Y position in pixels.void
unfocus()
Removes focus from this object.abstract void
update
(boolean showFrame) Update logic called each frame.boolean
updates()
Whether this object should update each frame.
-
Field Details
-
name
Unique identifier for this object. -
layer
protected int layerThe rendering layer index. Higher layers are drawn above lower ones. -
gui
-
sizeX
protected int sizeXPixel dimensions of the object. -
sizeY
protected int sizeYPixel dimensions of the object. -
limitX
protected int limitXAbsolute bounds within the object. -
limitY
protected int limitYAbsolute bounds within the object. -
minX
protected int minXAbsolute bounds within the object. -
minY
protected int minYAbsolute bounds within the object. -
pixelBuffer
OpenGL pixel buffer storing object texture data. -
x
public int xObject position in pixels (top-left corner). -
y
public int yObject position in pixels (top-left corner). -
winLimitX
protected int winLimitXWindow-constrained bounds. -
winLimitY
protected int winLimitYWindow-constrained bounds. -
winMinX
protected int winMinXWindow-constrained bounds. -
winMinY
protected int winMinYWindow-constrained bounds. -
constraint
protected int constraint -
RGBA
public static final int RGBAPixel format constants.- See Also:
-
RGB
public static final int RGBPixel format constants.- See Also:
-
rgba
protected final boolean rgbaWhether this object uses RGBA pixel data. -
BYTES_PER_PIXEL
protected final int BYTES_PER_PIXELBytes per pixel (3 for RGB, 4 for RGBA). -
destroyed
protected boolean destroyed -
focused
protected boolean focused -
visible
protected boolean visibleVisibility flag. -
vao
protected int vao -
vbo
protected int vbo
-
-
Constructor Details
-
GUIObject
public GUIObject(String name, int layer, GUI gui, int x, int y, int sizeX, int sizeY, boolean nearestFilter, boolean rgba, boolean includeKeyCallback, boolean includeMouseCallback, boolean updates) Constructs a new GUI object with full parameter control.- Parameters:
name
- unique object namelayer
- rendering layer indexgui
- parent GUI instancex
- initial X positiony
- initial Y positionsizeX
- object width in pixelssizeY
- object height in pixelsnearestFilter
- whether to use nearest-neighbor filteringrgba
- whether to use RGBA (vs RGB)includeKeyCallback
- whether to register key callbacksincludeMouseCallback
- whether to register mouse callbacksupdates
- whether this object updates each frame
-
GUIObject
public GUIObject(String name, int layer, GUI gui, int x, int y, int sizeX, int sizeY, boolean nearestFilter, boolean rgba) Simplified constructor with callbacks and updates enabled.- Parameters:
name
- unique object namelayer
- rendering layer indexgui
- parent GUI instancex
- initial X positiony
- initial Y positionsizeX
- object width in pixelssizeY
- object height in pixelsnearestFilter
- whether to use nearest-neighbor filteringrgba
- whether to use RGBA (vs RGB)
-
-
Method Details
-
getScale
public int getScale()- Returns:
- current rendering scale of this object
-
setScale
public void setScale(int scale) Sets the rendering scale of this object. -
updates
public boolean updates()Whether this object should update each frame. -
includesMouseCallback
public boolean includesMouseCallback()- Returns:
- true if this object listens for mouse callbacks
-
includesKeyCallback
public boolean includesKeyCallback()- Returns:
- true if this object listens for key callbacks
-
setX
public void setX(int x) Sets the X position in pixels. -
setY
public void setY(int y) Sets the Y position in pixels. -
getX
public int getX()- Returns:
- current X position
-
getY
public int getY()- Returns:
- current Y position
-
setPreserveTextureIDOverride
public void setPreserveTextureIDOverride(boolean bool) Sets whether to prevent automatic deletion/regeneration of texture IDs. Useful if texture reuse is required. -
isFocused
public boolean isFocused()- Returns:
- true if this object is focused
-
focus
public void focus()Sets this object as focused. -
unfocus
public void unfocus()Removes focus from this object. -
isDestroyed
public boolean isDestroyed()- Returns:
- true if this object has been destroyed
-
getSizeX
public int getSizeX()- Returns:
- width in pixels
-
getSizeY
public int getSizeY()- Returns:
- height in pixels
-
setWinLimitX
public void setWinLimitX(int x) -
setWinLimitY
public void setWinLimitY(int y) -
setWinMinX
public void setWinMinX(int x) -
setWinMinY
public void setWinMinY(int y) -
getWinLimitX
public int getWinLimitX() -
getWinLimitY
public int getWinLimitY() -
getWinMinX
public int getWinMinX() -
getWinMinY
public int getWinMinY() -
setLimitX
public void setLimitX(int x) -
setLimitY
public void setLimitY(int y) -
setMinX
public void setMinX(int x) -
setMinY
public void setMinY(int y) -
getMinX
public int getMinX() -
getMinY
public int getMinY() -
getLimitX
public int getLimitX() -
getLimitY
public int getLimitY() -
allowReTexture
protected void allowReTexture()Marks this object as needing re-texturing on next render. -
setVisible
public void setVisible()Makes this object visible. -
getVisible
public boolean getVisible()- Returns:
- true if this object is visible
-
hide
public void hide()Hides this object. -
getLayer
public int getLayer()- Returns:
- current rendering layer
-
setLayer
public void setLayer(int layer) Sets the rendering layer and updates parent GUI ordering. -
update
public abstract void update(boolean showFrame) Update logic called each frame. -
sendKey
public abstract void sendKey(int key, int action) Handles key input events. -
sendMousePos
public abstract void sendMousePos(long window, double xPos, double yPos) Handles mouse position updates. -
sendMouseButton
public abstract void sendMouseButton(long window, int button, int action, int mods) Handles mouse button input. -
sendMouseScroll
public abstract void sendMouseScroll(long window, double xOffset, double yOffset) Handles mouse scroll input. -
render
public void render(long window, int windowWidth, int windowHeight) Renders this object using OpenGL.- Parameters:
window
- GLFW window id as a longwindowWidth
- GLFW window width in pixelswindowHeight
- GLFW window height in pixels
-
destroyObject
public void destroyObject()Destroys this object, releasing GPU resources and unregistering it.If
preserveTextureIDOverride
is true, the OpenGL texture ID will not be deleted. SeesetPreserveTextureIDOverride(boolean)
. -
setPixel
public void setPixel(int x, int y, byte[] p) Sets a single pixel in the buffer. -
setAll
public void setAll(int x, int y, byte[] p) Replaces the entire pixel buffer with the given byte array. -
setAll
Replaces the entire pixel buffer with the givenByteBuffer
. -
getTextureID
public int getTextureID()- Returns:
- OpenGL texture ID for this object
-
setTextureID
public void setTextureID(int textureID) Sets the OpenGL texture ID manually. -
resetTextureID
public void resetTextureID()Regenerates a new texture ID and re-uploads pixel data.If
preserveTextureIDOverride
is true, the OpenGL texture ID will not be reset. SeesetPreserveTextureIDOverride(boolean)
. -
isNearestFilter
public boolean isNearestFilter()- Returns:
- true if using nearest-neighbor filtering
-
setNearestFilter
public void setNearestFilter(boolean nearestFilter) Sets nearest-neighbor filtering mode. -
getGlPixelInt
public int getGlPixelInt()- Returns:
- OpenGL pixel format flag
-
interactionInVisibleBounds
public boolean interactionInVisibleBounds(int mX, int mY) Tests whether a point lies within the object's visible interaction bounds.- Parameters:
mX
- mouse X positionmY
- mouse Y position- Returns:
- true if within bounds
-
setRotation
public void setRotation(int rotation) Sets rotation in 90° increments.0 = 0°
1 = 90°
2 = 180°
3 = 270° -
getRotation
public int getRotation()- Returns:
- current rotation
0 = 0°
1 = 90°
2 = 180°
3 = 270°
-
setHFlip
public void setHFlip(boolean flip) Sets horizontal flip. -
setVFlip
public void setVFlip(boolean flip) Sets vertical flip. -
getHFlip
public boolean getHFlip()- Returns:
- true if horizontally flipped
-
getVFlip
public boolean getVFlip()- Returns:
- true if vertically flipped
-