Class GUI
java.lang.Object
com.blackrook.gui.GUI
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceGUI.Animation<G extends GUIObject>Describes an animation to be performed on an object.static classGUI.AnimationState<T extends GUIObject>Animation state.static classA viewport "camera" that describes how or what is displayed of the GUI. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a GUI Object to this GUI (plus children).voidAdds all objects in the GUI to a render set for rendering later.voidbindBroadcastAction(GUIKeyStroke keystroke, GUIAction action) Adds a broadcast key event to this GUI.voidResets/clears the GUI state.getAll()Gets all GUI Objects.Gets all GUI Objects that are in an animation.Gets all GUI Objects with a matching name.getByPattern(Pattern pattern) Gets all GUI Objects with a matching name RegEx pattern.Gets all GUI Objects with a matching name.getTheme()Gets this GUI's viewport (this affects what is displayed).booleanisDirty()Checks if the GUI has potentially changed, and will need to be redrawn.booleanremoveObject(GUIObject obj) Removes a GUI Object from this GUI (plus children).voidrequestObjectFocus(GUIObject object) Requests an object focus and fires object events.voidrequestObjectUnfocus(GUIObject object) Requests that an object be unfocused, but only if it was the one currently in focus.booleansendGamepadAxisChange(int joystickId, int joystickAxisId, float value) Called to send a joystick axis change type event.booleansendGamepadAxisTapPress(int joystickId, int joystickAxisId, boolean position) Called to send a joystick axis tap type event.booleansendGamepadAxisTapRelease(int joystickId, int joystickAxisId, boolean position) Called to send a joystick axis tap type event.booleansendGamepadPress(int joystickId, int joystickButton) Called to send a joystick button press type event.booleansendGamepadRelease(int joystickId, int joystickButton) Called to send a joystick button release type event.booleansendGenericInput(int code) Called to send a generic input event.booleansendKeyPress(int keycode) Called to send a key press event.booleansendKeyRelease(int keycode) Called to send a key release event.booleansendKeyType(int keycode) Called to send a key type event.voidsendMouseEnter(int mouseX, int mouseY) Called to send a "mouse entered the GUI" event.voidCalled to send a "mouse exited the GUI" event.voidsendMousePosition(int mouseX, int mouseY) Called to send a mouse move event.booleansendMousePress(int mousebutton) Called to send a mouse button press type event.booleansendMouseRelease(int mousebutton) Called to send a mouse button press type event.booleansendMouseWheel(int units) Called to send a mouse button press type event.booleanCalled to send a broadcast event by name.voidsetDirty(boolean dirty) Sets if this GUI has potentially changed, and will need to be redrawn.voidSets the theme used by all objects.toString()voidRemoves all specific broadcast key events from this GUI for a keystroke.booleanunbindAllBroadcastActions(GUIKeyStroke keystroke) Removes all specific broadcast key events from this GUI for a keystroke.booleanunbindBroadcastAction(GUIKeyStroke keystroke, GUIAction action) Removes a specific broadcast key event from this GUI.voidupdate(long timeslice) Updates this GUI.
-
Constructor Details
-
GUI
public GUI()Creates a new GUI instance.
-
-
Method Details
-
isDirty
public boolean isDirty()Checks if the GUI has potentially changed, and will need to be redrawn.- Returns:
- true if so, false if not.
-
setDirty
public void setDirty(boolean dirty) Sets if this GUI has potentially changed, and will need to be redrawn.- Parameters:
dirty- true if so, false if not.
-
addObject
Adds a GUI Object to this GUI (plus children).- Parameters:
obj- the object to add.
-
removeObject
Removes a GUI Object from this GUI (plus children).- Parameters:
obj- the object to remove.- Returns:
- true if removed, false if not.
-
addToRenderSet
Adds all objects in the GUI to a render set for rendering later. Depending on some object flags or their bounds, some objects or sets of objects are not rendered.- Parameters:
set- the set to add it to.
-
bindBroadcastAction
Adds a broadcast key event to this GUI. All keystrokes made to this GUI perform the associatedKeyStroke. Actions are called in the order that they were bound.- Parameters:
keystroke- the keystroke to add.action- the associated action.
-
unbindBroadcastAction
Removes a specific broadcast key event from this GUI.- Parameters:
keystroke- the associated keystroke.action- the action to remove.- Returns:
- true if removed successfully, false otherwise.
-
unbindAllBroadcastActions
Removes all specific broadcast key events from this GUI for a keystroke.- Parameters:
keystroke- the keystroke to remove.- Returns:
- true if removed successfully, false otherwise.
-
unbindAllBroadcastActions
public void unbindAllBroadcastActions()Removes all specific broadcast key events from this GUI for a keystroke. -
requestObjectFocus
Requests an object focus and fires object events. Fires events if and only ifobjectis not the currently-focused object.- Parameters:
object- the object requesting focus.
-
requestObjectUnfocus
Requests that an object be unfocused, but only if it was the one currently in focus.- Parameters:
object- the object to unfocus.
-
getFocusedObject
- Returns:
- the object that currently has focus in this GUI. Can be null if no object has focus.
-
getViewport
Gets this GUI's viewport (this affects what is displayed).- Returns:
- the GUI's current viewport.
-
getTheme
- Returns:
- the current theme used by the GUI. If no current theme, this returns null.
-
setTheme
Sets the theme used by all objects.- Parameters:
theme- the theme to set.
-
getAll
-
getAnimating
Gets all GUI Objects that are in an animation.- Returns:
- a query result.
-
getByName
-
getByPattern
-
getByType
-
clearState
public void clearState()Resets/clears the GUI state. This does NOT fire events. This consists of:- Current moused-over object.
- Current object the mouse button is pressed on.
- Current pressed mouse button.
- Current "drag state."
- Current focused object.
- Current modifiers for keys (used with broadcast).
- Current mouse enter state.
- Current mouse position X.
- Current mouse position Y.
- Current mouse movement X.
- Current mouse movement Y.
- Current mouse current object X.
- Current mouse current object Y.
-
sendName
Called to send a broadcast event by name. The event is only broadcast.- Parameters:
name- the generic code to send.- Returns:
- true if handled, false if not.
-
sendGenericInput
public boolean sendGenericInput(int code) Called to send a generic input event. The event is first broadcast, then sent to the currently-focused object. If this is handled by an existing broadcast event, it is still sent to the focused object.- Parameters:
code- the generic code to send.- Returns:
- true if handled by a component, false if not.
-
sendKeyPress
public boolean sendKeyPress(int keycode) Called to send a key press event. The key press is first broadcast, then sent to the currently-focused object. If this is handled by an existing broadcast event, it is still sent to the focused object. This also sets the current key's mask internally, if the key has an associated mask.- Parameters:
keycode- a key code to send.- Returns:
- true if handled by a component, false if not.
-
sendKeyRelease
public boolean sendKeyRelease(int keycode) Called to send a key release event. The key release is first broadcast, then sent to the currently-focused object. If this is handled by an existing broadcast event, it is still sent to the focused object. This also clears the current key's mask internally, if the key has an associated mask.- Parameters:
keycode- a key code to send.- Returns:
- true if handled by a component, false if not.
-
sendKeyType
public boolean sendKeyType(int keycode) Called to send a key type event. The key type is only sent to the currently-focused object.- Parameters:
keycode- a key code to send.- Returns:
- true if handled by a component, false if not.
-
sendMousePress
public boolean sendMousePress(int mousebutton) Called to send a mouse button press type event. A button press is handled by the currently moused-over object.- Parameters:
mousebutton- the mouse button id.- Returns:
- true if handled by a component, false if not.
-
sendMouseRelease
public boolean sendMouseRelease(int mousebutton) Called to send a mouse button press type event. A button release is handled by the currently moused-over object. If the same object was previously the subject of a mouse press, a CLICK event is also sent to that object.- Parameters:
mousebutton- the mouse button id.- Returns:
- true if handled by a component, false if not.
-
sendMouseWheel
public boolean sendMouseWheel(int units) Called to send a mouse button press type event. A mouse wheel change is handled by the currently focused object.- Parameters:
units- the amount of wheel units.- Returns:
- true if handled by a component, false if not.
-
sendMousePosition
public void sendMousePosition(int mouseX, int mouseY) Called to send a mouse move event. This sets the current mouse coordinates of this GUI, which affects what the currently moused-over object is, and may also send MOUSE LEAVE or MOUSE ENTER events. If a mouse button is already pressed on an object, a DRAG event is sent to it, but only if it handles it. A mouse move is also handled by the currently moused-over object.NOTE: This is not affected by viewport. You need to calculate that.
- Parameters:
mouseX- the mouse position, X-axis.mouseY- the mouse position, Y-axis.
-
sendMouseEnter
public void sendMouseEnter(int mouseX, int mouseY) Called to send a "mouse entered the GUI" event. A mouse enter sets the initial mouse position.- Parameters:
mouseX- the entry x-coordinate.mouseY- the entry y-coordinate.
-
sendMouseExit
public void sendMouseExit()Called to send a "mouse exited the GUI" event. A mouse exit is handled by the currently moused-over object, then clears the currently-moused over object. -
sendGamepadPress
public boolean sendGamepadPress(int joystickId, int joystickButton) Called to send a joystick button press type event. The button press is first broadcast, then sent to the currently-focused object. If this is handled by an existing broadcast event, it is still sent to the focused object.- Parameters:
joystickId- the game pad id.joystickButton- the joystick button.- Returns:
- true if handled by a component, false if not.
-
sendGamepadRelease
public boolean sendGamepadRelease(int joystickId, int joystickButton) Called to send a joystick button release type event. The button release is first broadcast, then sent to the currently-focused object. If this is handled by an existing broadcast event, it is still sent to the focused object.- Parameters:
joystickId- the game pad id.joystickButton- the joystick button.- Returns:
- true if handled by a component, false if not.
-
sendGamepadAxisChange
public boolean sendGamepadAxisChange(int joystickId, int joystickAxisId, float value) Called to send a joystick axis change type event. The axis change is only sent to the currently-focused object.- Parameters:
joystickId- the game pad id.joystickAxisId- the axis id.value- the axis value.- Returns:
- true if handled by a component, false if not.
-
sendGamepadAxisTapPress
public boolean sendGamepadAxisTapPress(int joystickId, int joystickAxisId, boolean position) Called to send a joystick axis tap type event. An "axis tap" is when a joystick axis is brought from a value in its deadzone to outside of it. The axis tap is first broadcast, then sent to the currently-focused object. If this is handled by an existing broadcast event, it is still sent to the focused object.- Parameters:
joystickId- the game pad id.joystickAxisId- the axis id.position- the axis position (true = not in deadzone).- Returns:
- true if handled by a component, false if not.
-
sendGamepadAxisTapRelease
public boolean sendGamepadAxisTapRelease(int joystickId, int joystickAxisId, boolean position) Called to send a joystick axis tap type event. An "axis tap" is when a joystick axis is brought from a value in its deadzone to outside of it. The axis tap is first broadcast, then sent to the currently-focused object. If this is handled by an existing broadcast event, it is still sent to the focused object.- Parameters:
joystickId- the game pad id.joystickAxisId- the axis id.position- the axis position (true = not in deadzone).- Returns:
- true if handled by a component, false if not.
-
update
public void update(long timeslice) Updates this GUI.- Parameters:
timeslice- the time slice amount to update the animations by.
-
toString
-