Class ButtonObject
java.lang.Object
com.iragui.objects.GUIObject
com.iragui.objects.AnimationObject
com.iragui.objects.ButtonObject
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.
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionButtonObject
(String name, int layer, GUI gui, int x, int y, int sizeX, int sizeY, boolean nearestFilter, boolean rgba, WrappedBufferedImage... images) Creates a newButtonObject
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
disable()
Disables the button, preventing interactions.void
enable()
Enables the button, allowing interactions.boolean
Returns whether the mouse is currently inside the button.boolean
inBounds()
Checks if the mouse cursor is currently within the button's bounds.boolean
Returns whether the button is currently enabled.boolean
Reads and clears the "pressed" state of the button.void
sendKey
(int key, int action) Handles key input events.void
sendMouseButton
(long window, int button, int action, int mods) Handles mouse button input and updates the button's pressed state.void
sendMousePos
(long window, double xPos, double yPos) Handles mouse movement and updates the button's hover/idle state.void
sendMouseScroll
(long window, double xOffset, double yOffset) Handles mouse scroll input.void
update
(boolean showFrame) Update logic called each frame.Methods inherited from class com.iragui.objects.AnimationObject
destroyObject, getAnyFrameVisible, getFrame, getFrames, getVisible, hide, setFrame, setLayer, setLimitX, setLimitY, setMinX, setMinY, setVisible, setWinLimitX, setWinLimitY, setWinMinX, setWinMinY, setX, setY
Methods inherited from class com.iragui.objects.GUIObject
allowReTexture, focus, getGlPixelInt, getHFlip, getLayer, getLimitX, getLimitY, getMinX, getMinY, getRotation, getScale, getSizeX, getSizeY, getTextureID, getVFlip, getWinLimitX, getWinLimitY, getWinMinX, getWinMinY, getX, getY, includesKeyCallback, includesMouseCallback, interactionInVisibleBounds, isDestroyed, isFocused, isNearestFilter, render, resetTextureID, setAll, setAll, setHFlip, setNearestFilter, setPixel, setPreserveTextureIDOverride, setRotation, setScale, setTextureID, setVFlip, unfocus, updates
-
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 newButtonObject
.- Parameters:
name
- the unique name of the buttonlayer
- the GUI layer this button belongs togui
- the GUI instance managing this buttonx
- the x-position of the buttony
- the y-position of the buttonsizeX
- the width of the buttonsizeY
- the height of the buttonnearestFilter
- whether nearest-neighbor filtering should be usedrgba
- whether the button uses RGBA color formatimages
- 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
-
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 classGUIObject
- Parameters:
window
- the window handlexPos
- the current mouse x-positionyPos
- 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 classGUIObject
- Parameters:
window
- the window handlebutton
- the mouse button pressed/releasedaction
- 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 classGUIObject
-
update
-