Class GuiComponent

All Implemented Interfaces:
KeyboardInputHandler, MouseInteractionController
Direct Known Subclasses:
TextEditComponent

public class GuiComponent extends AbstractCompositeShape implements KeyboardInputHandler, MouseInteractionController
Base class for interactive GUI components rendered in 3D space.

GuiComponent combines a composite shape with keyboard and mouse interaction handling. When clicked, it acquires keyboard focus (via the KeyboardFocusStack), and a red wireframe border is displayed to indicate focus. Pressing ESC releases focus.

This class is the foundation for interactive widgets like the TextEditComponent.

Usage example - creating a custom GUI component:


 GuiComponent myWidget = new GuiComponent(
     new Transform(new Point3D(0, 0, 300)),
     viewPanel,
     new Point3D(400, 300, 0)  // width, height, depth
 );

 // Add visual content to the widget
 myWidget.addShape(someTextCanvas);

 // Add to the scene
 viewPanel.getRootShapeCollection().addShape(myWidget);
 
See Also:
  • Field Details

    • viewPanel

      public final ViewPanel viewPanel
      The view panel this component is attached to.
  • Constructor Details

    • GuiComponent

      public GuiComponent(Transform transform, ViewPanel viewPanel, Point3D size)
      Creates a GUI component with the specified transform, view panel, and bounding box size.
      Parameters:
      transform - the position and orientation of the component in 3D space
      viewPanel - the view panel this component belongs to
      size - the bounding box dimensions (width, height, depth)
  • Method Details

    • focusLost

      public boolean focusLost(ViewPanel viewPanel)
      Description copied from interface: KeyboardInputHandler
      Called when the component loses keyboard focus.
      Specified by:
      focusLost in interface KeyboardInputHandler
      Parameters:
      viewPanel - the view panel that owns this handler
      Returns:
      true if view needs to be re-rendered
    • focusReceived

      public boolean focusReceived(ViewPanel viewPanel)
      Description copied from interface: KeyboardInputHandler
      Called when the component receives keyboard focus.
      Specified by:
      focusReceived in interface KeyboardInputHandler
      Parameters:
      viewPanel - the view panel that owns this handler
      Returns:
      true if view needs to be re-rendered
    • getBorders

      public WireframeBox getBorders()
      Returns the wireframe border box for this component.
      Returns:
      the border wireframe box
    • getDepth

      public int getDepth()
      Returns the depth of this component's bounding box.
      Returns:
      the depth in pixels
    • getHeight

      public int getHeight()
      Returns the height of this component's bounding box.
      Returns:
      the height in pixels
    • getWidth

      public int getWidth()
      Returns the width of this component's bounding box.
      Returns:
      the width in pixels
    • hideBorder

      public void hideBorder()
      Hides the focus border around this component.
    • keyPressed

      public boolean keyPressed(KeyEvent event, ViewPanel viewPanel)
      Description copied from interface: KeyboardInputHandler
      Called when a key is pressed while the component has focus.
      Specified by:
      keyPressed in interface KeyboardInputHandler
      Parameters:
      event - the key event
      viewPanel - the view panel that owns this handler
      Returns:
      true if view needs to be re-rendered
    • keyReleased

      public boolean keyReleased(KeyEvent event, ViewPanel viewPanel)
      Description copied from interface: KeyboardInputHandler
      Called when a key is released while the component has focus.
      Specified by:
      keyReleased in interface KeyboardInputHandler
      Parameters:
      event - the key event
      viewPanel - the view panel that owns this handler
      Returns:
      true if view needs to be re-rendered
    • mouseClicked

      public boolean mouseClicked(int button)
      Description copied from interface: MouseInteractionController
      Called when mouse is clicked on component.
      Specified by:
      mouseClicked in interface MouseInteractionController
      Parameters:
      button - the mouse button that was clicked (1 = left, 2 = middle, 3 = right)
      Returns:
      true if view update is needed as a consequence of this mouse click
    • mouseEntered

      public boolean mouseEntered()
      Description copied from interface: MouseInteractionController
      Called when mouse gets over given component.
      Specified by:
      mouseEntered in interface MouseInteractionController
      Returns:
      true if view update is needed as a consequence of this mouse enter.
    • mouseExited

      public boolean mouseExited()
      Description copied from interface: MouseInteractionController
      Called when mouse leaves screen area occupied by component.
      Specified by:
      mouseExited in interface MouseInteractionController
      Returns:
      true if view update is needed as a consequence of this mouse exit.