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 |
addPosition(x: number, y: number) 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 |
setPosition(x: number, y: number) Sets the position of the element. |
|
public |
Sets the scale of the element. |
|
public |
Sets the z-index of the element. |
Private Methods | ||
private |
resize() Function called when the canvas gets resized. |
|
private |
Sets the world object where element will be drawn. |
|
private |
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 dragging: boolean source
Flag set when the element is being dragged around. Default value is false.
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.
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 Methods
public draggable(s: boolean) source
Sets if the element is draggable.
Params:
Name | Type | Attribute | Description |
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.
public setColor(c: string) source
Sets the color in HEX format of the element.
Params:
Name | Type | Attribute | Description |
c | string | Desired color in HEX format. |
public setScale(s: number) source
Sets the scale of the element.
Params:
Name | Type | Attribute | Description |
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:
Name | Type | Attribute | Description |
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.