Canvas MFD framework: Difference between revisions

Jump to navigation Jump to search
Added documentation of the current MFD_generic framework
(Added documentation of the current MFD_generic framework)
Line 18: Line 18:


{{Template:Canvas Navigation}}
{{Template:Canvas Navigation}}
== Introduction ==
There is a simple implementation of the basic support for an MFD (or MPCD, or PFD), or any device that is basically a set of pages with buttons around the outside to select the page that is displayed.
This works with a SVG file that defines the menu label locations and has a group for each page. The framework manages the menu hierarchy and displays labels corresponding to the buttons.
This is based around the http://wiki.flightgear.org/McDonnell_Douglas_F-15_Eagle#MPCD
[[File:f-15-cockpit-mpcd-armament.jpg|300px|MCPD Armament Top Level Menu]]
== Implementation example ==
This uses a 3d rectangle called "MPCDImage". If there is likely to be more than one instance of an MFD then all of this logic should be wrapped up inside a class
<syntaxhighlight lang="nasal">
# F-15 Canvas MPCD (Multi-Purpose-Colour-Display)
# ---------------------------
# MPCD has many pages; the classes here support multiple pages, menu
# operation and the update loop.
var MPCDcanvas= canvas.new({
                          "name": "F-15 MPCD",
                          "size": [1024,1024],
                          "view": [740,680],                     
                          "mipmapping": 1   
                          });                         
                         
MPCDcanvas.addPlacement({"node": "MPCDImage"});
MPCDcanvas.setColorBackground(0.003921,0.1764,0, 0);
# Create a group for the parsed elements
var MPCDsvg = MPCDcanvas.createGroup();
# Parse an SVG file and add the parsed elements to the given group
canvas.parsesvg(MPCDsvg, "Nasal/MPCD/MPCD_0_0.svg");
#
# translation may be required to get the image in the right place on the canvas
#MPCDsvg.setTranslation (270.0, 197.0);
</syntaxhighlight>
=== Sample page ===
A typical MFD will have many pages, each page will have its update method called when it is on display, and the ondisplay method when it goes on display, the offdisplay method when it is about to be replaced by another page.
This is a simple page that has a clock display.
<syntaxhighlight lang="nasal">
var p1_1 = MPCD.addPage("Aircraft Menu", "p1_1");
p1_1.update = func
{
    var sec = getprop("instrumentation/clock/indicated-sec");
    p1_1.time.setText(getprop("sim/time/gmt-string")~"Z");
    var cdt = getprop("sim/time/gmt");
    if (cdt != nil)
        p1_1.date.setText(substr(cdt,5,2)~"/"~substr(cdt,8,2)~"/"~substr(cdt,2,2)~"Z");
};
p1_1.addMenuItem(0, "ARMT", p1_2);
p1_1.addMenuItem(1, "BIT", p1_2);
p1_1.addMenuItem(2, "SIT", pjitds_1);
p1_1.addMenuItem(3, "WPN", p1_2);
p1_1.addMenuItem(4, "DTM", p1_2);
p1_1.date = MPCDsvg.getElementById("p1_1_date");
p1_1.time = MPCDsvg.getElementById("p1_1_time");
</syntaxhighlight>
=== Supporting logic ===
<syntaxhighlight lang="nasal">
MPCD.selectPage(p1_1);
#
# called from the aircraft main loop, or via a maketimer() call
var updateMPCD = func ()
    if(mpcd_mode)
        MPCD.update();
}
</syntaxhighlight>


== Background ==
== Background ==
308

edits

Navigation menu