Class GUI

java.lang.Object
com.blackrook.gui.GUI

public class GUI extends Object
Main GUI structure.
Author:
Matthew Tropiano
  • 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

      public void addObject(GUIObject obj)
      Adds a GUI Object to this GUI (plus children).
      Parameters:
      obj - the object to add.
    • removeObject

      public boolean removeObject(GUIObject obj)
      Removes a GUI Object from this GUI (plus children).
      Parameters:
      obj - the object to remove.
      Returns:
      true if removed, false if not.
    • addToRenderSet

      public void addToRenderSet(GUIRenderSet set)
      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

      public void bindBroadcastAction(GUIKeyStroke keystroke, GUIAction action)
      Adds a broadcast key event to this GUI. All keystrokes made to this GUI perform the associated KeyStroke. Actions are called in the order that they were bound.
      Parameters:
      keystroke - the keystroke to add.
      action - the associated action.
    • unbindBroadcastAction

      public boolean unbindBroadcastAction(GUIKeyStroke keystroke, GUIAction action)
      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

      public boolean unbindAllBroadcastActions(GUIKeyStroke keystroke)
      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

      public void requestObjectFocus(GUIObject object)
      Requests an object focus and fires object events. Fires events if and only if object is not the currently-focused object.
      Parameters:
      object - the object requesting focus.
    • requestObjectUnfocus

      public void requestObjectUnfocus(GUIObject object)
      Requests that an object be unfocused, but only if it was the one currently in focus.
      Parameters:
      object - the object to unfocus.
    • getFocusedObject

      public GUIObject getFocusedObject()
      Returns:
      the object that currently has focus in this GUI. Can be null if no object has focus.
    • getViewport

      public GUI.Viewport getViewport()
      Gets this GUI's viewport (this affects what is displayed).
      Returns:
      the GUI's current viewport.
    • getTheme

      public GUITheme getTheme()
      Returns:
      the current theme used by the GUI. If no current theme, this returns null.
    • setTheme

      public void setTheme(GUITheme theme)
      Sets the theme used by all objects.
      Parameters:
      theme - the theme to set.
    • getAll

      public GUIQuery getAll()
      Gets all GUI Objects.
      Returns:
      a query result.
    • getAnimating

      public GUIQuery getAnimating()
      Gets all GUI Objects that are in an animation.
      Returns:
      a query result.
    • getByName

      public GUIQuery getByName(String name)
      Gets all GUI Objects with a matching name.
      Parameters:
      name - the name to use.
      Returns:
      a query result.
    • getByPattern

      public GUIQuery getByPattern(Pattern pattern)
      Gets all GUI Objects with a matching name RegEx pattern.
      Parameters:
      pattern - the pattern to use.
      Returns:
      a query result.
    • getByType

      public GUIQuery getByType(Class<?> clazz)
      Gets all GUI Objects with a matching name.
      Parameters:
      clazz - the class type to search on.
      Returns:
      a query result.
    • 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

      public boolean sendName(String name)
      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

      public String toString()
      Overrides:
      toString in class Object