Board index FlightGear Development Canvas

testing my SVGs in Flightgear

Canvas is FlightGear's new fully scriptable 2D drawing system that will allow you to easily create new instruments, HUDs and even GUI dialogs and custom GUI widgets, without having to write C++ code and without having to rebuild FlightGear.

testing my SVGs in Flightgear

Postby pommesschranke » Sun Feb 23, 2014 3:17 pm

thank you, Hooray
for the code to test our svg files:

Code: Select all
    var CanvasApplication = {
     # constructor
     new: func(x=300,y=200,file="/gui/dialogs/images/ndb_symbol.svg") {

      var m = { parents: [CanvasApplication] };
      m.dlg =[x,y],"dialog");
      # you can change the background color here
      var color = {WHITE:[1,1,1,1],BLACK:[0,0,0,1]};
      m.canvas = m.dlg.createCanvas().setColorBackground(color.BLACK);
      m.root = m.canvas.createGroup();
      return m;
    update: func() {
    var svg_symbols = me.root.createChild("group", "navaid");
    canvas.parsesvg(svg_symbols, me.file);
    svg_symbols.setScale(0.35); # resize the image so that it can be  fully seen (30%)
    #symbol_navaid.setGeoPosition(, navaid.lon);

    init: func() {
     var filename = "/Aircraft/Instruments/gyro.xml";
     }, # init
    }; # end of CanvasApplication
    var SVGMapPreview= {
     new: func(x,y,svg) {
      var m =, y:y, file:svg);
      return m;
    var preview=, y:400, svg:"Nasal/canvas/map/boeingND.svg");
    print("SVGPreviewer loaded ...!");

I'm a Nasal newbie and just learned from experimenting that the parameters to
are all optional, so in this example If I leave away the file:svg then ndb_symbol.svg gets displayed.

this is also very helpful: ... up_Profile

FlightGear starts quicker and uses only 30% CPU when it runs compared to usual 98%
Posts: 1105
Joined: Sat Apr 27, 2013 7:58 pm
Location: EDLM & LJCE
Callsign: d-laser
IRC name: laserman
Version: git
OS: Linux Lubuntu 18.04

Re: testing my SVGs in Flightgear

Postby Hooray » Sun Feb 23, 2014 3:31 pm

No problem, you are welcome - thank you very much for your work, and for helping Michat with those SVG files for the new Map dialog, it's really appreciated - and you've both done a great job with TQPanel, it's really looking very good!

Regarding Nasal, whenever a function's signature uses the equal sign, the parameters have default values:
Code: Select all
new: func(x=300,y=200,file="/gui/dialogs/images/ndb_symbol.svg")

This means: add a new function, named new with three parameters: x,y and file - and assign a default value to each of these, so that they're all optional.
Full explanation at: ... _arguments

Normally, we could change the code to automatically show a file-selection dialog so that you can select the SVG file, but IIRC there's a bug preventing multiple instances of the dialog from working correctly, and I don't think that's been solved yet (admittedly, also not a priority for me...)
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Posts: 11968
Joined: Tue Mar 25, 2008 8:40 am

Return to Canvas

Who is online

Users browsing this forum: No registered users and 1 guest