NGL@1.0.0-beta.7 Home Manual Reference Source Gallery
import MouseObserver from 'ngl/src/stage/mouse-observer.js'
public class | source

MouseObserver

Mouse observer

Example:

// listen to mouse moving (and touch-moving) events
mouseObserver.moved.moved.add( function( deltaX, deltaY ){ ... } );
// listen to scrolling (and pinching) events
mouseObserver.signals.scrolled.add( function( delta ){ ... } );
// listen to dragging (and touch-dragging) events
mouseObserver.signals.dragged.add( function( deltaX, deltaY ){ ... } );
// listen to clicking (and tapping) events
mouseObserver.signals.clicked.add( function(){ ... } );
// listen to double clicking (and double tapping) events
mouseObserver.signals.doubleClicked.add( function(){ ... } );
// listen to hovering events
mouseObserver.signals.hovered.add( function(){ ... } );

Constructor Summary

Public Constructor
public

constructor(domElement: Element, params: Object)

Member Summary

Public Members
public

Flag indicating if the alt key is pressed

public

Indicates which mouse buttons were pressed: 0: No button; 1: Left button; 2: Right button; 4: Middle button

public

Position on dom element

public

Flag indicating if the ctrl key is pressed

public
public
public
public

Position on page when clicked

public
public
public

Flag indicating if the mouse is hovering

public get

key

public
public

Timestamp of last mouse move

public
public

Flag indicating if the meta key is pressed

public

Flag indicating if the mouse is moving

public
public

Position on page

public

Flag indicating if the mouse is pressed down

public
public

Previous position on page

public

Flag indicating if there was a scolling event since the last mouse move

public

Flag indicating if the shift key is pressed

public

Events emitted by the mouse observer

public

Indicates which mouse button was pressed: 0: No button; 1: Left button; 2: Middle button; 3: Right button

Method Summary

Public Methods
public
public
Private Methods
private
private

listen to mouse actions

private
private
private

_onMousemove(event: Event): undefined

handle mouse move

private

_onMouseup(event: Event): undefined

handle mouse up

private

_onMousewheel(event: Event): undefined

handle mouse scroll

private
private
private
private
private

Public Constructors

public constructor(domElement: Element, params: Object) source

Params:

NameTypeAttributeDescription
domElement Element

the dom element to observe mouse events in

params Object

parameters object

params.hoverTimeout Integer

timeout in ms until the MouseSignals.hovered signal is fired, set to -1 to ignore hovering

params.handleScroll Boolean

whether or not to handle scroll events

params.doubleClickSpeed Integer

max time in ms to trigger double click

Public Members

public altKey: Boolean source

Flag indicating if the alt key is pressed

public buttons: Integer source

Indicates which mouse buttons were pressed: 0: No button; 1: Left button; 2: Right button; 4: Middle button

public canvasPosition: Vector2 source

Position on dom element

public ctrlKey: Boolean source

Flag indicating if the ctrl key is pressed

public domElement source

public doubleClickPending source

public doubleClickSpeed source

public down: Vector2 source

Position on page when clicked

public handleScroll source

public hoverTimeout source

public hovering: Boolean source

Flag indicating if the mouse is hovering

public get key source

public lastClicked source

public lastMoved: Number source

Timestamp of last mouse move

public lastTouchDistance source

public metaKey: Boolean source

Flag indicating if the meta key is pressed

public moving: Boolean source

Flag indicating if the mouse is moving

public overElement source

public position: Vector2 source

Position on page

public pressed: Boolean source

Flag indicating if the mouse is pressed down

public prevClickCP source

public prevPosition: Vector2 source

Previous position on page

public scrolled: Boolean source

Flag indicating if there was a scolling event since the last mouse move

public shiftKey: Boolean source

Flag indicating if the shift key is pressed

public signals: MouseSignals source

Events emitted by the mouse observer

public which: Integer source

Indicates which mouse button was pressed: 0: No button; 1: Left button; 2: Middle button; 3: Right button

Public Methods

public dispose() source

public setParameters() source

Private Methods

private _distance() source

private _listen(): undefined source

listen to mouse actions

Return:

undefined

Emit:

MouseSignals.clicked

when clicked

MouseSignals.hovered

when hovered

private _onContextmenu() source

private _onMousedown() source

private _onMousemove(event: Event): undefined source

handle mouse move

Params:

NameTypeAttributeDescription
event Event

mouse event

Return:

undefined

Emit:

MouseSignals.moved

when moved

MouseSignals.dragged

when dragged

private _onMouseup(event: Event): undefined source

handle mouse up

Params:

NameTypeAttributeDescription
event Event

mouse event

Return:

undefined

Emit:

MouseSignals.doubleClicked

when double clicked

MouseSignals.dropped

when dropped

private _onMousewheel(event: Event): undefined source

handle mouse scroll

Params:

NameTypeAttributeDescription
event Event

mouse event

Return:

undefined

Emit:

MouseSignals.scrolled

when scrolled

private _onTouchend() source

private _onTouchmove() source

private _onTouchstart() source

private _setCanvasPosition() source

private _setKeys() source