20,741
edits
(Created page with "{{Canvas Navigation}} {{WIP}} == Background == == Debugging Canvas code == == Profiling Canvas code == == Optimizing Canvas code == == Useful C++ changes ==") |
mNo edit summary |
||
| Line 6: | Line 6: | ||
== Debugging Canvas code == | == Debugging Canvas code == | ||
The following snippet is taken from [[Canvas Snippets]] | |||
<syntaxhighlight lang="nasal"> | |||
# create a new window, dimensions are 320 x 160, using the dialog decoration (i.e. titlebar) | |||
var window = canvas.Window.new([320,160],"dialog"); | |||
# adding a canvas to the new window and setting up background colors/transparency | |||
var myCanvas = window.createCanvas().set("background", canvas.style.getColor("bg_color")); | |||
# Using specific css colors would also be possible: | |||
# myCanvas.set("background", "#ffaac0"); | |||
# creating the top-level/root group which will contain all other elements/group | |||
var root = myCanvas.createGroup(); | |||
</syntaxhighlight> | |||
=== Inspecting a Canvas Group === | |||
To inspect the structure of the <code>root</code> group, all you need to do is using <code>debug.dump</code>: | |||
<syntaxhighlight lang="nasal"> | |||
debug.dump(root); | |||
</syntaxhighlight> | |||
to write the structure of the property sub-tree to a file, you can use <code>io.write_properties()</code> like this: | |||
<syntaxhighlight lang="nasal"> | |||
var filename = getprop('/sim/fg-hime')~'CanvasRootGroup.xml'; | |||
io.write_properties(filename, root); | |||
</syntaxhighlight> | |||
=== Inspecting a whole Canvas === | |||
Equally, you can inspect the structure of the whole canvas by using something like this: | |||
<syntaxhighlight lang="nasal"> | |||
debug.dump( myCanvas.getPath() ); | |||
</syntaxhighlight> | |||
to write the structure of the whole Canvas sub-tree to a file, you can use <code>io.write_properties()</code> like this: | |||
<syntaxhighlight lang="nasal"> | |||
var filename = getprop('/sim/fg-hime')~'WholeCanvas.xml'; | |||
io.write_properties(filename, myCanvas); | |||
</syntaxhighlight> | |||
== Profiling Canvas code == | == Profiling Canvas code == | ||
== Optimizing Canvas code == | == Optimizing Canvas code == | ||
== Useful C++ changes == | == Useful C++ changes == | ||