Shape
Source: AWT.js:820
Modifiers: abstract
Shape is a generic abstract class for rectangles, ellipses and stroke-free shapes.
Constructor
new Shape(pos: module:AWT.Point): ShapeShape constructor
Parameters
pos(module:AWT.Point) — The top-left coordinates of this Shape
Instance Methods
moveBy(delta: Point | Dimension): module:AWT.Shape
Shifts the shape a specified amount in horizontal and vertical directions
Parameters
Returns
moveTo(newPos: module:AWT.Point): module:AWT.Shape
Moves this shape to a new position
Parameters
newPos(module:AWT.Point) — The new position of the shape
Returns
getBounds(): module:AWT.Rectangle
Gets the enclosing Rectangle of this Shape.
Returns
equals(p: module:AWT.Shape): boolean
Checks if two shapes are equivalent.
Parameters
p(module:AWT.Shape) — The Shape to compare against
Returns
boolean
scaleBy(_delta: Point | Dimension): module:AWT.Shape
Multiplies the dimension of the Shape by the specified delta amount.
Parameters
Returns
getShape(rect: module:AWT.Rectangle): module:AWT.Shape
Gets a clone of this shape moved to the pos component of the rectangle and scaled
by its dim value.
Parameters
rect(module:AWT.Rectangle) — The rectangle to be taken as a base for moving and scaling
this shape.
Returns
contains(_p: module:AWT.Point): boolean
Checks if the provided module:AWT.Point is inside this shape.
Parameters
_p(module:AWT.Point) — The point to check
Returns
boolean
intersects(_r: module:AWT.Rectangle): boolean
Checks if the provided Rectangle r intersects with this shape.
Parameters
_r(module:AWT.Rectangle)
Returns
boolean
fill(
ctx: external:CanvasRenderingContext2D,
dirtyRegion?: module:AWT.Rectangle,
): external:CanvasRenderingContext2D
Fills the Shape with the current style in the provided HTML canvas context
Parameters
ctx(external:CanvasRenderingContext2D) — The canvas 2D rendering context where to fill this shape.dirtyRegion(module:AWT.Rectangle, optional) — The context region to be updated. Used as clipping
region when drawing.
Returns
stroke(
ctx: external:CanvasRenderingContext2D,
): external:CanvasRenderingContext2D
Draws this shape in the provided HTML canvas 2D rendering context.
Parameters
ctx(external:CanvasRenderingContext2D) — The canvas 2D rendering context where to draw the shape.
Returns
preparePath(
ctx: external:CanvasRenderingContext2D,
): external:CanvasRenderingContext2D
Prepares an HTML canvas 2D rendering context with a path that can be used to stroke a line,
to fill a surface or to define a clipping region.
Parameters
Returns
clip(
ctx: external:CanvasRenderingContext2D,
fillRule?: string,
): external:CanvasRenderingContext2D
Creates a clipping region on the specified HTML canvas 2D rendering context
Parameters
ctx(external:CanvasRenderingContext2D) — The rendering contextfillRule(string, optional, default: "'nonzero'") — Can be 'nonzero' (default when not set) or 'evenodd'
Returns
isRect(): boolean
Shorthand method for determining if a Shape is an Rectangle
Returns
boolean
toString(): string
Overwrites the original 'Object.toString' method with a more descriptive text
Returns
string
setAttributes(data: object): module:AWT.Shape
Reads the properties of this Shape from a data object
Parameters
data(object) — The data object to be parsed
Returns
Static Methods
buildShape(data: object): module:AWT.Shape
Builds a shape based on the provided data object.
Data should contain a 'type' member, specifying the type of shape requested ('rect', 'ellipse', 'rectangle' or 'path')
Parameters
data(object) — Specific data for this shape
Returns
Instance Fields
type: string
Shape type id (Rectangle, ellipse, path...)
pos: module:AWT.Point
The current position of the shape