rhodonite
    Preparing search index...

    Class InputManager

    Manages input event handling across different states in the Rhodonite engine.

    This class provides a centralized way to manage input events for different interaction modes such as camera control, gizmo manipulation, etc. It automatically handles adding and removing event listeners based on the current active state, ensuring that only the appropriate input handlers are active at any given time.

    The InputManager uses a state-based approach where different input handling states (like camera control or gizmo manipulation) can be registered with their respective event handlers. The manager then activates/deactivates these handlers based on the current application state.

    // Register input handlers for camera control
    InputManager.register(INPUT_HANDLING_STATE_CAMERA_CONTROLLER, [
    {
    eventName: 'mousedown',
    handler: onMouseDown,
    options: {},
    classInstance: cameraController,
    eventTargetDom: canvas
    }
    ]);

    // Activate camera controller
    InputManager.setActive(INPUT_HANDLING_STATE_CAMERA_CONTROLLER, true);
    Index

    Constructors

    Methods

    • Disables the camera controller input handling.

      This is a convenience method that deactivates the camera controller state and processes the event listeners accordingly. It's equivalent to calling setActive(INPUT_HANDLING_STATE_CAMERA_CONTROLLER, false).

      Returns void

      InputManager.disableCameraController();
      
    • Enables the camera controller input handling.

      This is a convenience method that activates the camera controller state and processes the event listeners accordingly. It's equivalent to calling setActive(INPUT_HANDLING_STATE_CAMERA_CONTROLLER, true).

      Returns void

      InputManager.enableCameraController();
      
    • Gets the current active input handling state.

      Returns string

      The currently active input handling state

      const currentState = InputManager.getCurrentState();
      if (currentState === INPUT_HANDLING_STATE_CAMERA_CONTROLLER) {
      console.log('Camera controller is active');
      }
    • Registers input handlers for a specific input handling state.

      This method associates a set of input event handlers with a particular state. When the state becomes active, these handlers will be automatically attached to their respective DOM elements.

      Parameters

      Returns void

      InputManager.register(INPUT_HANDLING_STATE_CAMERA_CONTROLLER, [
      {
      eventName: 'mousedown',
      handler: (e) => console.log('Mouse down'),
      options: { passive: false },
      classInstance: this,
      eventTargetDom: document.getElementById('canvas')
      }
      ]);
    • Sets the active state of a specific input handling state.

      This method controls whether the input handlers for a particular state should be active or inactive. When set to active, the corresponding event listeners will be attached. When set to inactive, they will be removed.

      Special handling is implemented for gizmo states - activating one gizmo state will automatically deactivate the other to prevent conflicts.

      Parameters

      • inputHandlingState: InputHandlingState

        The input handling state to modify

      • active: boolean

        Whether the state should be active (true) or inactive (false)

      Returns void

      // Activate camera controller
      InputManager.setActive(INPUT_HANDLING_STATE_CAMERA_CONTROLLER, true);

      // Deactivate camera controller
      InputManager.setActive(INPUT_HANDLING_STATE_CAMERA_CONTROLLER, false);
    • Unregisters and deactivates input handlers for a specific input handling state.

      This method removes all event handlers associated with the specified state and marks the state as inactive. All event listeners will be removed from their respective DOM elements.

      Parameters

      Returns void

      InputManager.unregister(INPUT_HANDLING_STATE_CAMERA_CONTROLLER);