Gijs wrote in Mon Feb 25, 2013 1:43 pm:I've managed to add a SVG canvas to a XML dialog.
I have to correct myself. Altough the canvas shows up in the model and the dialog, only the dialog is updated after opening it. As long as I don't open the dialog, the model canvas updates fine, but as soon as the dialog is opened, the model stops updating. After closing the dialog, the model still refuses to update. Re-opening the dialog shows a perfectly updating canvas...
My code (removed tons of logic to color/hide lines etc., which is irrelevant for the issue):
- Code: Select all
var canvas_fuel = {
new: func(canvas_group)
{
var m = { parents: [canvas_fuel] };
var eicas = canvas_group;
canvas.parsesvg(eicas, "Aircraft/747-400/Models/Cockpit/Instruments/EICAS/fuel.svg");
text3956 = eicas.getElementById("text3956");
return m;
},
update: func()
{
text3956.setText(sprintf("%3.01f",getprop("/consumables/fuel/tank[7]/level-lbs")/1000));
settimer(func me.update(), 0);
},
};
setlistener("/nasal/canvas/loaded", func {
var my_canvas = canvas.new({
"name": "EICASFuel",
"size": [1024, 1024],
"view": [1024, 1024],
"mipmapping": 1
});
my_canvas.addPlacement({"node": "Lower-EICAS-Screen"});
var group = my_canvas.createGroup();
var canvas_fuel_eicas = canvas_fuel.new(group);
canvas_fuel_eicas.update();
}, 1);
The dialog:
- Code: Select all
<?xml version="1.0"?>
<PropertyList>
<name>eicas_dialog</name>
<layout>vbox</layout>
<draggable>true</draggable>
<resizable>true</resizable>
<group>
<layout>hbox</layout>
<text>
<label>Boeing 747-400 EICAS</label>
</text>
<empty>
<stretch>true</stretch>
</empty>
<button>
<legend/>
<key>Esc</key>
<pref-width>16</pref-width>
<pref-height>16</pref-height>
<border>2</border>
<binding>
<command>dialog-close</command>
</binding>
</button>
</group>
<hrule/>
<canvas>
<nasal>
<load>
<![CDATA[
var my_canvas = canvas.get(cmdarg());
var gui_fmc = Boeing747.canvas_fuel.new(my_canvas.createGroup());
]]>
</load>
</nasal>
<valign>fill</valign>
<halign>fill</halign>
<stretch>true</stretch>
<pref-width>400</pref-width>
<pref-height>400</pref-height>
<view n="0">1024</view>
<view n="1">1024</view>
</canvas>
</PropertyList>
----------------
I also looked at another approach, which involved this code (and no XML dialog):
- Code: Select all
var canvas_fuel = {
new: func(canvas_group)
{
var m = { parents: [canvas_fuel] };
var eicas = canvas_group;
canvas.parsesvg(eicas, "Aircraft/747-400/Models/Cockpit/Instruments/EICAS/fuel.svg");
text3956 = eicas.getElementById("text3956");
return m;
},
update: func()
{
text3956.setText(sprintf("%3.01f",getprop("/consumables/fuel/tank[7]/level-lbs")/1000));
settimer(func me.update(), 0);
},
};
setlistener("/nasal/canvas/loaded", func {
var my_canvas = canvas.new({
"name": "EICASFuel",
"size": [1024, 1024],
"view": [1024, 1024],
"mipmapping": 1
});
my_canvas.addPlacement({"node": "Lower-EICAS-Screen"});
var group = my_canvas.createGroup();
var canvas_fuel_eicas = canvas_fuel.new(group);
canvas_fuel_eicas.update();
eicas_dialog = canvas.Window.new ([640,640]);
eicas_dialog.setPosition(20,20);
eicas_dialog.setCanvas (my_canvas);
}, 1);
The funny thing here is that it does seem to be updating both the dialog and the canvas on the model, but the canvas on the dialog is only visible when a popup dialog is open (eg. when changing views). It shows up at the location of the popup, and also seems to have that size, as can be seen at the screenshot below. I experience the same with the F-20's Stores dialog that used to work fine... This is with today's Git, but I remember seeing it since at least some days ago.