Board index FlightGear Development Canvas

cmdarg() and CanvasWidget musings

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.

cmdarg() and CanvasWidget musings

Postby Hooray » Sat May 25, 2013 1:49 am

Traditionally, we've been using cmdarg() in dialogs to get a handle to the "private" property tree of the XML file, so that it can be procedurally modified before the dialog is instantiated - that's pretty useful, because the XML isn't otherwise accessible.

Now, CanvasWidget sections on our old dialogs use the cmdarg() API to get a handle to their canvas texture in the tree - which makes it a little difficult to access the surrounding XML file. Specifically, I am thinking in terms of reading in stuff from the PropertyList in order to get sane defaults for various widgets, e.g. see: ... xml#line42

Code: Select all
tab1.addEventListener("wheel", func(e) {
   if (e.deltaY == 1)
      pos_y = math.min(0, pos_y + 10);
      pos_y = math.max(-200, pos_y - 10); # FIXME: should not use hard coded widget height!!
   root.setTranslation(0, pos_y);
   scroll.setTranslation(0, -pos_y);   

Ideally, we'd be able to access the widget tags specified at the top (or the surrounding/included defaults) - i.e. pref-height, pref-width etc to customize certain variables for each canvaswidget instance, because these can be individually overridden in the top-level dialog file: ... xml#line72
Code: Select all
<canvas include="gui/widgets/loglist.xml"> <!-- see $FG_ROOT/Docs/README.gui for details -->

But currently, the canvas only passes "cprops" and not "props" to NasalSys:handleCommand(): ... cxx#line90

Code: Select all
SGPropertyNode *load = nasal->getNode("load");
  if( load )
    const char *s = load->getStringValue();
    nas->handleCommand( module.c_str(), file.c_str(), s, cprops );

Obviously, that makes it a little difficult to parameterize PUI canvases through custom, widget-specific, XML tags - a method which I am currently using to get rid of hardcoded PUI widgets:

There are other options obviously, but I find that pretty elegant and simple enough to implement with very little specialized code, while most code could be shared among re-implemented widgets. Given that I would not necessarily need to the private tree to be mutable, I was thinking of simply copying it to the cprops tree...

@TheTom: Any thoughts, what would you suggest ?
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: 11437
Joined: Tue Mar 25, 2008 8:40 am

Return to Canvas

Who is online

Users browsing this forum: No registered users and 2 guests