Class GUIObject

java.lang.Object
com.iragui.objects.GUIObject
Direct Known Subclasses:
AnimationObject, ScreenObject, SubWindowObject, TextBoxObject, TextObject, WrappedBufferedImage

public abstract class GUIObject extends Object
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

    Fields
    Modifier and Type
    Field
    Description
    protected final int
    Bytes per pixel (3 for RGB, 4 for RGBA).
    protected int
     
    protected boolean
     
    protected boolean
     
    protected GUI
    The parent GUI 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

    Constructors
    Constructor
    Description
    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.
    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 Type
    Method
    Description
    protected void
    Marks this object as needing re-texturing on next render.
    void
    Destroys this object, releasing GPU resources and unregistering it.
    void
    Sets this object as focused.
    int
     
    boolean
     
    int
     
    int
     
    int
     
    int
     
    int
     
    int
     
    int
     
    int
     
    int
     
    int
     
    boolean
     
    boolean
     
    int
     
    int
     
    int
     
    int
     
    int
     
    int
     
    void
    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
    Replaces the entire pixel buffer with the given ByteBuffer.
    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
    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
    Removes focus from this object.
    abstract void
    update(boolean showFrame)
    Update logic called each frame.
    boolean
    Whether this object should update each frame.

    Methods inherited from class java.lang.Object

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

    • name

      public final String name
      Unique identifier for this object.
    • layer

      protected int layer
      The rendering layer index. Higher layers are drawn above lower ones.
    • gui

      protected GUI gui
      The parent GUI managing this object.
    • sizeX

      protected int sizeX
      Pixel dimensions of the object.
    • sizeY

      protected int sizeY
      Pixel dimensions of the object.
    • limitX

      protected int limitX
      Absolute bounds within the object.
    • limitY

      protected int limitY
      Absolute bounds within the object.
    • minX

      protected int minX
      Absolute bounds within the object.
    • minY

      protected int minY
      Absolute bounds within the object.
    • pixelBuffer

      protected ByteBuffer pixelBuffer
      OpenGL pixel buffer storing object texture data.
    • x

      public int x
      Object position in pixels (top-left corner).
    • y

      public int y
      Object position in pixels (top-left corner).
    • winLimitX

      protected int winLimitX
      Window-constrained bounds.
    • winLimitY

      protected int winLimitY
      Window-constrained bounds.
    • winMinX

      protected int winMinX
      Window-constrained bounds.
    • winMinY

      protected int winMinY
      Window-constrained bounds.
    • constraint

      protected int constraint
    • RGBA

      public static final int RGBA
      Pixel format constants.
      See Also:
    • RGB

      public static final int RGB
      Pixel format constants.
      See Also:
    • rgba

      protected final boolean rgba
      Whether this object uses RGBA pixel data.
    • BYTES_PER_PIXEL

      protected final int BYTES_PER_PIXEL
      Bytes per pixel (3 for RGB, 4 for RGBA).
    • destroyed

      protected boolean destroyed
    • focused

      protected boolean focused
    • visible

      protected boolean visible
      Visibility 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 name
      layer - rendering layer index
      gui - parent GUI instance
      x - initial X position
      y - initial Y position
      sizeX - object width in pixels
      sizeY - object height in pixels
      nearestFilter - whether to use nearest-neighbor filtering
      rgba - whether to use RGBA (vs RGB)
      includeKeyCallback - whether to register key callbacks
      includeMouseCallback - whether to register mouse callbacks
      updates - 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 name
      layer - rendering layer index
      gui - parent GUI instance
      x - initial X position
      y - initial Y position
      sizeX - object width in pixels
      sizeY - object height in pixels
      nearestFilter - whether to use nearest-neighbor filtering
      rgba - 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 long
      windowWidth - GLFW window width in pixels
      windowHeight - 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. See setPreserveTextureIDOverride(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

      public void setAll(ByteBuffer p)
      Replaces the entire pixel buffer with the given ByteBuffer.
    • 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. See setPreserveTextureIDOverride(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 position
      mY - 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