Canvas Nasal API: Difference between revisions
m (Removed temp. statement) |
m (→setStrokeDashArray: made example bold) |
||
Line 352: | Line 352: | ||
Make dashed path. Pattern is a vector of alternating dash and gap lengths. ? horizontal, or misunderstood the vector ? | Make dashed path. Pattern is a vector of alternating dash and gap lengths. ? horizontal, or misunderstood the vector ? | ||
Example: my_path.setStrokeDashArray([10, 20, 10, 20, 10]); | '''Example:''' my_path.setStrokeDashArray([10, 20, 10, 20, 10]); | ||
=== setData === | === setData === | ||
=== setDataGeo === | === setDataGeo === |
Revision as of 01:10, 26 February 2013
Canvas consist of a class with various nestable classes (elements).
See inside 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
Parameters: (text)
Sets the text to be displayed.
setAlignment
Parameters: (alignment)
Sets how the text should be aligned with its position.
Examples of alignment: "left-top", "center-center", "right-bottom", "left-baseline", "center-bottom-baseline"
setFontSize
Parameters: (size, aspectRatio)
Sets the size and aspectRatio of the font. AspectRatio is the Ratio between character height and width. Default aspectRatio is 1.
setFont
Parameters: (fontName)
Sets the font to be used. See $FG_DATA/Fonts for list of fonts.
setDrawMode
Parameters: (mode)
Sets the drawing mode. You can use the values below and add those you need.
Text.TEXT: Draws the text
Text.BOUNDINGBOX: Draws the boundingbox
Text.FILLEDBOUNDINGBOX: Draws the filled boundingbox
Text.ALIGNMENT: Draws a cross where the element position is
Example: my_text.setDrawMode(Text.TEXT + Text.BOUNDINGBOX);
setPadding
?
setMaxWidth
?
setColor
Parameters: (r, g, b)
Parameters: (r, g, b, a)
Sets the color the text should be drawn in.
setColorFill
Parameters: (r, g, b)
Parameters: (r, g, b, a)
Sets the color the text background should be drawn in.
Path
Inherits from Element.
A path is similar to drawing with a pen on paper. The move and moveTo methods represent lifting the pen from the paper and moving to a new position. The drawing methods like lineTo would then be seen as starting from the current position of the pen. Therefore offcause the order the methods is called in, is important.
moveTo
Parameters: (x, y)
Moves the position to an new absolute position.
move
Parameters: (x, y)
Moves the position to an new relative position from the current.
reset
Parameters: ()
Remove all existing path data.
lineTo
Parameters: (x, y)
Draws a line to specified position.
line
Parameters: (x, y)
Draws a line to specified relative position.
horizTo
Parameters: (x)
Draws a horizontal line to specified position.
horiz
Parameters: (x)
Draws a horizontal line to specified relative position.
vertTo
Parameters: (y)
Draws a vertical line to specified position.
vert
Parameters: (y)
Draws a vertical line to specified relative position.
quadTo
Parameters: (x, y)
Draws quadratic Bézier curve.
quad
Parameters: (x, y)
Draws quadratic Bézier curve. Relative coordinates.
cubicTo
Parameters: (x, y)
Draws cubic Bézier curve.
cubic
Parameters: (x, y)
Draws cubic Bézier curve. Relative coordinates.
scubicTo
scubic
arcSmallCCWTo
arcSmallCCW
arcSmallCWTo
arcSmallCW
arcLargeCCWTo
arcLargeCCW
arcLargeCWTo
arcLargeCW
close
setColor
Parameters: (r, g, b)
Parameters: (r, g, b, a)
Sets the color of the drawn path
setColorFill
Parameters: (r, g, b)
Parameters: (r, g, b, a)
Calling this will make the path get filled in the specified color. For example if you draw a 'V' and fill it, the fill area will be a triangle inside the 'V'.
setStrokeLineWidth
Parameters: (width)
The width of the path.
setStrokeLineCap
Parameters: (type)
Caps the path. Type can be "butt", "round" or "square".
setStrokeDashArray
Parameters: (pattern)
Make dashed path. Pattern is a vector of alternating dash and gap lengths. ? horizontal, or misunderstood the vector ?
Example: my_path.setStrokeDashArray([10, 20, 10, 20, 10]);
setData
setDataGeo
addSegment
Map
Inherits from Element.
See: Canvas Maps and Canvas Map API
Image
Inherits from Element.
See: Canvas Image