API Docs for: 0.3.0
Show:

Event.MouseInput Class

EventProvider using the mouse.

Four events are provided:

  • MOUSE_MOVE (object containing x and y properties)
  • MOUSE_BUTTON_LEFT (type boolean)
  • MOUSE_BUTTON_RIGHT (type boolean)
  • MOUSE_BUTTON_MIDDLE (type boolean)

Each button is either MOUSE_PRESSED or MOUSE_RELEASED following the mouse state.
The MOUSE_MOVE state contain directly and object representing the position of the object. At each mouse movement, a new event is created, updating the values.

Constructor

Event.MouseInput

(
  • [target]
)

Parameters:

  • [target] HTMLElement optional

    element listened. Only mouse events on target are considered. default to window.document.

Example:

 var mouse = new MouseInput();
 mouse.addListener("MOUSE_BUTTON_LEFT", MouseInput.BUTTON_PRESSED, function(event, value, provider) {
 });

Methods

_getAssociatedEvent

(
  • event
)
String | Null private

search a state corresponding to the event object

Parameters:

  • event MouseEvent

Returns:

String | Null: name of state changed. null if no state is found.

_modifyState

(
  • event
  • newValue
)
protected

Apply a modification to an internal state variable and call listeners.

Parameters:

  • event String

    event name

  • newValue

    the new value.

_onMouseDown

(
  • event
)
private

Called when a mouse button is pressed.

Parameters:

  • event MouseEvent

_onMouseMove

(
  • event
)
private

Called when a mouse is moved.

Parameters:

  • event MouseEvent

_onMouseUp

(
  • event
)
private

Called when a mouse button is released.

Parameters:

  • event MouseEvent

_showContextMenu

(
  • event
)
private

remove showing of context menu

Parameters:

  • event MouseEvent

addListener

(
  • [event]
  • [value]
  • callback
)
Number

add a listener.

it can listen all events or only one event variable. The listener can choose to be called for all events associated to a variable, or only when the variable is in a certain state.

Parameters:

  • [event] String optional

    name of event variable. y default, all events are caught.

  • [value] optional

    value expected for call the callback. By default, any value call the callback.

  • callback Function

    callback function called with 3 parameters:

    • event String

      event name

    • value

      new value

    • provider EventProvider

      instance of provider

Returns:

Number: listener id (used for remove it with rmListener)

Example:

 //myCallback will be called for each events.
 provider.addListener(myCallback);

 //mySecondCallback will be called only when the "A" variable obtain the state KEY_PRESSED.
 provider.addListener("A", provider.KEY_PRESSED, mySecondCallback);

getOldState

(
  • name
)

Search the previous state of a state variable. The provider keep always one old state for each variable. It's useful for compare the difference.

Parameters:

  • name String

Returns:

: value of corresponding variable

getState

(
  • name
)

Search the state of a state variable

Parameters:

  • name String

Returns:

: value of corresponding variable

getStateList

() String

List all variables accessible by this provider Each variable can accept listeners.

Note: return value is a reference. you should make a copy if you need to modify it.

Returns:

String: [] list of name variables.

getType

() String

Inherited from Event.EventProvider but overwritten in modules/Event/MouseInput.js:97

return the EventProvider type.

Returns:

String: "MOUSE"

rmListener

(
  • id
)

Remove a listener.

Parameters:

  • id Number

    id of the listener.

Properties

_oldValues

Array protected

List of previous values for state variables. this._states and this._oldValues share the same array index.

_states []

String protected

List of all event variables name.

_values

Array protected

List of values for state variables. this._states and this._values share the same array index.

BUTTON_PRESSED

Boolean static

Represent a button pressed state

BUTTON_RELEASED

Boolean static

Represent a button released state

contextMenuActive

Boolean

Enable or disable context menu display on right click.

Default: true