Shaper
Source: Shaper.js:41
The function of this class and its subclasses is to draw a set of "shapes" that will be used to
place ActiveBox objects at a specific position, and to determine its dimension and
appearance.
Constructor
new Shaper(nx: number, ny: number): ShaperShaper constructor
Parameters
nx(number) — Number of columns (in grid-based shapers)ny(number) — Number of rows (in grid-based shapers)
Instance Methods
reset(nCols: number, nRows: number)
Initializes this Shaper to default values
Parameters
nCols(number) — Number of columnsnRows(number) — Number of rows
setProperties($xml: external:jQuery)
Loads this shaper settings from a specific JQuery XML element
Parameters
$xml(external:jQuery) — The XML element with the shaper data
getAttributes(): object
Gets a object with the basic attributes needed to rebuild this instance excluding functions,
parent references, constants and also attributes retaining the default value.
The resulting object is commonly usued to serialize elements in JSON format.
Returns
object
buildShapes()
Builds the individual shapes that will form this Shaper
getShape(
n: number,
rect: module:AWT.Rectangle,
): module:AWT.Shape
Gets a clone of the nth Shape object, scaled and located inside a Rectangle
Parameters
n(number)rect(module:AWT.Rectangle)
Returns
getShapeData(n: number): object
Gets the nth Shape data object
Parameters
n(number)
Returns
object
getEnclosingShapeData(): module:AWT.Rectangle
Gets the AWT.Rectangle that contains all shapes of this Shaper.
Returns
getRemainderShape(
rect: module:AWT.Rectangle,
): module:AWT.Rectangle
When hasRemainder is true, this method gets the rectangle containing the full surface where
the Shaper develops.
Parameters
rect(module:AWT.Rectangle) — The frame where to move and scale all the shapes
Returns
Static Methods
registerClass(
shaperName: string,
shaperClass: function,
): module:shapers/Shaper.Shaper
Registers a new type of shaper
Parameters
shaperName(string) — The name used to identify this shapershaperClass(function) — The shaper class, usually extending Shaper
Returns
getShaper(
className: string,
nx: number,
ny: number,
): module:shapers/Shaper.Shaper
Factory constructor that returns a Shaper of the requested class.
Parameters
className(string) — The class name of the requested Shaper.nx(number) — Number of columns (in grid-based shapers)ny(number) — Number of rows (in grid-based shapers)
Returns
readShapeData(
$xml: external:jQuery,
scaleX: number,
scaleY: number,
): module:AWT.Shape
Reads an individual shape from an XML element.
Shapes are arrays of stroke objects.
Each stroke has an action (move to, line to, quad to...) and associated data.
Parameters
$xml(external:jQuery) — The XML element with the shape datascaleX(number)scaleY(number)
Returns
factory(data: object): module:shapers/Shaper.Shaper
Builds a new shaper, based on the properties specified in a data object
Parameters
data(object) — The data object to be parsed
Returns
Instance Fields
className: string
This shaper class name
nCols: number
Number of columns (useful in grid-based shapers)
nRows: number
Number of rows (useful in grid-based shapers)
nCells: number
Number of cells managed by this shaper
shapeData: object
Contains the specific definition of each shape
initiated: boolean
Flag used to check if the Shaper has been initialized against a real surface
baseWidthFactor: number
In JigSaw, ratio between the base width of the tooth and the total length of the side.
toothHeightFactor: number
In JigSaw, ratio between the tooth height and the total length of the side.
randomLines: boolean
In JigSaw, whether the tooths take random directions or not
scaleX: number
In Holes, scale to be applied to horizontal positions and lengths to achieve the real
value of the shape placed on a real surface.
scaleY: number
In Holes, scale to be applied to vertical positions and lengths to achieve the real
value of the shape placed on a real surface.
enclosing: module:AWT.Shape
In Holes, the enclosing area where all shapes are placed.
showEnclosure: boolean
In Holes, when true, the enclosing area will be drawn
rectangularShapes: boolean
Flag indicating if this shaper organizes its cells in rows and columns
hasRemainder: boolean
Flag indicating if this Shaper deploys over a surface biggest than the rectangle enclosing
all its shapes
customShapes: boolean
Only the Holes shaper has this flag activated
Static Fields
CLASSES: object
List of known classes derived from Shaper. It should be filled by real shaper classes at
declaration time.