Module: container

Provides access to the 3D canvas element and its container.

Summary

Methods

Detailed Description

Methods

client_to_canvas_coords(x, y, destopt) → {Vec2}

Convert client(e.clientX/e.clientY) CSS coordinates to CSS coordinates relative to the Canvas.
Parameters:
Name Type Attributes Default Description
x number X client coordinate.
y number Y client coordinate.
dest Vec2 <optional>
Float32Array(2) Destination vector.
Returns:
CSS coordinates relative to the Canvas.
Type
Vec2
Source:

client_to_element_coords(x, y, element, destopt) → {Vec2}

Convert client(e.clientX/e.clientY) CSS coordinates to CSS coordinates relative to the HTML element.
Parameters:
Name Type Attributes Default Description
x number X client coordinate.
y number Y client coordinate.
element HTMLElement HTML element.
dest Vec2 <optional>
Float32Array(2) Destination vector.
Returns:
CSS coordinates relative to the Canvas.
Type
Vec2
Source:

force_offsets_updating()

Update canvas offsets on the next request.
Deprecated
  • Not needed anymore.
Source:

get_canvas() → {HTMLElement}

Returns the 3D canvas element.
Returns:
Canvas element
Type
HTMLElement
Source:

get_canvas_hud() → {HTMLElement}

Returns the HUD element.
Returns:
Canvas hud element
Type
HTMLElement
Source:

get_container() → {HTMLElement}

Returns the HTML element which contains the 3D canvas.
Returns:
Canvas container element
Type
HTMLElement
Source:

get_coords_target_space(event, use_target_touchesopt, destopt) → {Vec2}

Get CSS coordinates from the given MouseEvent or TouchEvent transformed into the space of its target element.
Parameters:
Name Type Attributes Default Description
event MouseEvent | TouchEvent An event to get values from.
use_target_touches boolean <optional>
false For TouchEvent use only those touches that were started on the event target element (the targetTouches property).
dest Vec2 <optional>
Float32Array(2) Destination vector.
Returns:
CSS coordinates relative to the Canvas.
Type
Vec2
Source:
Example
var m_cont = require("container");
var m_input = require("input");
var _vec2_tmp = new Float32Array(2);

var canvas = m_cont.get_canvas();
m_input.add_click_listener(canvas, function(event) {
    var coords = m_cont.get_coords_target_space(event, false, _vec2_tmp);
});

insert_to_container(elem, stack_order)

Inserts the DOM element to the container.
Parameters:
Name Type Description
elem HTMLElement Inserted DOM element.
stack_order string Inserted DOM element stack order (one of "FIRST", "JUST_BEFORE_CANVAS", "JUST_AFTER_CANVAS", "LAST").
Source:

resize(width, height, update_canvas_cssopt)

Resize the rendering canvas.
Parameters:
Name Type Attributes Default Description
width number New canvas width
height number New canvas height
update_canvas_css boolean <optional>
true Change canvas CSS width/height
Source:

resize_to_container(forceopt)

Fit canvas elements to match the size of container element.
Parameters:
Name Type Attributes Default Description
force boolean <optional>
false Resize canvas element even in case of matching of canvas and container size.
Source:

set_canvas_offsets(left, top)

Set left/top offsets (relative to browser window) for the canvas. Can be useful in case of scrolling/DOM-manipulations, when the canvas position has been changed.
Parameters:
Name Type Description
left number Left offset for the container
top number Top offset for the container
Deprecated
  • Not needed anymore.
Source:

update_canvas_offsets()

Update canvas left/top offsets (relative to browser window). Can be useful in case of scrolling/DOM-manipulations, when the canvas position has been changed.
Deprecated
  • Not needed anymore.
Source: