Foundry Virtual Tabletop - API Documentation - Version 14
    Preparing search index...

    Handle mouse interaction events for a Canvas object. There are three phases of events: hover, click, and drag

    Hover Events: _handlePointerOver action: hoverIn _handlePointerOut action: hoverOut

    Left Click and Double-Click _handlePointerDown action: clickLeft action: clickLeft2 action: unclickLeft

    Right Click and Double-Click _handleRightDown action: clickRight action: clickRight2 action: unclickRight

    Drag and Drop _handlePointerMove action: dragLeftStart action: dragRightStart action: dragLeftMove action: dragRightMove _handlePointerUp action: dragLeftDrop action: dragRightDrop _handleDragCancel action: dragLeftCancel action: dragRightCancel

    Index

    Constructors

    • Parameters

      • object: DisplayObject

        The Canvas object (e.g., a Token, Tile, or Drawing) to which mouse events should be bound.

      • layer: Container<DisplayObject>

        The Canvas Layer that contains the object.

      • Optionalpermissions: object = {}

        An object of permission checks, keyed by action name, which return a boolean or invoke a function for whether the action is allowed.

      • Optionalcallbacks: object = {}

        An object of callback functions, keyed by action name, which will be executed during the event workflow (e.g., hoverIn, clickLeft).

      • Optionaloptions: { application?: Application<ICanvas>; dragResistance?: number; target?: string } = {}

        Additional options that configure interaction behavior.

        • Optionalapplication?: Application<ICanvas>

          A specific PIXI Application to use for pointer event handling defaults to canvas.app if not provided.

        • OptionaldragResistance?: number

          A minimum number of pixels the mouse must move before a drag is initiated.

        • Optionaltarget?: string

          If provided, the property name on object which references a foundry.canvas.containers.ControlIcon. This is used to set MouseInteractionManager#controlIcon.

      Returns MouseInteractionManager

    Properties

    _dragRight: boolean

    A flag for whether we are right-click dragging

    controlIcon: ControlIcon | null

    An optional ControlIcon instance for the object

    dragTime: number

    The drag handling time

    interactionData: Record<string, any>

    Bound interaction data object to populate with custom data.

    lastClick: Point = ...

    The client position of the last left/right-click.

    lcTime: number

    The time of the last left-click event

    options: { dragResistance: number; target: DisplayObject }

    Interaction options which configure handling workflows

    rcTime: number

    The time of the last right-click event

    state: number

    The current interaction state

    viewId: string

    The view id pertaining to the PIXI Application. If not provided, default to canvas.app.view.id

    DEFAULT_DRAG_RESISTANCE_PX: number = 10

    The minimum distance, measured in screen-coordinate pixels, that a pointer must move to initiate a drag operation. This default value can be overridden by specifying the dragResistance option when invoking the constructor.

    DOUBLE_CLICK_DISTANCE_PX: number = 5

    The maximum number of pixels between two clicks to be considered a double-click.

    DOUBLE_CLICK_TIME_MS: number = 250

    The maximum number of milliseconds between two clicks to be considered a double-click.

    INTERACTION_STATES: {
        CLICKED: number;
        DRAG: number;
        DROP: number;
        GRABBED: number;
        HOVER: number;
        NONE: number;
    } = ...

    Enumerate the states of a mouse interaction workflow. 0: NONE - the object is inactive 1: HOVER - the mouse is hovered over the object 2: CLICKED - the object is clicked 3: GRABBED - the object is grabbed 4: DRAG - the object is being dragged 5: DROP - the object is being dropped

    LONG_PRESS_DURATION_MS: number = 500

    The number of milliseconds of mouse click depression to consider it a long press.

    longPressTimeout: number | null = null

    Global timeout for the long-press event.

    Accessors

    • get handlerOutcomes(): Record<string, number>

      A reference to the possible interaction states which can be observed

      Returns Record<string, number>

    • get isDragging(): boolean

      Is this mouse manager in a dragging state?

      Returns boolean

    • get states(): Record<string, number>

      A reference to the possible interaction states which can be observed

      Returns Record<string, number>

    • get target(): DisplayObject

      Get the target.

      Returns DisplayObject

    Methods

    • Execute a callback function associated with a certain action in the workflow

      Parameters

      • action: string

        The action being attempted

      • event: Event | FederatedEvent<UIEvent | PixiTouch>

        The event being handled

      • ...args: any[]

        Additional callback arguments.

      Returns boolean

      A boolean which may indicate that the event was handled by the callback. Events which do not specify a callback are assumed to have been handled as no-op.

    • Test whether the current user has permission to perform a step of the workflow

      Parameters

      • action: string

        The action being attempted

      • event: Event | FederatedEvent<UIEvent | PixiTouch>

        The event being handled

      Returns boolean

      Can the action be performed?

    • A public method to cancel a current interaction workflow from this manager.

      Parameters

      • Optionalevent: FederatedEvent<UIEvent | PixiTouch>

        The event that initiates the cancellation

      Returns void

    • A public method to handle directly an event into this manager, according to its type. Note: drag events are not handled.

      Parameters

      • event: FederatedEvent<UIEvent | PixiTouch>

      Returns boolean

      Has the event been processed?

    • Reset the mouse manager.

      Parameters

      • Optionaloptions: { interactionData?: boolean; state?: boolean } = {}
        • OptionalinteractionData?: boolean

          Reset the interaction data?

        • Optionalstate?: boolean

          Reset the state?

      Returns void

    • Emulate a pointermove event on the main game canvas. This method must be called when an object with the static event mode or any of its parents is transformed or its visibility is changed.

      Returns void