Canvas Nasal API

Revision as of 23:18, 25 February 2013 by Necolatis (talk | contribs) (List of 2.10 Nasal Canvas methods (what I wish I had when I made my HUD))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Work in progress!! Just saved for backup.

Canvas consist of a class with various nestable classes (elements).

See the 2.10 API here.

Canvas

For constructor see: Initialize a Canvas

addPlacement

See: Place a Canvas

setColorBackground

Parameters: (r, g, b, a)

Fills the background of the entire canvas with the supplied color.

createGroup

Parameters: ()

Parameters: (name)

Returns: Group

Create a new group under this Canvas. Supplying name is optional.

getPath

Parameters: ()

?

del

Parameters: ()

Deletes this Canvas.

wrapCanvas

Parameters: ()

?

get

Parameters: (name)

Returns: Canvas

Returns the canvas with the specified name.

parsesvg

Parameters: (group, file)

Parameters: (group, file, font-mapper)

See: SVG inside a Canvas

Element

Note that in each element there are 2 transformation matrices. The first will be applied first, then the second.

update

Parameters: ()

Normally an element gets updated in the next frame. Calling this will make it update in the current frame. Note that visibility methods do get updated in the current frame.

getVisible

Parameters: ()

Returns: visible

Returns 0 if not visible, 1 if visible.

setVisible

Parameters: ()

Parameters: (visible)

Sets if this element should be visible. 0 sets it not visible, 1 visible. No parameters sets it visible.

show

Parameters: ()

Sets the element visible.

hide

Parameters: ()

Sets the element not visible.

toggleVisibility

Parameters: ()

Toggles if element should be visible.

setGeoPosition

Parameters: (lat, lon)

?

createTransform

Parameters: ()

Parameters: ([a, b, c, d, e, f])

Return: The new (second) transform

Creates a new (second) transformation matrix for this element. No parameters will create a default identity matrix transform. Otherwise supply a 6 element vector for the matrix:

a b c
d e f
0 0 1

setTranslation

Parameters: (x, y)

Translates the element. The translation is set on the second transform.

setRotation

Parameters: (x, y)

Rotates the element around the center. The rotation is set on the first transform.

setScale

Parameters: (x, y)

Scales the element. The scale is set on the second transform.

getScale

Parameters: ()

Return: 2 element vector [x,y]

Returns the scale of this element.

setColorFill

Parameters: (r, g, b)

Parameters: (r, g, b, a)

Sets the color/alpha to be used as fill value. If you do not want the element to be filled, do not call this method.

getBoundingBox

Parameters: ()

Returns: [minX, minY, maxX, maxY]

Returns the bounds of the element.

updateCenter

Parameters: ()

Sets the center to be the center of the boundingbox in relation to the elements position in its parent.

setCenter

Parameters: (x, y)

Sets the center of the element that is used for rotation.

getCenter

Parameters: ()

Gets the center of the element.

Group

Inherits from element.

set

Parameters: (key, value)

key = "clip"

Makes a clipping bounds for the group, only what is inside the clipping bounds will be shown.

It uses same coordinate format as Clipping

Example: my_grp.set("clip", "rect(62px, 587px, 262px, 437px)"); # top,right,bottom,left

key = "font"

Sets the default font.

Example: my_group.set("font", "LiberationFonts/LiberationMono-Regular.ttf");

key = "stroke"

?

key = "fill"

?

setDouble

Parameters: (key, value)

key = "character-aspect-ration"

?

key = "character-size"

?

createChild

Parameters: (type)

Parameters: (type, name)

Returns: Element

Creates a child element under this Group. Name can be supplied. Type can be "text", "group", "path", "image", "map". Return an Element of the particular type specified.

createChildren

Parameters: (type, count)

Returns: [Element]

Creates a number of child elements under this Group. Return a vector of Elements of the particular type specified.

getChildren

Parameters: ()

Returns: [Element]

Returns all the child elements of this group.

getElementById

Parameters: (name)

Returns: Element

Returns the first found child element with the specified name.

removeAllChildren

Parameters: ()

Removes all the child elements from this group.

Text

Inherits from element.

setText

setAlignment

setFontSize

setFont

setDrawMode

setPadding

setMaxWidth

setColor

setColorFill

Path

Inherits from element.

reset

setData

setDataGeo

addSegment

moveTo

move

lineTo

line

horizTo

horiz

vertTo

vert

quadTo

quad

cubicTo

cubic

quadTo

quad

scubicTo

scubic

arcSmallCCWTo

arcSmallCCW

arcSmallCWTo

arcSmallCW

arcLargeCCWTo

arcLargeCCW

arcLargeCWTo

arcLargeCW

close

setColor

setColorFill

setFill

setStroke

setStrokeLineWidth

setStrokeLineCap

setStrokeDashArray

Map

Inherits from element.

See: Canvas Maps and Canvas Map API

Image

Inherits from element.

See: Canvas Image