Class SubWindowObject

java.lang.Object
com.iragui.objects.GUIObject
com.iragui.objects.SubWindowObject

public class SubWindowObject extends GUIObject
A specialized GUIObject representing a resizable, movable, and optionally decorated sub-window within the GUI.

This class manages its own constraints, background rendering, title bar, and embedded objects (including other SubWindowObject instances). It provides functionality for scrolling, layering, and parent-child window relationships.

  • Field Details

    • TOP_LEFT

      public static final int TOP_LEFT
      Window alignment constant: top-left corner.
      See Also:
    • TOP_CENTER

      public static final int TOP_CENTER
      Window alignment constant: top-center.
      See Also:
    • TOP_RIGHT

      public static final int TOP_RIGHT
      Window alignment constant: top-right corner.
      See Also:
    • CENTER_LEFT

      public static final int CENTER_LEFT
      Window alignment constant: center-left.
      See Also:
    • CENTER

      public static final int CENTER
      Window alignment constant: absolute center.
      See Also:
    • CENTER_RIGHT

      public static final int CENTER_RIGHT
      Window alignment constant: center-right.
      See Also:
    • BOTTOM_LEFT

      public static final int BOTTOM_LEFT
      Window alignment constant: bottom-left corner.
      See Also:
    • BOTTOM_CENTER

      public static final int BOTTOM_CENTER
      Window alignment constant: bottom-center.
      See Also:
    • BOTTOM_RIGHT

      public static final int BOTTOM_RIGHT
      Window alignment constant: bottom-right corner.
      See Also:
    • MOVABLE

      public static final int MOVABLE
      Window movement type: constrained to parent window.
      See Also:
    • FREE

      public static final int FREE
      Window movement type: free (no constraint).
      See Also:
    • OBJECT_LAYER_FACTOR

      public static final int OBJECT_LAYER_FACTOR
      Layer offset factor for embedded objects.
      See Also:
    • SUBWINDOW_LAYER_FACTOR

      public static final int SUBWINDOW_LAYER_FACTOR
      Layer offset factor for nested sub-windows.
      See Also:
    • windows

      public static HashMap<String, SubWindowObject> windows
      Global registry of subwindows by name.
    • objectConstraintOffset

      public HashMap<String,Long> objectConstraintOffset
      Tracks scroll offsets for scrollable objects within this subwindow.
    • insideAnotherSubWindow

      protected boolean insideAnotherSubWindow
      Whether this window is nested inside another subwindow.
    • parentWindow

      protected SubWindowObject parentWindow
      The immediate parent subwindow, if nested.
    • absoluteParentWindow

      protected SubWindowObject absoluteParentWindow
      The absolute top-level parent subwindow in the hierarchy.
    • title

      public TextObject title
      Title text object (only exists if decorated).
    • originalConstraint

      protected int originalConstraint
      The original constraint used when nested inside another subwindow.
    • titleText

      public String titleText
      Title text for the window.
  • Constructor Details

    • SubWindowObject

      public SubWindowObject(String name, int layer, GUI gui, int x, int y, int sizeX, int sizeY, boolean nearestFilter, boolean rgba, Color bkgColor, Color topColor, boolean decorated, boolean resizable, Color titleColor, String title)
      Creates a new decorated or undecorated subwindow object.
      Parameters:
      name - the subwindow name
      layer - the rendering layer
      gui - the parent GUI instance
      x - initial X position
      y - initial Y position
      sizeX - width of the window
      sizeY - height of the window
      nearestFilter - true to use nearest-neighbor filtering
      rgba - true if window textures use RGBA
      bkgColor - background fill color
      topColor - top bar and border color
      decorated - whether the window has borders and title bar
      resizable - whether the window can be resized
      titleColor - font color for the title text
      title - initial title string
  • Method Details

    • getMouseWheelScrollOffset

      public int getMouseWheelScrollOffset()
      Returns the current accumulated mouse wheel scroll offset for this subwindow.
      Returns:
      the number of mouse wheel scroll steps
    • allowMouseWheelScroll

      public void allowMouseWheelScroll()
      Enables mouse wheel scrolling within this subwindow.
    • disallowMouseWheelScroll

      public void disallowMouseWheelScroll()
      Disables mouse wheel scrolling within this subwindow.
    • allowDragScroll

      public void allowDragScroll()
      Enables drag-based scrolling (click and drag to scroll).
    • disallowDragScroll

      public void disallowDragScroll()
      Disables drag-based scrolling.
    • getDragScrollX

      public int getDragScrollX()
      Gets the horizontal scroll offset from drag scrolling.
      Returns:
      the drag scroll X offset
    • getDragScrollY

      public int getDragScrollY()
      Gets the vertical scroll offset from drag scrolling.
      Returns:
      the drag scroll Y offset
    • setDragScrollX

      public void setDragScrollX(int v)
      Sets the horizontal scroll offset used when drag scrolling.
      Parameters:
      v - the new horizontal offset
    • setDragScrollY

      public void setDragScrollY(int v)
      Sets the vertical scroll offset used when drag scrolling.
      Parameters:
      v - the new vertical offset
    • setUseMinScroll

      public void setUseMinScroll(boolean useMinScroll, int min)
      Enables or disables minimum scroll clamping.
      Parameters:
      useMinScroll - whether to enforce a minimum scroll offset
      min - the minimum scroll offset to enforce
    • setUseMaxScroll

      public void setUseMaxScroll(boolean useMaxScroll, int max)
      Enables or disables maximum scroll clamping.
      Parameters:
      useMaxScroll - whether to enforce a maximum scroll offset
      max - the maximum scroll offset to enforce
    • setObjectLayerInWindow

      public void setObjectLayerInWindow(GUIObject o, int layer)
      Assigns a GUI object to a relative layer within this subwindow.
      Parameters:
      o - the object to re-layer
      layer - the relative layer value
    • render

      public void render(long window, int windowWidth, int windowHeight)
      Renders the subwindow’s background and borders using its shader.
      Overrides:
      render in class GUIObject
      Parameters:
      window - the GLFW window handle
      windowWidth - full framebuffer width
      windowHeight - full framebuffer height
    • resetTextureID

      public void resetTextureID()
      Resets the texture ID for this subwindow and all contained child objects, forcing them to reload textures if necessary.
      Overrides:
      resetTextureID in class GUIObject
    • add

      public void add(GUIObject o, int constraint)
      Adds a GUIObject to this subwindow with a positional constraint.

      If the object is another SubWindowObject, this will properly configure its parent relationships and assign its rendering layer. Non-window objects are placed above the window layer using OBJECT_LAYER_FACTOR.

      Parameters:
      o - the object to add
      constraint - the constraint constant (e.g. FREE, TOP_LEFT, etc.)
    • getMouseWheelScrollMultiplier

      public int getMouseWheelScrollMultiplier()
      Returns the current multiplier used for mouse wheel scroll calculations.
      Returns:
      the scroll multiplier
    • setMouseScrollMultiplier

      public void setMouseScrollMultiplier(int i)
      Sets the multiplier applied to mouse wheel scroll offsets.
      Parameters:
      i - the new scroll multiplier
    • makeObjectScrollable

      public void makeObjectScrollable(GUIObject o)
      Marks a GUIObject as scrollable within this subwindow.
      Parameters:
      o - the object to make scrollable
    • changeConstraint

      public void changeConstraint(GUIObject o, int constraint)
      Changes the constraint bucket for an existing child and reapplies positioning.

      This removes o from its current internal list and reassigns it to the list for constraint, then immediately calls constrainObject(GUIObject, int) to update its position and limits.

      Parameters:
      o - the child object whose constraint should change
      constraint - the new constraint (see constants like FREE, CENTER, etc.)
    • remove

      public void remove(String name)
      Removes a child object by name from this subwindow.

      This method deletes the reference from internal collections. If the removed object is itself a SubWindowObject, its parent/containment flags are reset. This does not call GUIObject.destroyObject() on the removed object; it only detaches it from this container.

      Parameters:
      name - the name of the child object to remove
    • destroyObject

      public void destroyObject()
      Destroys this subwindow and all of its children.

      Steps performed:

      1. Unregisters this window from the global windows map.
      2. Rebuilds the windowsByLayer index.
      3. Resets the cursor on the owning window.
      4. Calls GUIObject.destroyObject() on all child objects and clears internal collections.
      5. Invokes super.destroyObject() to release this object’s own resources.

      Overrides:
      destroyObject in class GUIObject
    • update

      public void update(boolean showFrame)
      Per-frame update for this subwindow.

      Behavior:

      • No-op when showFrame == false.
      • Updates title color based on focus state.
      • Enables/disables window control buttons depending on focus, dragging, and resizing state.
      • If dragging, repositions the window within the screen bounds.
      • Re-applies constraints for all child objects each frame.
      • Handles clicks on close/minimize (destroys the window).
      • Handles maximize/split toggle: maximizes to parent or full window, and restores on split.
      Specified by:
      update in class GUIObject
      Parameters:
      showFrame - whether this frame should be processed and drawn
    • resize

      public void resize(int x, int y)
      Resizes this window object, enforcing minimum (225x225) and maximum bounds based on the current window size.
      Parameters:
      x - new width in pixels
      y - new height in pixels
    • setLayer

      public void setLayer(int layer)
      Sets the rendering layer of this window and updates all contained objects to maintain correct z-ordering.
      Overrides:
      setLayer in class GUIObject
      Parameters:
      layer - new layer index
    • getHighestLayer

      public int getHighestLayer()
      Gets the highest layer value used by this window and its children.
      Returns:
      highest layer index
    • getHighestLayer

      public int getHighestLayer(GUIObject ignore)
      Gets the highest layer value used by this window and its children, excluding a specific object.
      Parameters:
      ignore - object to ignore
      Returns:
      highest layer index without ignore
    • forceFocus

      public void forceFocus()
      Brings this window to focus, forcing it to the top of the rendering hierarchy.
    • sendKey

      public void sendKey(int key, int action)
      Sends a key input event to this window.
      Specified by:
      sendKey in class GUIObject
      Parameters:
      key - key code
      action - key action (press/release)
    • setX

      public void setX(int x)
      Safely sets this object's X position, constraining it to window bounds and applying parent constraints if necessary.
      Overrides:
      setX in class GUIObject
      Parameters:
      x - new X position
    • setY

      public void setY(int y)
      Safely sets this object's Y position, constraining it to window bounds and applying parent constraints if necessary.
      Overrides:
      setY in class GUIObject
      Parameters:
      y - new Y position
    • freeToInteract

      public static boolean freeToInteract(SubWindowObject o)
      Checks whether the given window is free to interact, i.e. no other window is currently dragging or resizing.
      Parameters:
      o - subwindow to test
      Returns:
      true if free to interact, otherwise false
    • anyWindowsInResizeRange

      public static boolean anyWindowsInResizeRange()
      Checks whether the given window is free to interact, i.e. no other window is currently dragging or resizing.
      Parameters:
      o - subwindow to test
      Returns:
      true if free to interact, otherwise false
    • sendMousePos

      public void sendMousePos(long window, double xPos, double yPos)
      Sends the current mouse position to this window, updating resize and drag state if applicable.
      Specified by:
      sendMousePos in class GUIObject
    • sendMouseButton

      public void sendMouseButton(long window, int button, int action, int mods)
      Sends a mouse button event to this window, handling dragging, resizing, and scroll-drag interactions.
      Specified by:
      sendMouseButton in class GUIObject
    • mouseIsNormal

      public boolean mouseIsNormal()
      Returns whether the current cursor is the "normal" system cursor.
      Returns:
      true if cursor is normal, otherwise false
    • sendMouseScroll

      public void sendMouseScroll(long window, double xOffset, double yOffset)
      Sends a mouse scroll event to this window, updating scroll offsets if enabled.
      Specified by:
      sendMouseScroll in class GUIObject
    • getTopSize

      public int getTopSize()
      Returns the height of this window's top bar (title bar region).
      Returns:
      top bar height in pixels
    • getObjectsByName

      public HashMap<String, GUIObject> getObjectsByName()
      Returns the height of this window's top bar (title bar region).
      Returns:
      top bar height in pixels
    • addObjectConstraintOffset

      public void addObjectConstraintOffset(GUIObject o, int offsetX, int offsetY)
      Adds a constraint offset for the given object within this window.
      Parameters:
      o - target GUI object
      offsetX - horizontal offset
      offsetY - vertical offset
    • isDragging

      public boolean isDragging()
      Returns whether this window is currently being dragged.
      Returns:
      true if dragging
    • isResizing

      public boolean isResizing()
      Returns whether this window is currently being dragged.
      Returns:
      true if dragging