Class UIHud

All Implemented Interfaces:
Hintable, Savable

public class UIHud extends Node
UIHud represents a "Heads Up Display" or the base of a game UI scenegraph. Various UI Input, dragging, events, etc. are handled through this class.
  • Field Details

    • MOUSE_CLICK_SENSITIVITY

      public static int MOUSE_CLICK_SENSITIVITY
    • _logicalLayer

      protected final LogicalLayer _logicalLayer
      The logical layer used by this UI to receive input events.
    • _mouseInputConsumed

      protected boolean _mouseInputConsumed
      Internal flag indicating whether the last input event was consumed by the UI. This is used to decide if we will forward the event to the next LogicalLayer.
    • _keyInputConsumed

      protected boolean _keyInputConsumed
  • Constructor Details

    • UIHud

      public UIHud(Canvas canvas)
      Construct a new UIHud for a given canvas
      Parameters:
      canvas - the canvas
  • Method Details

    • getLastMouseX

      public int getLastMouseX()
      Returns:
      the last detected x position of the mouse.
    • getLastMouseY

      public int getLastMouseY()
      Returns:
      the last detected y position of the mouse.
    • getTooltip

      public UITooltip getTooltip()
      Returns:
      this hud's associated tooltip object.
    • add

      public void add(UIComponent component)
      Add the given component to this hud.
      Parameters:
      component - the component to add
    • remove

      public void remove(UIComponent component)
      Remove the given component from the hud
      Parameters:
      component - the component to remove
    • detachAllChildren

      public void detachAllChildren()
      Overridden to force component detachments to go through remove(UIComponent)
      Overrides:
      detachAllChildren in class Node
    • bringToFront

      public void bringToFront(UIComponent component)
      Reorder the components so that the given component is drawn last and is therefore "on top" of any others.
      Parameters:
      component - the component to bring to front
    • getUIComponent

      public UIComponent getUIComponent(int x, int y)
      Look for a UIComponent at the given screen coordinates. If no pickable component is at that location, null is returned.
      Parameters:
      x - the x screen coordinate
      y - the y screen coordinate
      Returns:
      the picked component or null if nothing pickable was found at the given coordinates.
    • getFocusedComponent

      public UIComponent getFocusedComponent()
      Returns:
      the component that currently has key focus or null if none.
    • setFocusedComponent

      public void setFocusedComponent(UIComponent compomponent)
      Parameters:
      compomponent - the component that should now have key focus. If this component has a focus target, that will be used instead.
    • getDragButton

      public MouseButton getDragButton()
      Returns:
      the MouseButton that triggers drag operations
    • setDragButton

      public void setDragButton(MouseButton dragButton)
      Parameters:
      dragButton - set the MouseButton that triggers drag operations
    • draw

      public void draw(Renderer r)
      Override to force setting ortho before drawing and to specifically handle draw order of components and tool tip.
      Overrides:
      draw in class Node
      Parameters:
      r - the renderer to draw to.
      See Also:
    • updateGeometricState

      public void updateGeometricState(double time, boolean initiator)
      Description copied from class: Spatial
      updateGeometricState updates all the geometry information for the node.
      Overrides:
      updateGeometricState in class Spatial
      Parameters:
      time - The time in seconds between the last two consecutive frames (time per frame). See ReadOnlyTimer.getTimePerFrame()
      initiator - true if this node started the update process.
    • addDragListener

      public void addDragListener(DragListener listener)
      Add the given drag listener to this hud. Expired WeakReferences are also cleaned.
      Parameters:
      listener - the listener to add
    • removeDragListener

      public boolean removeDragListener(DragListener listener)
      Remove any matching drag listener from this hud. Expired WeakReferences are also cleaned.
      Parameters:
      listener - the listener to remove
      Returns:
      true if at least one "equal" DragListener was found in the pool of listeners and removed.
    • addHudListener

      public void addHudListener(HudListener listener)
      Add the given hud listener to this hud.
      Parameters:
      listener - the listener to add
    • removeHudListener

      public boolean removeHudListener(HudListener listener)
      Remove any matching hud listener from this hud.
      Parameters:
      listener - the listener to remove
      Returns:
      true if at least one "equal" HudListener was found in the pool of listeners and removed.
    • getLogicalLayer

      public LogicalLayer getLogicalLayer()
      Returns:
      the logical layer associated with this hud. When chaining UI logic to game logic, this LogicalLayer is the one to call checkTriggers on.
    • isIgnoreMouseInputOnGrabbed

      public boolean isIgnoreMouseInputOnGrabbed()
      Returns:
      true if we should ignore (only forward) mouse input when the mouse is set to grabbed. If true, requires mouse manager to be set or this param is ignored.
    • setIgnoreMouseInputOnGrabbed

      public void setIgnoreMouseInputOnGrabbed(boolean mouseInputOnGrabbed)
      Parameters:
      mouseInputOnGrabbed - true if we should ignore (only forward) mouse input when the mouse is set to grabbed. If true, requires mouse manager to be set or this param is ignored.
      See Also:
    • getMouseManager

      public MouseManager getMouseManager()
      Returns:
      a MouseManager used to test if mouse is grabbed, or null if none was set.
    • setMouseManager

      public void setMouseManager(MouseManager manager)
      Parameters:
      manager - a MouseManager used to test if mouse is grabbed.
    • setupInput

      public void setupInput(PhysicalLayer physicalLayer, LogicalLayer forwardTo)
      Convenience method for setting up the UI's connection to the Ardor3D input system, along with a forwarding address for input events that the UI does not care about.
      Parameters:
      physicalLayer - the physical layer to register with
      forwardTo - a LogicalLayer to send unconsumed (by the UI) input events to.
    • setupLogicalLayer

      protected void setupLogicalLayer()
      Set up our logical layer with a trigger that hands input to the UI and saves whether it was "consumed".
    • offerKeyInputToUI

      protected boolean offerKeyInputToUI(TwoInputStates inputStates)
    • offerMouseInputToUI

      protected boolean offerMouseInputToUI(TwoInputStates inputStates)
      Parse a given set of input states for UI events and pass these events to the UI components contained in this hud.
      Parameters:
      inputStates - our two InputState objects, detailing a before and after snapshot of the input system.
      Returns:
      true if a UI element consumed the event described by inputStates.
    • fireMouseButtonPressed

      public boolean fireMouseButtonPressed(MouseButton button, InputState currentIS)
      Handle mouse presses.
      Parameters:
      button - the button that was pressed.
      currentIS - the current input state.
      Returns:
      true if this event is consumed.
    • fireMouseButtonReleased

      public boolean fireMouseButtonReleased(MouseButton button, InputState currentIS)
      Handle mouse releases.
      Parameters:
      button - the button that was release.
      currentIS - the current input state.
      Returns:
      true if this event is consumed.
    • fireMouseMoved

      public boolean fireMouseMoved(int mouseX, int mouseY, InputState currentIS)
      Handle movement events.
      Parameters:
      mouseX - the new x position of the mouse
      mouseY - the new y position of the mouse
      currentIS - the current input state.
      Returns:
      if this event is consumed.
    • fireMouseWheelMoved

      public boolean fireMouseWheelMoved(int wheelDx, InputState currentIS)
      Handle wheel events.
      Parameters:
      wheelDx - the change in wheel position.
      currentIS - the current input state.
      Returns:
      if this event is consumed.
    • fireKeyPressedEvent

      public boolean fireKeyPressedEvent(Key key, InputState currentIS)
      Handle key presses.
      Parameters:
      key - the pressed key
      currentIS - the current input state.
      Returns:
      if this event is consumed.
    • fireKeyHeldEvent

      public boolean fireKeyHeldEvent(Key key, InputState currentIS)
      Handle key held (pressed down over more than one input update cycle.)
      Parameters:
      key - the held key
      currentIS - the current input state.
      Returns:
      if this event is consumed.
    • fireKeyReleasedEvent

      public boolean fireKeyReleasedEvent(Key key, InputState currentIS)
      Handle key releases.
      Parameters:
      key - the released key
      currentIS - the current input state.
      Returns:
      if this event is consumed.
    • getWidth

      public int getWidth()
    • getHeight

      public int getHeight()
    • closePopupMenus

      public void closePopupMenus()
    • closePopupMenusAfter

      public void closePopupMenusAfter(Object parent)
    • showPopOver

      public void showPopOver(IPopOver pop)
    • showSubPopupMenu

      public void showSubPopupMenu(IPopOver pop)
    • getPostKeyboardHook

      public UIHud.UIInputPostHook getPostKeyboardHook()
    • setPostKeyboardHook

      public void setPostKeyboardHook(UIHud.UIInputPostHook postKeyboardHook)
    • getPostMouseHook

      public UIHud.UIInputPostHook getPostMouseHook()
    • setPostMouseHook

      public void setPostMouseHook(UIHud.UIInputPostHook postMouseHook)
    • getCanvas

      public Canvas getCanvas()