| 1 |
# Copyright 2018 Stuart Buchanan |
| 2 |
# This file is part of FlightGear. |
| 3 |
# |
| 4 |
# FlightGear is free software: you can redistribute it and/or modify |
| 5 |
# it under the terms of the GNU General Public License as published by |
| 6 |
# the Free Software Foundation, either version 2 of the License, or |
| 7 |
# (at your option) any later version. |
| 8 |
# |
| 9 |
# FlightGear is distributed in the hope that it will be useful, |
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
# GNU General Public License for more details. |
| 13 |
# |
| 14 |
# You should have received a copy of the GNU General Public License |
| 15 |
# along with FlightGear. If not, see <http://www.gnu.org/licenses/>. |
| 16 |
# |
| 17 |
|
| 18 |
var GUI = |
| 19 |
{ |
| 20 |
# List of UI hotspots and their mapping to Emesary bridge notifications |
| 21 |
WHEEL_HOT_SPOTS : [ |
| 22 |
{ notification: fg1000.FASCIA.NAV_VOL, shift: 0, top_left: [65, 45], bottom_right: [112, 90] }, |
| 23 |
{ notification: fg1000.FASCIA.NAV_INNER, shift: 0, top_left: [45, 168], bottom_right: [135, 250] }, |
| 24 |
{ notification: fg1000.FASCIA.NAV_OUTER, shift: 1, top_left: [45, 168], bottom_right: [135, 250] }, |
| 25 |
{ notification: fg1000.FASCIA.HEADING, shift: 0, top_left: [45, 338], bottom_right: [135, 411] }, |
| 26 |
{ notification: fg1000.FASCIA.ALT_INNER, shift: 0, top_left: [45, 800], bottom_right: [135, 880] }, |
| 27 |
{ notification: fg1000.FASCIA.ALT_OUTER, shift: 1, top_left: [45, 800], bottom_right: [135, 880] }, |
| 28 |
|
| 29 |
|
| 30 |
{ notification: fg1000.FASCIA.COM_VOL, shift: 0, top_left: [1290, 45], bottom_right: [1340, 90] }, |
| 31 |
{ notification: fg1000.FASCIA.COM_INNER, shift: 0, top_left: [1275, 170], bottom_right: [1355, 245] }, |
| 32 |
{ notification: fg1000.FASCIA.COM_OUTER, shift: 1, top_left: [1275, 170], bottom_right: [1355, 245] }, |
| 33 |
|
| 34 |
{ notification: fg1000.FASCIA.CRS, shift: 0, top_left: [1275, 331], bottom_right: [1355, 410] }, |
| 35 |
{ notification: fg1000.FASCIA.BARO, shift: 1, top_left: [1275, 331], bottom_right: [1355, 410] }, |
| 36 |
|
| 37 |
{ notification: fg1000.FASCIA.RANGE, shift: 0, top_left: [1275, 497], bottom_right: [1355, 554] }, |
| 38 |
|
| 39 |
{ notification: fg1000.FASCIA.FMS_INNER, shift: 0, top_left: [1275, 800], bottom_right: [1355, 880] }, |
| 40 |
{ notification: fg1000.FASCIA.FMS_OUTER, shift: 1, top_left: [1275, 800], bottom_right: [1355, 880] }, |
| 41 |
], |
| 42 |
|
| 43 |
CLICK_HOT_SPOTS : [ |
| 44 |
{ notification: fg1000.FASCIA.NAV_ID, shift: 0, value: 1, top_left: [65, 47], bottom_right: [112, 90] }, |
| 45 |
{ notification: fg1000.FASCIA.NAV_FREQ_TRANSFER, shift: 0, value: 1, top_left: [100, 102], bottom_right: [150, 138] }, |
| 46 |
{ notification: fg1000.FASCIA.NAV_TOGGLE, shift: 0, value: 1, top_left: [45, 168], bottom_right: [135, 250] }, |
| 47 |
{ notification: fg1000.FASCIA.HEADING_PRESS, shift: 0, value: 1, top_left: [45, 338], bottom_right: [135, 411] }, |
| 48 |
|
| 49 |
{ notification: fg1000.FASCIA.COM_VOL_TOGGLE, shift: 0, value: 1, top_left: [1290, 45], bottom_right: [1340, 90] }, |
| 50 |
{ notification: fg1000.FASCIA.COM_FREQ_TRANSFER, shift: 0, value: 1, top_left: [1250, 100], bottom_right: [1300, 140] }, |
| 51 |
{ notification: fg1000.FASCIA.COM_FREQ_TRANSFER_HOLD, shift: 1, value: 1, top_left: [1250, 100], bottom_right: [1300, 140] }, |
| 52 |
{ notification: fg1000.FASCIA.COM_TOGGLE, shift: 0, value: 1, top_left: [1275, 170], bottom_right: [1355, 245] }, |
| 53 |
|
| 54 |
{ notification: fg1000.FASCIA.CRS_CENTER, shift: 0, value: 1, top_left: [1275, 331], bottom_right: [1355, 410] }, |
| 55 |
|
| 56 |
{ notification: fg1000.FASCIA.JOYSTICK_PRESS, shift: 0, value: 1, top_left: [1295, 500], bottom_right: [1345, 550] }, |
| 57 |
|
| 58 |
{ notification: fg1000.FASCIA.JOYSTICK_HORIZONTAL, shift: 0, value: -1, top_left: [1255, 500], bottom_right: [1285, 550] }, |
| 59 |
{ notification: fg1000.FASCIA.JOYSTICK_HORIZONTAL, shift: 0, value: 1, top_left: [1345, 500], bottom_right: [1380, 550] }, |
| 60 |
|
| 61 |
{ notification: fg1000.FASCIA.JOYSTICK_VERTICAL, shift: 0, value: -1, top_left: [1295, 465], bottom_right: [1345, 500] }, |
| 62 |
{ notification: fg1000.FASCIA.JOYSTICK_VERTICAL, shift: 0, value: 1, top_left: [1295, 550], bottom_right: [1345, 585] }, |
| 63 |
|
| 64 |
{ notification: fg1000.FASCIA.DTO, shift: 0, value: 1, top_left: [1255, 620], bottom_right: [1305, 660] }, |
| 65 |
{ notification: fg1000.FASCIA.FPL, shift: 0, value: 1, top_left: [1255, 670], bottom_right: [1305, 710] }, |
| 66 |
{ notification: fg1000.FASCIA.CLR, shift: 0, value: 1, top_left: [1255, 720], bottom_right: [1305, 760] }, |
| 67 |
{ notification: fg1000.FASCIA.CLR_HOLD, shift: 1, value: 1, top_left: [1255, 720], bottom_right: [1305, 760] }, |
| 68 |
|
| 69 |
{ notification: fg1000.FASCIA.MENU, shift: 0, value: 1, top_left: [1325, 620], bottom_right: [1380, 660] }, |
| 70 |
{ notification: fg1000.FASCIA.PROC, shift: 0, value: 1, top_left: [1325, 670], bottom_right: [1380, 710] }, |
| 71 |
{ notification: fg1000.FASCIA.ENT, shift: 0, value: 1, top_left: [1325, 720], bottom_right: [1380, 760] }, |
| 72 |
|
| 73 |
{ notification: fg1000.FASCIA.FMS_CRSR, shift: 0, value: 1, top_left: [1275, 800], bottom_right: [1355, 880] }, |
| 74 |
], |
| 75 |
|
| 76 |
SOFTKEY_HOTSPOTS : [ |
| 77 |
{ Id: 1, top_left: [205, 830], bottom_right: [265, 875] }, |
| 78 |
{ Id: 2, top_left: [290, 830], bottom_right: [350, 875] }, |
| 79 |
{ Id: 3, top_left: [375, 830], bottom_right: [435, 875] }, |
| 80 |
{ Id: 4, top_left: [460, 830], bottom_right: [520, 875] }, |
| 81 |
{ Id: 5, top_left: [545, 830], bottom_right: [605, 875] }, |
| 82 |
{ Id: 6, top_left: [630, 830], bottom_right: [690, 875] }, |
| 83 |
{ Id: 7, top_left: [715, 830], bottom_right: [775, 875] }, |
| 84 |
{ Id: 8, top_left: [800, 830], bottom_right: [860, 875] }, |
| 85 |
{ Id: 9, top_left: [885, 830], bottom_right: [945, 875] }, |
| 86 |
{ Id: 10, top_left: [970, 830], bottom_right: [1030, 875] }, |
| 87 |
{ Id: 11, top_left: [1055, 830], bottom_right: [1115, 875] }, |
| 88 |
{ Id: 12, top_left: [1145, 830], bottom_right: [1200, 875] }, |
| 89 |
], |
| 90 |
|
| 91 |
new : func(mfd, mfd_canvas, device_id, scale = 1.0) |
| 92 |
{ |
| 93 |
var obj = { |
| 94 |
parents : [ GUI ], |
| 95 |
mfd : mfd, |
| 96 |
eisPublisher : nil, |
| 97 |
navcomPublisher : nil, |
| 98 |
navcomUpdater : nil, |
| 99 |
navdataInterface : nil, |
| 100 |
width : 1407, |
| 101 |
height : 918, |
| 102 |
scale : scale, |
| 103 |
device_id : device_id, |
| 104 |
}; |
| 105 |
|
| 106 |
obj.window = canvas.Window.new([obj.scale*obj.width,obj.scale*obj.height],"dialog"); |
| 107 |
obj.window.set('title',"FG1000 Device " ~ device_id); |
| 108 |
obj.window.set('resize',1); |
| 109 |
obj.window.lockAspectRatio(1); |
| 110 |
|
| 111 |
var inset = canvas.new({ |
| 112 |
"name" : "Inset", |
| 113 |
"size" : [1407, 918], |
| 114 |
"view" : [obj.width, obj.height], |
| 115 |
"mipmapping": 0, |
| 116 |
}); |
| 117 |
|
| 118 |
var insetgroup = inset.createGroup(); |
| 119 |
|
| 120 |
# Project the canvas onto the dialog |
| 121 |
var mfd_child = insetgroup.createChild("image") |
| 122 |
.setFile(mfd_canvas.getPath()) |
| 123 |
.set("z-index", 150) |
| 124 |
.setTranslation(186,45) |
| 125 |
.setSize(1024, 768); |
| 126 |
|
| 127 |
# Create the surround fascia, which is just a PNG image; |
| 128 |
var child = insetgroup.createChild("image") |
| 129 |
.setFile("Aircraft/Instruments-3d/FG1000/Dialogs/fascia.png") |
| 130 |
.set("z-index", 100) |
| 131 |
.setSize(obj.width, obj.height); |
| 132 |
|
| 133 |
obj.window.setCanvas(inset); |
| 134 |
|
| 135 |
# Add a event listener for the mouse wheel, which is used for turning the |
| 136 |
# knobs. |
| 137 |
inset.addEventListener("wheel", func(e) |
| 138 |
{ |
| 139 |
foreach(var hotspot; GUI.WHEEL_HOT_SPOTS) { |
| 140 |
if ((e.localX > hotspot.top_left[0]) and (e.localX < hotspot.bottom_right[0]) and |
| 141 |
(e.localY > hotspot.top_left[1]) and (e.localY < hotspot.bottom_right[1]) and |
| 142 |
(e.shiftKey == hotspot.shift)) |
| 143 |
{ |
| 144 |
# We've found the hotspot, so send a notification to deal with it |
| 145 |
var args = {'device': obj.device_id, |
| 146 |
'notification': hotspot.notification, |
| 147 |
'offset' : e.deltaY}; |
| 148 |
|
| 149 |
fgcommand("FG1000HardKeyPushed", props.Node.new(args)); |
| 150 |
break; |
| 151 |
} |
| 152 |
} |
| 153 |
}); |
| 154 |
|
| 155 |
# Add a event listener for the mouse click, which is used for buttons |
| 156 |
inset.addEventListener("click", func(e) |
| 157 |
{ |
| 158 |
foreach(var hotspot; GUI.CLICK_HOT_SPOTS) { |
| 159 |
if ((e.localX > hotspot.top_left[0]) and (e.localX < hotspot.bottom_right[0]) and |
| 160 |
(e.localY > hotspot.top_left[1]) and (e.localY < hotspot.bottom_right[1]) and |
| 161 |
(e.shiftKey == hotspot.shift)) |
| 162 |
{ |
| 163 |
# We've found the hotspot, so send a notification to deal with it |
| 164 |
var args = {'device': obj.device_id, |
| 165 |
'notification': hotspot.notification, |
| 166 |
'offset' : hotspot.value}; |
| 167 |
|
| 168 |
fgcommand("FG1000HardKeyPushed", props.Node.new(args)); |
| 169 |
break; |
| 170 |
} |
| 171 |
} |
| 172 |
|
| 173 |
foreach(var hotspot; GUI.SOFTKEY_HOTSPOTS) { |
| 174 |
if ((e.localX > hotspot.top_left[0]) and (e.localX < hotspot.bottom_right[0]) and |
| 175 |
(e.localY > hotspot.top_left[1]) and (e.localY < hotspot.bottom_right[1])) |
| 176 |
{ |
| 177 |
# We've found the hotspot, so send a notification to deal with it |
| 178 |
var args = {'device': obj.device_id, |
| 179 |
'offset' : hotspot.Id}; |
| 180 |
|
| 181 |
fgcommand("FG1000SoftKeyPushed", props.Node.new(args)); |
| 182 |
break; |
| 183 |
} |
| 184 |
} |
| 185 |
}); |
| 186 |
|
| 187 |
return obj; |
| 188 |
}, |
| 189 |
}; |