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

WorldElement

Parent class for all elements added to the world. Sets the basic properties and methods all objects need.

Constructor Summary

Public Constructor
public

Member Summary

Public Members
public

Sets the color in HEX format of the element.

public

Sets the cursor style when the mouse is over the element.

public

Flag for enabling or diabling this element.

public

Flag set when the element is being dragged around.

public

Sets the font of the element.

public

Sets the current height of the element.

public

Flag for allowing the element to be dragged around.

public

Sets the move style of the element.

public

Flag set when the mouse is over the element.

public

Sets a callback function for when the element is dragged around.

public

Sets the position of the element.

public

Sets the renderer used for the element.

public

Sets the rotation of the element.

public

A copy of the z-index value is stored here.

public

Sets the drawing scale of the element.

public

Flag for determining if the element will be a top-most element when dragged around.

public

Flag used to determine if an object is a child of WorldElement.

public

Sets the current width of the element.

public

Sets the world where this element is found.

public

Sets the z-index of the element.

Method Summary

Public Methods
public

Adds the provided coordinates to the position.

public

Sets if the element is draggable.

public

Function called when the mouse moves to check if the pointer is over the element.

public

Sets the color in HEX format of the element.

public

Sets the position of the element.

public

Sets the scale of the element.

public

setZ(z: number)

Sets the z-index of the element.

Private Methods
private

resize()

Function called when the canvas gets resized.

private

setWorld(world: World)

Sets the world object where element will be drawn.

private

topmost(state: boolean)

Sets the element as a topmost element.

Public Constructors

public constructor() source

Public Members

public color: string source

Sets the color in HEX format of the element. The use of it depends on the type of element. Default value is COLORS.RED.

public cursor: string source

Sets the cursor style when the mouse is over the element. Default value is CURSOR.POINTER.

public display: boolean source

Flag for enabling or diabling this element. Default value is true.

public dragging: boolean source

Flag set when the element is being dragged around. Default value is false.

public font: Font source

Sets the font of the element. The default value is Font().

public height: number source

Sets the current height of the element. The default value is 0.

public isDraggable: boolean source

Flag for allowing the element to be dragged around. Default value is false.

public mouseMoveStyle: string source

Sets the move style of the element. Default value is MOVE_STYLE.BY_UNITS.

public mouseOver: boolean source

Flag set when the mouse is over the element. Default value is false.

public onMouseMove: function source

Sets a callback function for when the element is dragged around.

public position: object source

Sets the position of the element. The units can be in pixels or in units. Must look at the value of WorldElement.mouseMoveStyle.

Properties:

NameTypeAttributeDescription
x number
  • default: 0

x coordinate.

y number
  • default: 0

y coordinate.

public renderer: Renderer source

Sets the renderer used for the element. The default value is undefined.

public rotation: number source

Sets the rotation of the element. The units depend on the value of element's angle style. Default value is 0.

public savedZIndex: number source

A copy of the z-index value is stored here. When the element is dragged around, the element moves as a topmost element (only if WorldElement.topmostOnDrag is set to true). Therefore, the z-index of the element is increased and must be restored when the mouse gets released. The default value is 0.

public scale: number source

Sets the drawing scale of the element. Until now this property is only useful for Picture objects. Default value is 1.

public topmostOnDrag: boolean source

Flag for determining if the element will be a top-most element when dragged around. This means the element can be behind other objects, but when its dragged it will temporarily have a higher z-index. Default value is false.

public valid: boolean source

Flag used to determine if an object is a child of WorldElement. Only these objects have a WorldElement.valid flag. Default value is true.

public width: number source

Sets the current width of the element. The default value is 0.

public world: World source

Sets the world where this element is found. It is automatically set when added to the world.

public zIndex: number source

Sets the z-index of the element. Default value is 0.

Public Methods

public addPosition(x: number, y: number) source

Adds the provided coordinates to the position.

Params:

NameTypeAttributeDescription
x number

x coordinate.

y number

y coordinate.

public draggable(s: boolean) source

Sets if the element is draggable.

Params:

NameTypeAttributeDescription
s boolean

True sets the element as draggable, false otherwise.

public isMouseOver(): boolean source

Function called when the mouse moves to check if the pointer is over the element. The function is later replaced by the different types of elements.

Return:

boolean

Returns false by default.

public setColor(c: string) source

Sets the color in HEX format of the element.

Params:

NameTypeAttributeDescription
c string

Desired color in HEX format.

public setPosition(x: number, y: number) source

Sets the position of the element.

Params:

NameTypeAttributeDescription
x number

x coordinate.

y number

y coordinate.

public setScale(s: number) source

Sets the scale of the element.

Params:

NameTypeAttributeDescription
s number

Scale value for the element. Must be between 1 and 0.

public setZ(z: number) source

Sets the z-index of the element. It is used to sort the drawing order of the element. Those with the lowest z-index are drawn first. The highest z-index is drawn last.

Params:

NameTypeAttributeDescription
z number

Desired z-index.

Private Methods

private resize() source

Function called when the canvas gets resized. Enables the different element types to handle resize events differently depending on their needs. This is an empty resize function.

private setWorld(world: World) source

Sets the world object where element will be drawn. It is automatically set by the world when the element is added to it.

Params:

NameTypeAttributeDescription
world World

World of the element.

private topmost(state: boolean) source

Sets the element as a topmost element.

Params:

NameTypeAttributeDescription
state boolean

True sets the z-index to 1000, false sets the z-index to the saved z-index.