| 1 |
|
| 2 |
# Search the canvas texture created by the GPSmap196 |
| 3 |
var gps196CanvasInstance = canvas.get({name: "GPSmap196-screen"}); |
| 4 |
|
| 5 |
# Create a new Canvas window (calling that the "widget") |
| 6 |
var dlg = canvas.Window.new([1024, 512], "dialog").set("title", "Garmin GPSmap196"); |
| 7 |
|
| 8 |
# A list of all button available in the SVG file of the widget |
| 9 |
# and associate the button with the property he will trigger |
| 10 |
var buttons = [ |
| 11 |
["gps196.widget.button.in", "button-in"], ["gps196.widget.button.out", "button-out"], |
| 12 |
["gps196.widget.button.dto", "button-dto"], ["gps196.widget.button.page", "button-page"], |
| 13 |
["gps196.widget.button.quit", "button-quit"], ["gps196.widget.button.nrst", "button-nrst"], |
| 14 |
["gps196.widget.button.menu", "button-menu"], ["gps196.widget.button.enter", "button-enter"], |
| 15 |
["gps196.widget.button.power", "button-power"], ["gps196.widget.rocker.up", "rocker-up"], |
| 16 |
["gps196.widget.rocker.down", "rocker-down"], ["gps196.widget.rocker.left", "rocker-left"], |
| 17 |
["gps196.widget.rocker.right", "rocker-right"] |
| 18 |
]; |
| 19 |
|
| 20 |
# Create the content of the Canvas window with a white background |
| 21 |
var gps196Widget = dlg.createCanvas().setColorBackground(1,1,1,1); |
| 22 |
|
| 23 |
# Create the main (root) group of our canvas |
| 24 |
var root = gps196Widget.createGroup(); |
| 25 |
|
| 26 |
# Load the SVG file of the widget providing all buttons |
| 27 |
canvas.parsesvg(root, "Aircraft/Instruments-3d/GPSmap196/widget/gpsmap196-widget.svg"); |
| 28 |
|
| 29 |
# An helper function who add the event listener for each button |
| 30 |
var setButtonListener = func(btn, prop) { |
| 31 |
root.getElementById(btn).addEventListener("mousedown", func(e) { setprop("instrumentation/gps196/inputs/"~prop, 1); }); |
| 32 |
root.getElementById(btn).addEventListener("mouseup", func(e) { setprop("instrumentation/gps196/inputs/"~prop, 0); }); |
| 33 |
root.getElementById(btn).set("z-index", 11); |
| 34 |
} |
| 35 |
|
| 36 |
# Run through all our buttons in order to setup the event listener |
| 37 |
for( var i=0; i<size(buttons); i=i+1){ |
| 38 |
setButtonListener(buttons[i][0], buttons[i][1]); |
| 39 |
} |
| 40 |
|
| 41 |
# Add a background image to our Canvas window |
| 42 |
var background = root.createChild("image"); |
| 43 |
background.setFile("Aircraft/Instruments-3d/GPSmap196/widget/gpsmap196-widget.png").setSize(1024,512).set("z-index",10); |
| 44 |
|
| 45 |
# Include the canvas texture in the display of the widget |
| 46 |
var canvasScreenWidget = root.createChild("image"); |
| 47 |
canvasScreenWidget.setFile(gps196CanvasInstance.getPath()).setSize(563,359).setTranslation(87,53).set("z-index", 11); |