Class SceneActionMap

java.lang.Object
com.victorvalentim.zividomelive.SceneActionMap

public final class SceneActionMap extends Object
Activation-scoped named actions and Processing input bindings.

Key and mouse bindings run on the Processing frame thread before the matching raw Scene callback. Programmatic trigger(String) calls run synchronously on the caller's thread, so scene code should trigger actions from Processing callbacks.

The runtime clears all bindings when the activation ends.

API stability: Advanced Stable.

Since:
2.0.0
  • Method Details

    • register

      public void register(String name, Runnable action)
      Registers or replaces a named action.
      Parameters:
      name - stable non-blank action name
      action - callback to run
    • bindKeyPressed

      public void bindKeyPressed(String name, char key, Runnable action)
      Registers an action and binds it to a key-press character.
      Parameters:
      name - stable non-blank action name
      key - Processing key character
      action - callback to run
    • bindKeyCodePressed

      public void bindKeyCodePressed(String name, int keyCode, Runnable action)
      Registers an action and binds it to a Processing key code.
      Parameters:
      name - stable non-blank action name
      keyCode - Processing key code
      action - callback to run
    • bindMouse

      public void bindMouse(String name, int mouseAction, Consumer<processing.event.MouseEvent> handler)
      Binds a named mouse handler such as MouseEvent.PRESS or MouseEvent.DRAG.

      Only one binding is retained for each Processing mouse action constant.

      Parameters:
      name - stable non-blank action name
      mouseAction - Processing mouse action constant
      handler - event consumer to run
    • trigger

      public boolean trigger(String name)
      Triggers a named action programmatically.
      Parameters:
      name - action name
      Returns:
      true when a registered action ran
    • unregister

      public void unregister(String name)
      Removes an action and all of its input bindings.
      Parameters:
      name - action name to remove
    • size

      public int size()
      Returns:
      number of named runnable actions plus separately registered mouse bindings
    • clear

      public void clear()
      Removes every action and binding.