Class DOMPointerDriver

A PointerDriver which listens for pointer events from HTML DOM elements. Each HTML DOM element is bound to a specific root, which synergizes well with DOMRoot.

Automatically registers a pointer to be used by the mouse.

Hierarchy (view full)

Constructors

Properties

domElems: WeakMap<Root, DOMPointerDriverBind> = ...

The HTML DOM element and listeners that each root is bound to

hints: Map<number, PointerHint> = ...

The hints for each pointer. The keys are pointer IDs, while the values are that pointer's hint.

See PointerDriver#getPointerHint

mousePointerID: number

The pointer ID of the mouse. Registered in constructor. This is needed due to wheel events not being part of the DOM PointerEvent interface and therefore not having a pointerID field. This is also safe because there can only be one mouse.

pointers: Map<number, number> = ...

The mapping between each DOM pointer ID and internal pointer ID

states: Map<Root, PointerDriverState> = ...

The current state for each registered and enabled root. Contains whether each root is pressing, hovering, and which pointer is bound to it

Methods

  • Get the internal pointer ID of a given event. If the event has a pointer which hasn't been registered yet, then it is registered automatically

    Parameters

    • event: PointerEvent

    Returns number

  • Handle the capture of a DOM event. If captured, then the event will be stopImmediatePropagation'ed, and preventDefault'ed if it's a wheel event.

    Parameters

    • event: Event
    • captured: boolean

    Returns void

  • Dispatch a pointer event to a given root. The type of PointerEvent is decided automatically based on the root's state and whether its pressing or not.

    If null, the last pressing state is used, meaning that the pressing state has not changed. Useful if getting pointer movement in an event based environment where you only know when a pointer press occurs, but not if the pointer is pressed or not

    Parameters

    • root: Root
    • pointer: number

      The registered pointer ID

    • xNorm: number

      The normalised (non-integer range from 0 to 1) X coordinate of the pointer event. 0 is the left edge of the root, while 1 is the right edge of the root.

    • yNorm: number

      The normalised (non-integer range from 0 to 1) Y coordinate of the pointer event. 0 is the top edge of the root, while 1 is the bottom edge of the root.

    • pressing: null | number

      Is the pointer pressed? If null, then the last pressing state will be used. A bitmask where each set bit represents a different button being pressed

    • shift: boolean

      Is shift being pressed?

    • ctrl: boolean

      Is control being pressed?

    • alt: boolean

      Is alt being pressed?

    Returns boolean

    Returns true if the pointer event was captured.

  • Unbind a HTML DOM element from this pointer driver that is bound to a given Root. Removes all used listeners.

    Parameters

    Returns void

  • Unregister a pointer.

    If a root has this pointer bound to it, the pointer is unbound from the root, a LeaveRootEvent event is dispatched to the root and the hovering and pressing state of the root is set to false.

    Parameters

    • pointer: number

    Returns void

  • Dispatch a mouse wheel event in a given 2D direction. Event will only be dispatched if the root was being hovered.

    Parameters

    • root: Root
    • pointer: number

      The registered pointer ID

    • xNorm: number

      The normalised (non-integer range from 0 to 1) X coordinate of the pointer event. 0 is the left edge of the root, while 1 is the right edge of the root.

    • yNorm: number

      The normalised (non-integer range from 0 to 1) Y coordinate of the pointer event. 0 is the top edge of the root, while 1 is the bottom edge of the root.

    • deltaX: number

      How much was scrolled horizontally, in pixels

    • deltaY: number

      How much was scrolled vertically, in pixels

    • deltaZ: number

      How much was scrolled in the Z axis, in pixels. Rarely used

    • deltaMode: PointerWheelMode

      How the delta values should be interpreted

    • shift: boolean

      Is shift being pressed?

    • ctrl: boolean

      Is control being pressed?

    • alt: boolean

      Is alt being pressed?

    Returns boolean

    Returns true if the pointer event was captured.