Class GUIObject
- Direct Known Subclasses:
GUILabel, GUIPanel, GUITogglePanel
- Author:
- Matthew Tropiano
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected GUIBoundsThis object's absolute bounds.static final StringObject loses focus.static final StringObject is enabled/disabled.static final StringObject is shown/hidden.static final StringObject is focused.static final StringGamepad axis is changed on this object.static final StringGamepad button is pressed on this object.static final StringGamepad button is released on this object.static final StringGamepad axis is tapped (press) on this object.static final StringGamepad axis is untapped (release) on this object.static final StringSome kind of generic input is sent to the GUI in the form of a code.static final StringKeyboard key is pressed on this object.static final StringKeyboard key is released on this object.static final StringKeyboard key is typed on this object.static final StringMouse is clicked on this object.static final StringMouse is dragged on this object (not moved, button is down).static final StringMouse cursor leaves this object (not over it anymore).static final StringMouse is moved on this object.static final StringMouse cursor is (directly) over this object.static final StringMouse button is pressed on this object.static final StringMouse button is released on this object.static final StringMouse wheel is scrolled on this object.static final StringDenotes an event triggered by name.static final StringUnknown type of event. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal GUIObjectAdd a child object to this one.final GUIObjectAdd a child object to this one and sets a layout attribute to it, as thoughsetLayoutAttrib(Object)final voidAdds a single name or series of names to this object, used for selecting objects.protected final voidCalled when this object needs adding to a render set for rendering later.animate(long duration, GUIAnimation... animations) Enqueues an animation on this GUI Object, linear transition.animate(long duration, GUIEasingType transition, GUIAnimation... animations) Enqueues an animation on this GUI Object.animate(GUIAnimation... animations) Enqueues an animation on this GUI Object, no duration.Aborts the animation on this object, abandoning it mid-animation.animateDelay(long duration) Enqueues a delay between animations on this GUI Object.Finishes the animation on this object all the way to the end.final GUIObjectbindAction(GUIAction action, String... types) Adds an action bound to an event type.final voidcallAction(GUIAction action) Calls an action on this object.protected voidCorrects the position of this object, if this is constrained to the parent's position.protected final voidFires a non-specific event to the GUI system.Gets this object's ABSOLUTE bounds, i.e. the object's current position after considering its inherited hierarchy.Gets this object wrapped in anGUIQuery.Returns a copy of this object's bounding rectangle.Gets this object's children wrapped in anGUIQuery.getColor()Gets the object's color.booleanGets if this object DOESN'T pass on its color to its children.Gets this object's entire descendant tree wrapped in anGUIQuery.protected floatfinal intReturns how far down the generation tree this object is.final GUIgetGUI()Gets this object's layout type for resizing object children, should this object get resized itself.Gets this object's layout attribute, used by some layouts in order to affect the parent's layout behavior when resizing this component (as a child).protected GUIBoundsReturns a reference to this object's bounds rectangle.floatGets this object's opacity (0 to 1).final GUIObjectGets the parent object of this one.Gets this object's parent wrapped in anGUIQuery.floatfloatbooleanGets if this object is rendered.floatfloatfinal floatfinal floatfloatGets the object's radius, for use with determining what is on the screen or not.floatfloatfloatGets the object's texture scaling, S-axis (U).floatGets the object's texture scaling, T-axis (V).floatGets this object's siblings wrapped in anGUIQuery.Returns this object's texture.final GUIThemegetTheme()Returns the current theme used by this object.abstract StringReturns this object's theme key.booleanGets if this object is flagged as "visible".final booleanChecks if an action has at least one binding.final booleanChecks if this object has a particular name.final StringhasNamePattern(Pattern pattern) Returns true if one of this object's names matches the provided pattern, false otherwise.booleanGets if this object is currently animatingbooleanChecks if this constrains its position to its parent.booleanGets if the object can accept/intercept input.booleanGets if this object is currently focused in its GUI.booleanisInert()Gets if the object can accept/intercept input, but does NOT affect its "enabled" state, unless its parent is enabled/disabled.booleanGets if the object is visible, which means that this object has its "visible" member set to true, and its opacity is nonzero.final GUIObjectmoveDown()Moves the order of this object back among its siblings, so that it is rendered earlier than the one before it (pushing it "further from the camera").final GUIObjectMoves the order of this object back among its siblings, so that it is rendered first (pushing it "farthest from the camera").final GUIObjectMoves the order of this object up among its siblings, so that it is rendered last (bringing it "closest to the camera").final GUIObjectmoveUp()Moves the order of this object up among its siblings, so that it is rendered later than the one after it (bringing it "closer to the camera").protected voidonGUIChange(GUI gui) Called when this object is added to a GUI.Releases focus on this object if this object currently has focus in the scene it belongs to.final GUIObjectremove()Removes this object from its GUI.final GUIObjectremoveChild(GUIObject obj) Removes a child object from this one.final GUIObjectremoveName(String... names) Removes a single name or series of names from this object.Requests focus on this object in the scene it belongs to.voidCalls upon the layouts to resize the children.rotate(float degrees) Rotates this object by a number of degrees.setBounds(float x, float y, float width, float height) Sets the object bounds.Sets the object bounds.voidSets this object's width and height based on the bounds of its children.setColor(float red, float green, float blue, float alpha) Sets the color of this object.Sets the object's color.setColorNotInherited(boolean enabled) Sets if this object DOESN'T pass on its color to its children.setConstrainToParent(boolean constrainToParent) Sets if this should constrain its position to its parent.setDimensions(float width, float height) Sets the object width and height.setEnabled(boolean enabled) Sets if the object can accept input (and its children).setInert(boolean inert) Sets if the object can accept/intercept input, but does NOT affect its "enabled" state, unless its parent is enabled/disabled.Sets this object's layout type for resizing object children, should this object get resized itself.setLayoutAttrib(Object attrib) Sets this object's layout attribute, used by some layouts in order to affect the parent's layout behavior when resizing this component (as a child).setOpacity(float opacity) Gets this object's opacity (0 to 1).setPosition(float x, float y) Sets the object position.setRendered(boolean rendered) Sets if the object is visible (and its children).setRotationZ(float degrees) Sets this object's rotation in degrees.setScaleType(GUIObject.ScaleType scaleType) Sets this object's texture scaling type.setTexture(String texture) Sets this object's texture.Sets the theme used by this object, and its descendants if they do not have a theme set.setVisible(boolean visible) Sets if the object is visible (and its children).stretch(float width, float height) Changes this object's width/height by an x or y-coordinate amount.toString()translate(float x, float y) Changes this object's position by an x or y-coordinate amount.final GUIObjectunbindAction(GUIAction action, String... types) Removes an action bound to an event type.final GUIObjectunbindAllActions(String... types) Removes all actions bound to event types.protected final voidUpdate the dirty flag on the GUI that this object belongs to.protected voidUpdates this GUI Object's position and absolute bounds in the scene's collision field.booleanShould the object's radius value be used for collision, with the camera, rather than its half-height or half-width?
-
Field Details
-
EVENT_UNKNOWN
-
EVENT_MOUSE_OVER
-
EVENT_MOUSE_LEAVE
Mouse cursor leaves this object (not over it anymore).- See Also:
-
EVENT_MOUSE_PRESS
-
EVENT_MOUSE_RELEASE
-
EVENT_MOUSE_MOVE
-
EVENT_MOUSE_DRAG
Mouse is dragged on this object (not moved, button is down).- See Also:
-
EVENT_MOUSE_CLICK
-
EVENT_MOUSE_WHEEL
-
EVENT_KEY_PRESS
-
EVENT_KEY_RELEASE
-
EVENT_KEY_TYPE
-
EVENT_GAMEPAD_PRESS
-
EVENT_GAMEPAD_RELEASE
Gamepad button is released on this object.- See Also:
-
EVENT_GAMEPAD_AXIS
-
EVENT_GAMEPAD_TAP_PRESS
Gamepad axis is tapped (press) on this object.- See Also:
-
EVENT_GAMEPAD_TAP_RELEASE
Gamepad axis is untapped (release) on this object.- See Also:
-
EVENT_GENERIC_INPUT
Some kind of generic input is sent to the GUI in the form of a code.- See Also:
-
EVENT_NAMED
-
EVENT_FOCUS
-
EVENT_BLUR
-
EVENT_CHANGE_ENABLE_STATE
-
EVENT_CHANGE_VISIBLE_STATE
-
absoluteBounds
This object's absolute bounds.
-
-
Constructor Details
-
GUIObject
protected GUIObject()Creates a new GUI object.
-
-
Method Details
-
getGUI
- Returns:
- the reference to which GUI scene this belongs to.
-
getParent
Gets the parent object of this one. Can be null if this is not a child object.- Returns:
- the parent object, or null if not added to an object.
-
addChild
Add a child object to this one and sets a layout attribute to it, as thoughsetLayoutAttrib(Object)- Parameters:
obj- the object to add.attrib- the layout attribute.- Returns:
- itself, to chain calls.
-
addChild
-
removeChild
-
remove
-
moveUp
Moves the order of this object up among its siblings, so that it is rendered later than the one after it (bringing it "closer to the camera").If this is the last one anyway, nothing happens.
If this is not the child of an object, nor does it belong to a GUI, nothing happens.
- Returns:
- itself, to chain calls.
-
moveToFront
Moves the order of this object up among its siblings, so that it is rendered last (bringing it "closest to the camera").If this is the last one anyway, nothing happens.
If this is not the child of an object, nor does it belong to a GUI, nothing happens.
- Returns:
- itself, to chain calls.
-
moveDown
Moves the order of this object back among its siblings, so that it is rendered earlier than the one before it (pushing it "further from the camera").If this is the first one anyway, nothing happens.
If this is not the child of an object, nor does it belong to a GUI, nothing happens.
- Returns:
- itself, to chain calls.
-
moveToBack
Moves the order of this object back among its siblings, so that it is rendered first (pushing it "farthest from the camera").If this is the first one anyway, nothing happens.
If this is not the child of an object, nor does it belong to a GUI, nothing happens.
- Returns:
- itself, to chain calls.
-
addToRenderSet
Called when this object needs adding to a render set for rendering later. Usually, this should add itself plus its children to the set. Assumes the render set's GUI bounds are set.- Parameters:
set- the set to add it to.
-
hasAction
Checks if an action has at least one binding.- Parameters:
type- the event type.- Returns:
- true if so, false if not.
-
bindAction
Adds an action bound to an event type. The action is enqueued, so the added action will happen after other actions bound to this event type.- Parameters:
action- the action to bind.types- the event types.- Returns:
- itself, to chain calls.
-
unbindAction
-
unbindAllActions
-
callAction
Calls an action on this object.- Parameters:
action- the action to call on this object.
-
fireEvent
Fires a non-specific event to the GUI system.- Parameters:
type- the event type to fire.
-
addName
Adds a single name or series of names to this object, used for selecting objects.- Parameters:
names- the names to add.
-
removeName
-
hasName
Checks if this object has a particular name.- Parameters:
name- the name to search for.- Returns:
- true if found, false if not.
-
hasNamePattern
-
getBounds
Returns a copy of this object's bounding rectangle. Any changes to the returned Rectangle2F will not change the bounds of this object, and thus will NOT trigger any events triggered by a bounds change.NOTE: The returned object reference is used by other calls to this method on this thread. If you wish to preserve the values returned, they will need to be copied.
- Returns:
- a rectangle of this object's bounds.
- See Also:
-
getNativeBounds
Returns a reference to this object's bounds rectangle. Any changes made to this rectangle will affect the object's bounds, but will NOT trigger any events triggered by a bounds change.- Returns:
- the rectangle reference.
- See Also:
-
setRotationZ
Sets this object's rotation in degrees.- Parameters:
degrees- the new rotation in degrees. 0 is no rotation.- Returns:
- itself, to chain calls.
-
rotate
Rotates this object by a number of degrees.- Parameters:
degrees- the rotation in degrees to add.- Returns:
- itself, to chain calls.
-
setColor
Sets the color of this object.- Parameters:
red- the red component value for the color.green- the green component value for the color.blue- the blue component value for the color.alpha- the alpha component value for the color.- Returns:
- itself, to chain calls.
-
setColor
-
getColor
Gets the object's color. If the object returned is changed, it will not affect this object's color.- Returns:
- an GUIColor with this object's color components.
-
setTexture
-
setVisible
Sets if the object is visible (and its children). Fires an event if the visibility state changed. This attribute affects this object's descendants - they are not visible if this is not visible. Objects that are not visible are ignored when testing for mouse collisions, nor are they drawn by the renderer.- Parameters:
visible- true to set, false to unset.- Returns:
- itself, to chain calls.
-
setRendered
Sets if the object is visible (and its children). Fires an event if the visibility state changed. This attribute affects this object's descendants - they are not visible if this is not visible. Objects that are not visible are ignored when testing for mouse collisions, nor are they drawn by the renderer.- Parameters:
rendered- true to set, false to unset.- Returns:
- itself, to chain calls.
-
setEnabled
Sets if the object can accept input (and its children). Fires an event if the enabled state changed. If this object was focused, it tells the GUI that owns it to unfocus it if it was disabled.- Parameters:
enabled- true to set, false to clear.- Returns:
- itself, to chain calls.
-
setInert
Sets if the object can accept/intercept input, but does NOT affect its "enabled" state, unless its parent is enabled/disabled. UnlikeisVisible()andisEnabled(), this is not hierarchically significant (inert-ness is set on this and ONLY this object). Objects that are inert are ignored when testing for mouse collisions. This fires NO EVENTS on change. If this object was focused, it tells the GUI that owns it to unfocus it if it was set to be inert.- Parameters:
inert- true to set, false to clear.- Returns:
- itself, to chain calls.
-
setBounds
-
setBounds
Sets the object bounds.- Parameters:
x- its position x.y- its position y.width- its width.height- its height.- Returns:
- itself, to chain calls.
-
getAbsoluteBounds
Gets this object's ABSOLUTE bounds, i.e. the object's current position after considering its inherited hierarchy. The Rectangle2F returned can be changed and it will not affect this object's bounds.- Returns:
- a Rectangle2F of the current object bounds.
-
setPosition
Sets the object position.- Parameters:
x- its position x.y- its position y.- Returns:
- itself, to chain calls.
-
setDimensions
Sets the object width and height.- Parameters:
width- its width.height- its height.- Returns:
- itself, to chain calls.
-
translate
Changes this object's position by an x or y-coordinate amount.- Parameters:
x- the x movement.y- the y movement.- Returns:
- itself, to chain calls.
-
stretch
Changes this object's width/height by an x or y-coordinate amount.- Parameters:
width- the width amount.height- the height amount.- Returns:
- itself, to chain calls.
-
getRenderPositionX
public final float getRenderPositionX()- Returns:
- the object's rendering position, x-axis.
-
getRenderPositionY
public final float getRenderPositionY()- Returns:
- the object's rendering position, y-axis.
-
getRenderWidth
public float getRenderWidth()- Returns:
- the object's rendering width.
-
getRenderHeight
public float getRenderHeight()- Returns:
- the object's rendering height.
-
getRenderRotationZ
public float getRenderRotationZ()- Returns:
- the object's rotation in degrees, z-axis.
-
getRenderRadius
public float getRenderRadius()Gets the object's radius, for use with determining what is on the screen or not.Since this could be an expensive call, this is not always used - it is used if the object's useRenderRadius() function returns true, which leaves it in the hands of the implementor.
- Returns:
- the radius.
-
useRenderRadius
public boolean useRenderRadius()Should the object's radius value be used for collision, with the camera, rather than its half-height or half-width?- Returns:
- the radius.
-
getRenderRed
public float getRenderRed()- Returns:
- the object's red channel value.
-
getRenderGreen
public float getRenderGreen()- Returns:
- the object's green channel value.
-
getRenderBlue
public float getRenderBlue()- Returns:
- the object's blue channel value.
-
getRenderAlpha
public float getRenderAlpha()- Returns:
- the object's alpha channel value.
-
getFinalOpacity
protected float getFinalOpacity()- Returns:
- this object's inherited opacity.
-
getRenderTextureScaleS
public float getRenderTextureScaleS()Gets the object's texture scaling, S-axis (U). Should, in most cases, return 1f.- Returns:
- the scaling value.
-
getRenderTextureScaleT
public float getRenderTextureScaleT()Gets the object's texture scaling, T-axis (V). Should, in most cases, return 1f.- Returns:
- the scaling value.
-
getGeneration
public final int getGeneration()Returns how far down the generation tree this object is.- Returns:
- How many parents are above this one.
-
getTexture
Returns this object's texture. If no texture is set on this, this will take the one from the theme, ifgetThemeKey()returns a non-null value.- Returns:
- the texture name.
- See Also:
-
getThemeKey
Returns this object's theme key. This is the key that is used to look up the texture used to render this object. This may return null, indicating that this object does not have a default texture.- Returns:
- the theme key.
-
isVisible
public boolean isVisible()Gets if the object is visible, which means that this object has its "visible" member set to true, and its opacity is nonzero. This object is not visible if any of its ancestors are not visible. Objects that are not visible are ignored when testing for mouse collisions.- Returns:
- true if visible, false if not.
-
getVisible
public boolean getVisible()Gets if this object is flagged as "visible". This differs fromisVisible()as this is not a calculated value.- Returns:
- true, if this particular object is flagged as visible, false otherwise.
-
getRendered
public boolean getRendered()Gets if this object is rendered. The object's children can still be rendered. UnlikeisVisible(), this is not hierarchically significant ("rendered" affects this and ONLY this object).- Returns:
- true if so, false if not.
-
isFocused
public boolean isFocused()Gets if this object is currently focused in its GUI.- Returns:
- true if so. False if not, or this doesn't belong to a GUI.
-
isAnimating
public boolean isAnimating()Gets if this object is currently animating- Returns:
- true if so. False if not, or this doesn't belong to a GUI.
-
isEnabled
public boolean isEnabled()Gets if the object can accept/intercept input. This affects this object's "enabled" state, as the name suggests. This object is not enabled if any of its ancestors are not enabled. Objects that are not enabled cannot be focused, and are also ignored when testing mouse collisions/events. They can still be manipulated through user-enacted methods that are not direct input.- Returns:
- true if enabled, false if not.
-
isInert
public boolean isInert()Gets if the object can accept/intercept input, but does NOT affect its "enabled" state, unless its parent is enabled/disabled. UnlikeisVisible()andisEnabled(), this is not hierarchically significant (inert-ness is set on this and ONLY this object). Objects that are inert are ignored when testing for mouse collisions.- Returns:
- true if inert, false if not.
-
isConstrainedToParent
public boolean isConstrainedToParent()Checks if this constrains its position to its parent.- Returns:
- true of so, false if not.
-
setConstrainToParent
Sets if this should constrain its position to its parent.- Parameters:
constrainToParent- true if so, false if not.- Returns:
- itself, to chain calls.
-
getAsQuery
-
getParentAsQuery
-
getChildrenAsQuery
-
getDescendantsAsQuery
-
getSiblingsAsQuery
-
getLayout
Gets this object's layout type for resizing object children, should this object get resized itself. By default, this value is null.- Returns:
- the layout, or null if no layout.
-
setLayout
-
getLayoutAttrib
Gets this object's layout attribute, used by some layouts in order to affect the parent's layout behavior when resizing this component (as a child). By default, this value is null.- Returns:
- the layout attribute on this object, or null if none was set.
-
setLayoutAttrib
Sets this object's layout attribute, used by some layouts in order to affect the parent's layout behavior when resizing this component (as a child). By default, this value is null. Changing this value while this object is a part of its parent's layout will triggerresizeChildren()on the parent.- Parameters:
attrib- the layout attribute to set (or null).- Returns:
- itself, to chain calls.
-
getColorNotInherited
public boolean getColorNotInherited()Gets if this object DOESN'T pass on its color to its children.- Returns:
- true of so, false if not.
-
setColorNotInherited
Sets if this object DOESN'T pass on its color to its children.- Parameters:
enabled- true if- Returns:
- itself, to chain calls.
-
getTheme
Returns the current theme used by this object. If no current theme, this returns the parent's theme. If no parent, this returns the theme attached the owning GUI.- Returns:
- the theme to use.
-
setTheme
Sets the theme used by this object, and its descendants if they do not have a theme set. Setting this to null allows this object to inherit the current theme from its parents.- Parameters:
theme- the theme to use. Can be null.- Returns:
- itself, to chain calls.
-
getOpacity
public float getOpacity()Gets this object's opacity (0 to 1). Opacity is always inherited by children, regardless of ifgetColorNotInherited()is true or false. This affects visibility - if this is 0.0, this object is considered NOT VISIBLE.- Returns:
- this object's opacity.
- See Also:
-
setOpacity
Gets this object's opacity (0 to 1). Opacity is always inherited by children, regardless of ifgetColorNotInherited()is true or false. This affects visibility - setting this to 0.0 is like settingsetVisible(boolean)tofalse.- Parameters:
opacity- the new opacity factor.- Returns:
- itself, to chain calls.
-
getScaleType
- Returns:
- this object's texture scaling type.
-
setScaleType
Sets this object's texture scaling type.- Parameters:
scaleType- the scaling type to use.- Returns:
- itself, to chain calls.
-
setBoundsByChildren
public void setBoundsByChildren()Sets this object's width and height based on the bounds of its children. If it has no children, nothing happens. -
requestFocus
Requests focus on this object in the scene it belongs to.- Returns:
- itself, to chain calls.
-
releaseFocus
Releases focus on this object if this object currently has focus in the scene it belongs to.- Returns:
- itself, to chain calls.
-
resizeChildren
public void resizeChildren()Calls upon the layouts to resize the children. -
animate
Enqueues an animation on this GUI Object, no duration.- Parameters:
animations- the animations to perform (at once) for this animation.- Returns:
- itself, to chain calls.
-
animate
Enqueues an animation on this GUI Object, linear transition.- Parameters:
duration- the duration of the action in time units.animations- the animations to perform (at once) for this animation.- Returns:
- itself, to chain calls.
-
animate
Enqueues an animation on this GUI Object.- Parameters:
duration- the duration of the action in time units.transition- the transition type for the action.animations- the animations to perform (at once) for this animation.- Returns:
- itself, to chain calls.
-
animateDelay
Enqueues a delay between animations on this GUI Object.- Parameters:
duration- the duration of the action in time units.- Returns:
- itself, to chain calls.
-
animateAbort
Aborts the animation on this object, abandoning it mid-animation.- Returns:
- itself, to chain calls.
-
animateFinish
Finishes the animation on this object all the way to the end.- Returns:
- itself, to chain calls.
-
correctPosition
protected void correctPosition()Corrects the position of this object, if this is constrained to the parent's position. -
updateScenePosition
protected void updateScenePosition()Updates this GUI Object's position and absolute bounds in the scene's collision field. -
updateDirty
protected final void updateDirty()Update the dirty flag on the GUI that this object belongs to. -
onGUIChange
Called when this object is added to a GUI. Does nothing, unless overridden.- Parameters:
gui- the reference to the GUI that this was added to.
-
toString
-