20,741
edits
Line 234: | Line 234: | ||
| {{Caution|This is currently untested code}} | | {{Caution|This is currently untested code}} | ||
<syntaxhighlight lang="nasal" enclose="div"> | <syntaxhighlight lang="nasal" enclose="div"> | ||
## | |||
# this is the function that draws a symbol using OpenVG paths | |||
# it accepts a group to draw to and returns the rendered group | |||
# to the caller | |||
var drawVOR = func(group) { | var drawVOR = func(group) { | ||
return group.createChild("path") | return group.createChild("path") | ||
Line 243: | Line 247: | ||
.lineTo(-7.5,-12.5) | .lineTo(-7.5,-12.5) | ||
.close() | .close() | ||
.setStrokeLineWidth(line_width) | .setStrokeLineWidth(line_width) # style-able | ||
.setColor(color); | .setColor(color); # style-able | ||
}; | }; | ||
var style = { # | var style = { # styling related attributes (as per the draw* function above) | ||
line_width: 3, | line_width: 3, | ||
scale_factor: 1, | scale_factor: 1, | ||
color: [1,0,0], | |||
}; | }; | ||
var | # create a new cache entry for the styled symbol | ||
name:' | var myCachedSymbol = StyleableCacheable.new( | ||
cache: canvas.SymbolCache32x32, | name:'myVOR', draw_func: drawVOR, | ||
cache: canvas.SymbolCache32x32, # the cache to be used | |||
draw_mode: SymbolCache.DRAW_CENTERED, | draw_mode: SymbolCache.DRAW_CENTERED, | ||
relevant_keys: [ | relevant_keys: ['line_width', 'color'], # styling related attributes | ||
); | ); | ||
var target = root.createChild('group'); | |||
# look up the raster image for the symbol | |||
# render it using the passed style and adjust scaling | |||
var instanced = myCachedSymbol.render(target, style).setScale(0.3); | |||
</syntaxhighlight> | </syntaxhighlight> |