Changes

Jump to navigation Jump to search
Line 22: Line 22:     
== Development news ==
 
== Development news ==
 +
 +
=== Creating Canvas UI dialogs procedurally ===
 +
[[File:Draw-masks-via-canvas.png|thumb|FlightGear [[Draw masks]] GUI dialog procedurally created by the [[Canvas]] system.s]]
 +
 +
Most end-users will hardly be familiar with so called [[Draw masks]], however one stated goal is to add more node bits (and a GUI dialog to control them) so various categories of objects can be disabled during the update pass.
 +
 +
This will mean the direct hit of, say, AI models vs particles vs random trees can be measured.
 +
 +
Of course it won't account for resources (memory, textures) burned by such things, but would still help different people identify slowness on their setups. <ref>{{cite web
 +
  |url    =  https://sourceforge.net/p/flightgear/mailman/message/29564161/
 +
  |title  =  <nowiki> Re: [Flightgear-devel] Rendering passes question </nowiki>
 +
  |author =  <nowiki> James Turner </nowiki>
 +
  |date  =  Jul 19th, 2012
 +
  |added  =  Jul 19th, 2012
 +
  |script_version = 0.40
 +
  }}</ref>
 +
 +
The following snippet of Nasal/Canvas code (mostly based on code taken from [[Canvas Snippets]] demonstrates how easily such a dialog can be procedurally created using the Canvas system:
 +
 +
<syntaxhighlight lang="nasal">
 +
var (width,height) = (320,160);
 +
var title = 'Draw Masks';
 +
 +
var window = canvas.Window.new([width,height],"dialog").set('title',title);
 +
 +
window.del = func()
 +
{
 +
  print("Cleaning up window:",title,"\n");
 +
  call(canvas.Window.del, [], me);
 +
};
 +
 +
# adding a canvas to the new window and setting up background colors/transparency
 +
var myCanvas = window.createCanvas().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 drawMasks = props.globals.getNode("/sim/rendering/draw-mask").getChildren();
 +
 +
# create a new layout
 +
window.Layout = canvas.VBoxLayout.new();
 +
 +
# assign it to the Canvas
 +
myCanvas.setLayout(window.Layout);
 +
 +
 +
foreach(var mask; drawMasks) {
 +
 +
(func() {
 +
var m = mask;
 +
 +
# print("Found mask:", mask.getName(), "=", mask.getValue() );
 +
 +
var checkbox = canvas.gui.widgets.CheckBox.new(root, canvas.style, {wordWrap: 0})
 +
.setText( "render "  ~ m.getName() )
 +
.listen("toggled", func(e) {
 +
      setprop(m.getPath(), e.detail.checked);
 +
                            })
 +
.setChecked(  m.getValue() );
 +
window.Layout.addItem(checkbox);
 +
 +
}) ();
 +
 +
}
 +
</syntaxhighlight>
    
== In the hangar ==
 
== In the hangar ==

Navigation menu