1 // kln89_page.cxx - base class for the "pages" that
\r
2 // are used in the KLN89 GPS unit simulation.
\r
4 // Written by David Luff, started 2005.
\r
6 // Copyright (C) 2005 - David C Luff - david.luff@nottingham.ac.uk
\r
8 // This program is free software; you can redistribute it and/or
\r
9 // modify it under the terms of the GNU General Public License as
\r
10 // published by the Free Software Foundation; either version 2 of the
\r
11 // License, or (at your option) any later version.
\r
13 // This program is distributed in the hope that it will be useful, but
\r
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
\r
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
\r
16 // General Public License for more details.
\r
18 // You should have received a copy of the GNU General Public License
\r
19 // along with this program; if not, write to the Free Software
\r
20 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
\r
24 #include "kln89_page.hxx"
\r
25 #include <Main/fg_props.hxx>
\r
27 KLN89Page::KLN89Page(KLN89* parent)
\r
29 _kln89 = (KLN89*)parent;
\r
34 KLN89Page::~KLN89Page() {
\r
37 void KLN89Page::Update(double dt) {
\r
38 bool crsr = (_kln89->_mode == KLN89_MODE_CRSR ? true : false);
\r
39 bool nav1 = (_name == "NAV" && _subPage == 0);
\r
40 bool nav4 = (_name == "NAV" && _subPage == 3);
\r
41 // The extra level of check for the ACT page is necessary since
\r
42 // ACT is implemented by using the other waypoint pages as
\r
44 bool act = (_kln89->_activePage->GetName() == "ACT");
\r
45 _kln89->DrawDivider();
\r
47 if(!nav4) _kln89->DrawText("*CRSR*", 1, 0, 0);
\r
48 if(_uLinePos == 0) _kln89->Underline(1, 3, 1, 3);
\r
52 _kln89->DrawText("ACT", 1, 0, 0);
\r
54 _kln89->DrawText(_name, 1, 0, 0);
\r
56 if(_name == "DIR") {
\r
57 // Don't draw a subpage number
\r
58 } else if(_name == "USR" || _name == "FPL") {
\r
60 _kln89->DrawText(GPSitoa(_subPage), 1, 4, 0);
\r
63 _kln89->DrawText(GPSitoa(_subPage+1), 1, 4, 0);
\r
67 if(crsr && _uLinePos == 0 && _kln89->_blink) {
\r
70 if(_kln89->_obsMode) {
\r
71 _kln89->DrawText(GPSitoa(_kln89->_obsHeading), 1, 3, 1);
\r
73 _kln89->DrawText("Leg", 1, 3, 1);
\r
76 _kln89->DrawText((_kln89->GetDistVelUnitsSI() ? "km" : "nm"), 1, 4, 3);
\r
77 GPSWaypoint* awp = _parent->GetActiveWaypoint();
\r
78 if(_kln89->_navFlagged) {
\r
79 _kln89->DrawText("--.-", 1, 0 ,3);
\r
80 // Only nav1 still gets speed drawn if nav is flagged - not ACT
\r
81 if(!nav1) _kln89->DrawText("------", 1, 0, 2);
\r
84 float f = _parent->GetDistToActiveWaypoint() * (_kln89->GetDistVelUnitsSI() ? 0.001 : SG_METER_TO_NM);
\r
85 snprintf(buf, 5, (f >= 100.0 ? "%4.0f" : "%4.1f"), f);
\r
87 _kln89->DrawText(s, 1, 4 - s.size(), 3, true);
\r
88 // Draw active waypoint ID, except for
\r
89 // nav1, act, and any waypoint pages matching
\r
90 // active waypoint that need speed drawn instead.
\r
91 if(act || nav1 || (awp && awp->id == _id)) {
\r
92 _kln89->DrawSpeed(_kln89->_groundSpeed_kts, 1, 5, 2);
\r
94 if(!(_kln89->_waypointAlert && _kln89->_blink)) _kln89->DrawText(awp->id, 1, 0, 2);
\r
99 _kln89->DrawText(" No ", 1, 0, 1, false, 99);
\r
100 _kln89->DrawText(" Nrst ", 1, 0, 0, false, 99);
\r
103 if(_scratchpadMsg) {
\r
104 _kln89->DrawText(_scratchpadLine1, 1, 0, 1, false, 99);
\r
105 _kln89->DrawText(_scratchpadLine2, 1, 0, 0, false, 99);
\r
106 _scratchpadTimer += dt;
\r
107 if(_scratchpadTimer > 4.0) {
\r
108 _scratchpadMsg = false;
\r
109 _scratchpadTimer = 0.0;
\r
114 void KLN89Page::ShowScratchpadMessage(const string& line1, const string& line2) {
\r
115 _scratchpadLine1 = line1;
\r
116 _scratchpadLine2 = line2;
\r
117 _scratchpadTimer = 0.0;
\r
118 _scratchpadMsg = true;
\r
121 void KLN89Page::Knob1Left1() {
\r
122 if(_kln89->_mode == KLN89_MODE_CRSR) {
\r
123 if(_uLinePos > 0) _uLinePos--;
\r
127 void KLN89Page::Knob1Right1() {
\r
128 if(_kln89->_mode == KLN89_MODE_CRSR) {
\r
129 if(_uLinePos < _maxULinePos) _uLinePos++;
\r
133 void KLN89Page::Knob2Left1() {
\r
134 if(_kln89->_mode != KLN89_MODE_CRSR && !fgGetBool("/instrumentation/kln89/scan-pull")) {
\r
135 GPSPage::Knob2Left1();
\r
137 if(_uLinePos == 0 && _kln89->_obsMode) {
\r
138 _kln89->_obsHeading--;
\r
139 if(_kln89->_obsHeading < 0) {
\r
140 _kln89->_obsHeading += 360;
\r
142 _kln89->SetOBSFromWaypoint();
\r
147 void KLN89Page::Knob2Right1() {
\r
148 if(_kln89->_mode != KLN89_MODE_CRSR && !fgGetBool("/instrumentation/kln89/scan-pull")) {
\r
149 GPSPage::Knob2Right1();
\r
151 if(_uLinePos == 0 && _kln89->_obsMode) {
\r
152 _kln89->_obsHeading++;
\r
153 if(_kln89->_obsHeading > 359) {
\r
154 _kln89->_obsHeading -= 360;
\r
156 _kln89->SetOBSFromWaypoint();
\r
161 void KLN89Page::CrsrPressed() {
\r
162 // Stick some sensible defaults in
\r
163 if(_kln89->_obsMode) {
\r
171 void KLN89Page::EntPressed() {}
\r
172 void KLN89Page::ClrPressed() {}
\r
173 void KLN89Page::DtoPressed() {}
\r
174 void KLN89Page::NrstPressed() {}
\r
175 void KLN89Page::AltPressed() {}
\r
177 void KLN89Page::OBSPressed() {
\r
178 if(_kln89->_obsMode) {
\r
179 // If ORS2 and not slaved to gps
\r
182 // Don't leave the cursor on in the leg position.
\r
183 if(_uLinePos == 0) {
\r
184 _kln89->_mode = KLN89_MODE_DISP;
\r
189 void KLN89Page::MsgPressed() {}
\r
191 void KLN89Page::CleanUp() {
\r
192 _kln89->_cleanUpPage = -1;
\r
195 void KLN89Page::LooseFocus() {
\r
196 _entInvert = false;
\r
199 void KLN89Page::SetId(const string& s) {
\r
203 const string& KLN89Page::GetId() {
\r