Canvas Nasal API: Difference between revisions

From FlightGear wiki
Jump to navigation Jump to search
(List of 2.10 Nasal Canvas methods (what I wish I had when I made my HUD))
 
(Filled in what I could about the Text element)
Line 153: Line 153:
It uses same coordinate format as [http://www.w3.org/TR/CSS21/visufx.html#clipping Clipping]
It uses same coordinate format as [http://www.w3.org/TR/CSS21/visufx.html#clipping Clipping]


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


''key = "font"''
''key = "font"''
Line 159: Line 159:
Sets the default font.
Sets the default font.


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


''key = "stroke"''
''key = "stroke"''
Line 215: Line 215:


=== setText ===
=== setText ===
'''Parameters:''' (text)
Sets the text to be displayed.
=== setAlignment ===
=== 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 ===
=== 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 ===
=== setFont ===
'''Parameters:''' (fontName)
Sets the font to be used. See $FG_DATA/Fonts for list of fonts.
=== setDrawMode ===
=== 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 ===
=== setPadding ===
?
=== setMaxWidth ===
=== setMaxWidth ===
?
=== setColor ===
=== setColor ===
'''Parameters:''' (r, g, b)
'''Parameters:''' (r, g, b, a)
Sets the color the text should be drawn in.
=== setColorFill ===
=== setColorFill ===
'''Parameters:''' (r, g, b)
'''Parameters:''' (r, g, b, a)
Sets the color the text background should be drawn in.
== Path ==
== Path ==
Inherits from element.
Inherits from element.

Revision as of 00:01, 26 February 2013

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

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.

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