Module: mouse

Pointer lock and mouse actions add-on. Provides support for mouse pointer lock and low-level movement. For more generic cases use sensor-based API.

Summary

Methods

Type Definitions

Detailed Description

Methods

check_pointerlock(elem) → {boolean}

Check the pointer lock.
Parameters:
Name Type Description
elem HTMLElement Element
Returns:
Check result
Type
boolean
Source:

disable_mouse_hover_outline()

Disable objects outlining by mouse hover.
Source:

enable_mouse_hover_outline(relative_canvasopt)

Enable objects outlining by mouse hover.
Parameters:
Name Type Attributes Default Description
relative_canvas boolean <optional>
false Calculate coordinates relative to canvas.
Source:

exit_mouse_drag(elem)

Exit drag mode.
Parameters:
Name Type Description
elem HTMLElement Element
Source:

exit_pointerlock()

Exit the pointer lock mode.
Source:

get_coords_x(event, use_target_touchesopt, relative_canvasopt) → {number}

Get mouse/touch X coordinate.
Parameters:
Name Type Attributes Default Description
event MouseEvent | TouchEvent Mouse/touch event
use_target_touches boolean <optional>
false Use only those touches that were started on the event target element (the targetTouches property).
relative_canvas boolean <optional>
false Return coordinates relative to event target.
Returns:
Mouse/touch X coordinate or -1 if not defined.
Type
number
Source:
Example
var m_cont = require("container");
var m_input = require("input");
var m_mouse = require("mouse");

var canvas = m_cont.get_canvas();
m_input.add_click_listener(canvas, function(event) {
    var x = m_mouse.get_coords_x(event);
    var y = m_mouse.get_coords_y(event);
});

get_coords_y(event, use_target_touchesopt, relative_canvasopt) → {number}

Get mouse/touch Y coordinate.
Parameters:
Name Type Attributes Default Description
event MouseEvent | TouchEvent Mouse/touch event
use_target_touches boolean <optional>
false Use only those touches that were started on the event target element (the targetTouches property).
relative_canvas boolean <optional>
false Return coordinates relative to event target.
Returns:
Mouse/touch Y coordinate or -1 if not defined.
Type
number
Source:
Example
var m_cont = require("container");
var m_input = require("input");
var m_mouse = require("mouse");

var canvas = m_cont.get_canvas();
m_input.add_click_listener(canvas, function(event) {
    var x = m_mouse.get_coords_x(event);
    var y = m_mouse.get_coords_y(event);
});

get_plock_smooth_factor() → {number}

Get smooth factor for camera rotation while in pointerlock mode.
Returns:
Smooth factor
Type
number
Source:

request_mouse_drag(elem, use_mouse_control_cbopt, rotation_cbopt, relative_canvasopt)

Request drag mode.
Parameters:
Name Type Attributes Default Description
elem HTMLElement Element
use_mouse_control_cb UseMouseControlCallback <optional>
Callback to check the mouse control
rotation_cb RotationCallback <optional>
Callback for camera rotation. If not specified, the default one will be used.
relative_canvas boolean <optional>
false Calculate coordinates relative to canvas.
Source:

request_pointerlock(elem, enabled_cbopt, disabled_cbopt, mouse_move_cbopt, use_mouse_control_cbopt, rotation_cbopt)

Request pointer lock mode. Security issues: execute by user event.
Parameters:
Name Type Attributes Description
elem HTMLElement Element
enabled_cb PointerlockEnabledCallback <optional>
Enabled callback
disabled_cb PointerlockDisabledCallback <optional>
Disabled callback
mouse_move_cb PointerlockMouseMoveCallback <optional>
Mouse movement event callback
use_mouse_control_cb UseMouseControlCallback <optional>
Callback to check the camera/character control
rotation_cb RotationCallback <optional>
Callback for camera rotation. If not specified, the default one will be used.
Source:

set_plock_smooth_factor(value)

Set smooth factor for camera rotation while in pointerlock mode.
Parameters:
Name Type Description
value number New smooth factor
Source:

Type Definitions

PointerlockDisabledCallback()

Callback which will be executed when pointer lock is disabled.
Source:

PointerlockEnabledCallback()

Callback which will be executed when pointer lock is enable.
Source:

PointerlockMouseMoveCallback(e)

Mouse movement event callback
Parameters:
Name Type Description
e MouseEvent mousemove event
Source:

RotationCallback(x, y)

Callback for camera/characters rotation
Parameters:
Name Type Description
x rot_x rotation around X-axis
y rot_y rotation around Y-axis
Source:

UseMouseControlCallback() → {boolean}

Callback which allows user to specify whether the camera/character movement is controlled by mouse module or not.
Returns:
False to disable mouse control of active camera/character
Type
boolean
Source: