20,741
edits
(→Status) |
(→Status) |
||
Line 28: | Line 28: | ||
(note this bypasses Nasal/svg.nas and the XML parser entirely, and runs inside a background thread handled by OSG, and it only takes a few ms to load/display) | (note this bypasses Nasal/svg.nas and the XML parser entirely, and runs inside a background thread handled by OSG, and it only takes a few ms to load/display) | ||
<syntaxhighlight lang="nasal"> | |||
var (width, height) = (512, 512); | |||
# Create a standalone Canvas(not attached to any GUI dialog / aircraft etc) | |||
var myCanvas = canvas.new({ | |||
"name": "Canvas.Image SVG Test", | |||
# The name is optional but allow | |||
for easier identification "size": [width, height], | |||
# Size of the underlying texture(should be a power of 2, required)[Resolution] | |||
"view": [width, height], | |||
# Virtual resolution(Defines the coordinate system of the canvas[Dimensions] # which will be stretched the size of the texture, required) | |||
"mipmapping": 1 # Enable mipmapping(optional) | |||
}); | |||
# set background color | |||
myCanvas.set("background", canvas.style.getColor("bg_color")); | |||
# creating the top - level / root group which will contain all other elements / group | |||
var root = myCanvas.createGroup(); | |||
var window = canvas.Window.new([width, height], "dialog"); | |||
window.setCanvas(myCanvas); | |||
# path is relative to $FG_ROOT(base package) | |||
var path = "Aircraft/Instruments-3d/FG1000/MFDPages/PFDInstruments.svg"; | |||
# create an image child | |||
for the texture | |||
var child = root.createChild("image") | |||
.setFile(path) | |||
.setSize(512, 512); | |||
</syntaxhighlight> | |||
[[File: Svg-via-canvas-image.png|Native SVG handling via [[Canvas Image]] and the OSG SVG plugin (via librsvg)]] | [[File: Svg-via-canvas-image.png|Native SVG handling via [[Canvas Image]] and the OSG SVG plugin (via librsvg)]] |