Howto:Adding a canvas to a GUI dialog

From FlightGear wiki
Revision as of 18:30, 23 May 2013 by Hooray (talk | contribs) (http://flightgear.org/forums/viewtopic.php?f=18&t=19976&p=184027#p184027)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

You can just open an existing dialog from $FG_ROOT/gui/dialogs, and copy a simple dialog like the exit/about dialog, and customize it according to your needs - i.e. by naming it "fgplot.xml", remove any stuff that you don't need, then add a new canvas widget to the dialog, like this:

<canvas>
               <name>fgplot</name>
               <valign>fill</valign>
               <halign>fill</halign>
               <stretch>true</stretch>
               <pref-width>600</pref-width>
               <pref-height>400</pref-height>
<nasal>      
<!-- this is the Nasal/canvas section where you can run your own Nasal code -->
<load><![CDATA[

# you can add your canvas code here
var my_canvas = canvas.get( cmdarg() );
print("Hello world from the embedded canvas section!\n");

]]>
</load>
</nasal>
</canvas>

You can then use Nasal to animate your canvas and draw graphics etc.