Home Reference Source
import Renderer from 'newton-lib/src/utils/Renderer.js'
private class | source

Renderer

Enables an element to be prerendered in a hidden canvas. Once an element is prerendered it can be drawn to the main canvas faster. If an element has not changed, then prerendered version will be used, thus optimizing the application.

Constructor Summary

Public Constructor
public

Member Summary

Public Members
public

Sets if the rendered image will be drawn with respect to the axis of the world or not.

public

Function used to set the drawing procedure for the renderer.

public

Arguments passed to the callback function used to draw onto the renderer.

public

Canvas element where the object will be prerendered.

public

Context of the canvas element where the object will be prerendered.

public

Flag for switching the renderer on or off.

public

Sets if the target object is an axis.

public

Sets the object that will be prerendered.

public

Flag for signaling when then object has been drawn in the hidden canvas.

public

Sets the reference to the world object.

Method Summary

Public Methods
public

begin()

Starts the drawing process of the rendered canvas on the world canvas.

public

end()

Finishes the drawing process of the rendered canvas on the world canvas.

public

render()

Set the flags required to start the rendering process.

public

setCallback(f: function, args: *)

Sets the callback function for when the renderer is drawn.

Private Methods
private

draw()

Draws the rendered canvas onto the world canvas.

private

resize()

Resizes the rendered canvas to match the size of the world's canvas. It is automatically called when the canvas gets resized.

private

setWorld(world: World)

Sets the world object used by the renderer.

Public Constructors

public constructor(opts: object) source

Params:

NameTypeAttributeDescription
opts object
  • optional

Object that contains valid Renderer properties with values. Their values will be assigned at the end of the constructor. If an invalid property is passed then the value will be ignored.

Public Members

public absolute: boolean source

Sets if the rendered image will be drawn with respect to the axis of the world or not. Default value is false.

public callback: function source

Function used to set the drawing procedure for the renderer.

public callbackArgs: * source

Arguments passed to the callback function used to draw onto the renderer.

public canvas: object source

Canvas element where the object will be prerendered.

public ctx: object source

Context of the canvas element where the object will be prerendered.

public enabled: boolean source

Flag for switching the renderer on or off. If it is set to false, then the object will be drawn normally on the main canvas. Default value is true.

public isAxis: boolean source

Sets if the target object is an axis. It is important to set this property for all axis objects. Default value is false.

public parent: object source

Sets the object that will be prerendered. Default value is undefined.

public rendered: boolean source

Flag for signaling when then object has been drawn in the hidden canvas. Default value is false.

public world: World source

Sets the reference to the world object. Default value is undefined.

Public Methods

public begin() source

Starts the drawing process of the rendered canvas on the world canvas. It sets the translation depending on the value of Renderer.absolute.

public end() source

Finishes the drawing process of the rendered canvas on the world canvas.

public render() source

Set the flags required to start the rendering process. The flag Renderer.enabled is set to true and the flag Renderer.rendered is set to false.

public setCallback(f: function, args: *) source

Sets the callback function for when the renderer is drawn.

Params:

NameTypeAttributeDescription
f function

Callback function.

args *

Arguments passed to the callback function when called.

Private Methods

private draw() source

Draws the rendered canvas onto the world canvas.

private resize() source

Resizes the rendered canvas to match the size of the world's canvas. It is automatically called when the canvas gets resized.

private setWorld(world: World) source

Sets the world object used by the renderer. It is automatically set by the world when the element is added to the world.

Params:

NameTypeAttributeDescription
world World

World object where the renderer will draw the render.