Class ButtonObject


public class ButtonObject extends AnimationObject
Represents an interactive button within the GUI system.

A button is an AnimationObject with multiple frames representing different states (normal, hover, pressed). It supports mouse position and button interactions, and can be enabled/disabled.

  • Constructor Details

    • ButtonObject

      public ButtonObject(String name, int layer, GUI gui, int x, int y, int sizeX, int sizeY, boolean nearestFilter, boolean rgba, WrappedBufferedImage... images)
      Creates a new ButtonObject.
      Parameters:
      name - the unique name of the button
      layer - the GUI layer this button belongs to
      gui - the GUI instance managing this button
      x - the x-position of the button
      y - the y-position of the button
      sizeX - the width of the button
      sizeY - the height of the button
      nearestFilter - whether nearest-neighbor filtering should be used
      rgba - whether the button uses RGBA color format
      images - the animation frames for the button (e.g., idle, hover, pressed states)
  • Method Details

    • isEnabled

      public boolean isEnabled()
      Returns whether the button is currently enabled.
      Returns:
      true if the button can be interacted with, false if disabled
    • disable

      public void disable()
      Disables the button, preventing interactions.
    • enable

      public void enable()
      Enables the button, allowing interactions.
    • sendKey

      public void sendKey(int key, int action)
      Description copied from class: GUIObject
      Handles key input events.
      Specified by:
      sendKey in class GUIObject
    • inBounds

      public boolean inBounds()
      Checks if the mouse cursor is currently within the button's bounds.
      Returns:
      true if the mouse is over the button, false otherwise
    • sendMousePos

      public void sendMousePos(long window, double xPos, double yPos)
      Handles mouse movement and updates the button's hover/idle state.
      Specified by:
      sendMousePos in class GUIObject
      Parameters:
      window - the window handle
      xPos - the current mouse x-position
      yPos - the current mouse y-position
    • sendMouseButton

      public void sendMouseButton(long window, int button, int action, int mods)
      Handles mouse button input and updates the button's pressed state.
      Specified by:
      sendMouseButton in class GUIObject
      Parameters:
      window - the window handle
      button - the mouse button pressed/released
      action - the action type (press or release)
      mods - modifier keys pressed during the event
    • getInBounds

      public boolean getInBounds()
      Returns whether the mouse is currently inside the button.
      Returns:
      true if inside, false otherwise
    • readPress

      public boolean readPress()
      Reads and clears the "pressed" state of the button.

      This is useful for checking if the button was clicked once, since it resets after being read.

      Returns:
      true if the button was pressed since last read, false otherwise
    • sendMouseScroll

      public void sendMouseScroll(long window, double xOffset, double yOffset)
      Description copied from class: GUIObject
      Handles mouse scroll input.
      Specified by:
      sendMouseScroll in class GUIObject
    • update

      public void update(boolean showFrame)
      Description copied from class: GUIObject
      Update logic called each frame.
      Specified by:
      update in class GUIObject