-
Notifications
You must be signed in to change notification settings - Fork 0
/
soarForm.c
10226 lines (9816 loc) · 357 KB
/
soarForm.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <PalmOS.h> // all the system toolbox headers
#include "soaring.h"
#include "soarForm.h"
#include "soarUtil.h"
#include "soarMem.h"
#include "soarNMEA.h"
#include "soarDB.h"
#include "soarWay.h"
#include "soarMap.h"
#include "soarUMap.h"
#include "soarLog.h"
#include "soarIO.h"
#include "soarConf.h"
#include "soarWind.h"
#include "soarWLst.h"
#include "soarPLst.h"
#include "soarIGC.h"
#include "soarTask.h"
#include "soarGraph.h"
#include "soarSUA.h"
#include "soarComp.h"
#include "soarCAI.h"
#include "soarMath.h"
#include "soarSTF.h"
#include "soarSHA.h"
#include "soarSHAAdd.h"
#include "soarGPSInfo.h"
#include "soarVolk.h"
#include "soarCOL.h"
#include "soarFlrm.h"
#include "soarTer.h"
#include "soarGEOMAG.h"
#include "soarRECO.h"
#include "soarEW.h"
#include "soarWind.h"
static Boolean waytoggle=false;
static Boolean polartoggle=false;
static Boolean tasktoggle=false;
static Boolean configtoggle=false;
static Boolean suatoggle=false;
static Boolean igctoggle=false;
Boolean taskpreview = false;
Boolean clearrect=false;
double MCMult = 1.0;
Int16 MCXVal = 18;
Int16 MCYVal = 35;
Int16 MCWidth = 2;
double SinkConst;
Char SinkText[4];
Boolean graphing = false;
UInt8 graphtype = 0;
Boolean wayaddinfoedit = true;
Boolean pressedgo = false;
double tskpvwdist = 0.0;
Boolean wasrefwpt = false;
Boolean wenttoedit = false;
Boolean newTaskWay = false;
Boolean emergencyland = false;
Boolean frommenuorchain = false;
Boolean goingtotaskscrn = false;
Boolean FltInfoshowMC = false;
UInt32 formopen = 0xffffffff;
Boolean taskactvpressed = false;
extern Boolean defaultrules;
extern double windinc;
extern Boolean fieldupd;
extern double logmapscale;
extern Int8 logmapscaleidx;
extern Int8 logmaporient;
extern FlightData *fltdata;
extern Int16 selectedFltindex;
extern Boolean allowgenalerttap;
extern Boolean wayselect;
extern Boolean allowExit;
extern Boolean inflight;
extern Int16 TextOff;
extern Int16 activetskway;
extern Boolean savtaskonhold;
extern Int16 taskIndex;
extern IndexedColorType indexSUA, indexSUAwarn, indexTask, indexSector, indexWaypt, indexBlack, indexWhite;
extern IndexedColorType indexSink, indexWeak, indexStrong;
extern TaskData *edittsk;
extern Boolean activetasksector;
extern TaskData *tsktoedit;
extern Boolean IsMap;
extern Boolean draw_log;
extern Boolean chgstartaltref;
extern DateTimeType curtime;
extern Int8 xfrdialog;
extern Char transfer_filename[30];
extern Int8 io_file_type;
extern Int8 io_type;
extern Boolean skipballast;
extern Boolean skipbugs;
extern UInt32 cursecs;
extern UInt32 utcsecs;
extern Int16 defaultscreen;
extern Boolean skipnewflight;
extern UInt32 nogpstime;
extern Boolean logactive;
extern EWMRData *ewmrdata;
extern Boolean recordevent;
extern UInt32 lastevent;
extern Boolean tskoffterrain;
// External variables used by new polar code
extern Int16 numOfPolars;
extern Int16 currentPolarPage;
extern PolarData *selectedPolar;
extern PolarData *inusePolar;
extern Int16 selectedPolarIndex;
extern Boolean newPolar;
// External variables used by new waypoint code
extern Int16 currentWayptPage;
extern WaypointData *selectedWaypoint;
extern WaypointData *TempWpt;
extern Int16 selectedWaypointIndex;
extern Boolean newWaypt;
extern UInt16 WayptsortType;
extern Boolean recv_data;
extern UInt32 origform;
extern UInt32 origform2;
// External variables used by new task code
extern Int16 selectedTaskWayIdx;
extern UInt16 numWaypts;
extern Int16 tskWayAddIdx;
extern Boolean addWayToTask;
extern Int16 currentTaskPage;
extern Boolean dispactive;
extern TaskData *tsk;
extern Int16 inareasector;
extern Boolean settaskreadonly;
extern Int8 settaskstats;
extern Boolean exittaskreadonly;
extern Boolean settaskshowpct;
extern Boolean draw_task;
extern double taskctrlat;
extern double taskctrlon;
extern double taskmapscale;
extern Boolean manchgwpt;
extern Int8 AATdist;
extern Boolean starttask;
extern Boolean mustActivateAsNew;
extern Int16 minnumWaypts;
extern Int8 CompCmd;
extern Boolean menuopen;
extern Boolean updatemap;
extern UInt8 glidingtoheight;
extern Boolean set_task_changed;
extern Boolean goingtomenu;
extern Boolean goingtotaskedit;
extern Boolean tasknotfinished;
extern Char timeinfo[15];
extern Boolean tgtchg;
extern Boolean taskonhold;
extern Boolean forceupdate;
extern double curmapscale;
extern double savmapscale;
extern double actualmapscale;
extern UInt8 mapmode;
// External variables for the Alert Windows
extern SUAAlertData *suaalert;
extern SUAAlertRet *suaalertret;
extern Int16 startupscreen;
extern UInt32 warning_time;
// External variables for RECO Instrument Support
extern RECOData *recodata;
// External variables used by the SUA List code
extern Int16 selectedSUAListIdx;
extern Int16 currentSUAPage;
extern SUAIndex *selectedSUA;
// External variables used by the Wind Profile code
extern Boolean profilegraph;
extern Int16 *profilescale;
extern Int16 profilebase;
extern double profilestep;
// GPS simulator (IGC replay)
extern Boolean sim_gps;
extern Int32 sim_idx;
extern UInt16 sim_rec;
extern UInt32 sim_last_time;
// Main Final Glide Screen
Boolean form_final_glide_event_handler(EventPtr event)
{
Boolean handled =false;
Char MCUnitsTxt[6];
static Char TempChar[10];
Int16 x;
RectangleType rectP;
MemHandle waypoint_hand;
MemPtr waypoint_ptr;
static Boolean pen_addinfo = false;
Coord arrowX=0, arrowY=0;
static RectangleType saverectP;
static Boolean validpendown = false;
switch (event->eType) {
case frmOpenEvent:
case frmUpdateEvent:
// HostTraceOutputTL(appErrorClass, "final_glide-OpenEvent");
HandleTask(TSKNONE);
FrmDrawForm(FrmGetActiveForm());
origform = form_final_glide;
origform2 = form_final_glide;
menuopen = false;
if (data.config.optforspd) {
frm_set_title("Final Glide - Speed");
ctl_set_label(form_final_glide_sinkbtn, " MC ");
} else {
frm_set_title("Final Glide - Distance");
ctl_set_label(form_final_glide_sinkbtn, "SINK");
}
if (data.config.showrgs) {
ctl_set_visible(form_final_glide_speedlbl, false);
ctl_set_visible(form_final_glide_rgslbl, true);
} else {
ctl_set_visible(form_final_glide_rgslbl, false);
ctl_set_visible(form_final_glide_speedlbl, true);
}
if (data.config.hwposlabel) {
field_set_value(form_final_glide_headwind, DblToStr(pround(data.input.headwind*data.input.wndconst,1),1));
} else {
field_set_value(form_final_glide_headwind, DblToStr(pround(data.input.headwind*data.input.wndconst*(-1.0),1),1));
}
field_set_value(form_final_glide_basemc, DblToStr(pround(data.input.basemc*data.input.lftconst, data.input.lftprec+1), data.input.lftprec));
switch (data.config.altreftype) {
case MSL:
WinDrawChars(data.input.alttext, 2, 136, 68);
ctl_set_label(form_final_glide_curaltbtn1, "MSL");
break;
case QFE:
WinDrawChars(data.input.alttext, 2, 136, 68);
ctl_set_label(form_final_glide_curaltbtn1, "QFE");
break;
case AGL:
WinDrawChars(data.input.alttext, 2, 136, 68);
ctl_set_label(form_final_glide_curaltbtn1, "AGL");
break;
case PALT:
// FL always in ft
WinDrawChars("ft", 2, 136, 68);
ctl_set_label(form_final_glide_curaltbtn1, "FL ");
break;
default:
break;
}
switch (data.config.alttype) {
case REQALT:
ctl_set_label(form_final_glide_altbtn, "R.ALT");
break;
case ARVALT:
ctl_set_label(form_final_glide_altbtn, "A.ALT");
break;
case DLTALT:
ctl_set_label(form_final_glide_altbtn, "D.ALT");
break;
default:
break;
}
rectP.topLeft.x = GPSX;
rectP.topLeft.y = GPSY;
rectP.extent.x = GPSXOFF+1;
rectP.extent.y = GPSYOFF;
WinEraseRectangle(&rectP, 0);
if (!recv_data || (nogpstime > 0)) {
FntSetFont(boldFont);
WinDrawInvertedChars(" NO GPS", 7, GPSX, GPSY);
FntSetFont(stdFont);
clearrect = true;
} else if (StrCompare(data.logger.gpsstat, "V") == 0) {
FntSetFont(boldFont);
WinDrawInvertedChars("NOSATS", 6, GPSX, GPSY);
FntSetFont(stdFont);
clearrect = true;
} else {
if (clearrect) {
WinEraseRectangle(&rectP, 0);
clearrect = false;
}
if (!sim_gps) {
StrCopy(TempChar, "G");
StrCat(TempChar, data.input.gpsnumsats);
field_set_value(form_final_glide_gpsstat, TempChar);
// clearrect = false;
} else {
FntSetFont(boldFont);
WinDrawInvertedChars(" SIM ", 5, GPSX, GPSY);
FntSetFont(stdFont);
}
}
switch (data.config.altunits) {
case NAUTICAL:
ctl_set_label(form_final_glide_altbtn1, " (ft)");
break;
case METRIC:
ctl_set_label(form_final_glide_altbtn1, " (m)");
break;
default:
break;
}
StrCopy(TempChar, "(");
StrCat(TempChar, data.input.spdtext);
StrCat(TempChar, ")");
WinDrawChars(TempChar, 5, 29, 24);
WinDrawChars(data.input.wndtext, 3, 136, 34-2);
WinDrawChars(data.input.lfttext, 3, 136, 52-2);
WinDrawChars(data.input.lfttext, 3, 136, 88-2);
// WinDrawChars(data.input.lfttext, 3, 136, 106);
WinDrawChars(data.input.alttext, 2, 136, 124-7);
WinDrawChars(data.input.spdtext, 3, 45, 147);
WinDrawChars(data.input.distext, 2, 145, 147);
// This takes care of the zero value
switch (data.config.lftunits) {
case STATUTE:
// fpm
MCMult = 100;
MCXVal = 8;
MCWidth = 4;
StrCopy(MCUnitsTxt, " 000");
ctl_set_label(form_final_glide_sinkbtn1,"(fpm)");
break;
case NAUTICAL:
// kts
MCMult = 1;
MCXVal = 18;
MCWidth = 2;
StrCopy(MCUnitsTxt, " 0");
ctl_set_label(form_final_glide_sinkbtn1,"(kts)");
break;
case METRIC:
// m/s
MCMult = 0.5;
MCXVal = 8;
MCWidth = 4;
StrCopy(MCUnitsTxt, " 0.0");
ctl_set_label(form_final_glide_sinkbtn1,"(m/s)");
break;
default:
break;
}
WinDrawChars(MCUnitsTxt, MCWidth, MCXVal, MCYVal);
// This takes care of the rest of the values
for(x=1;x<6;x++) {
StrCopy(MCUnitsTxt, DblToStr(x*MCMult*data.config.mcrngmult, (data.config.lftunits==METRIC?1:0)));
WinDrawChars(leftpad(MCUnitsTxt, ' ', MCWidth), MCWidth, MCXVal, MCYVal+x*12);
}
// This forces the redraw of the various values when the form is
// first drawn. Useful with using with manual distance.
data.application.changed = 1;
handled=true;
break;
case winExitEvent:
// HostTraceOutputTL(appErrorClass, "final_glide-winExitEvent-menuopen = true");
menuopen = true;
handled = false;
break;
case winEnterEvent:
// HostTraceOutputTL(appErrorClass, "final_glide-winEnterEvent");
if (event->data.winEnter.enterWindow == (WinHandle) FrmGetFirstForm ()) {
// HostTraceOutputTL(appErrorClass, "final_glide-winEnterEvent-menuopen = false");
menuopen = false;
}
handled=false;
break;
case frmCloseEvent:
// HostTraceOutputTL(appErrorClass, "final_glide-frmCloseEvent-menuopen = false");
handled=false;
break;
case ctlSelectEvent: // A control button was pressed and released.
PlayKeySound();
switch (event->data.ctlEnter.controlID) {
case form_final_glide_altbtn:
case form_final_glide_altbtn1:
switch (data.config.alttype) {
case REQALT:
ctl_set_label(form_final_glide_altbtn, "A.ALT");
data.config.alttype = ARVALT;
data.application.changed = 1;
break;
case ARVALT:
ctl_set_label(form_final_glide_altbtn, "D.ALT");
data.config.alttype = DLTALT;
data.application.changed = 1;
break;
case DLTALT:
ctl_set_label(form_final_glide_altbtn, "R.ALT");
data.config.alttype = REQALT;
data.application.changed = 1;
break;
default:
break;
}
handled = true;
break;
case form_final_glide_curaltbtn1:
switch ( data.config.altreftype ) {
case MSL:
WinDrawChars(data.input.alttext, 2, 136, 68);
ctl_set_label(form_final_glide_curaltbtn1, "AGL");
data.config.altreftype = AGL;
break;
case AGL:
WinDrawChars(data.input.alttext, 2, 136, 68);
ctl_set_label(form_final_glide_curaltbtn1, "QFE");
data.config.altreftype = QFE;
break;
case QFE:
// FL always in ft
WinDrawChars("ft ", 4, 136, 68);
ctl_set_label(form_final_glide_curaltbtn1, "FL ");
data.config.altreftype = PALT;
break;
case PALT:
WinDrawChars(data.input.alttext, 2, 136, 68);
ctl_set_label(form_final_glide_curaltbtn1, "MSL");
data.config.altreftype = MSL;
break;
default:
break;
}
data.application.changed = 1;
handled = true;
break;
case form_final_glide_hwbtn:
FrmGotoForm( form_wind_disp );
handled = true;
break;
case form_final_glide_sinkbtn:
case form_final_glide_sinkbtn1:
case form_final_glide_sinkbtn2:
if (data.config.mcrngmult==1) {
data.config.mcrngmult = 2;
} else {
data.config.mcrngmult = 1;
}
// Erase the Current MC/Sink Values on Left
rectP.topLeft.x = 0;
rectP.topLeft.y = MCYVal;
rectP.extent.x = 27;
rectP.extent.y = 110-MCYVal;
WinEraseRectangle(&rectP, 0);
// This takes care of the zero value
switch (data.config.lftunits) {
case STATUTE:
// fpm
MCMult = 100;
MCXVal = 8;
MCWidth = 4;
StrCopy(MCUnitsTxt, " 000");
ctl_set_label(form_final_glide_sinkbtn1,"(fpm)");
break;
case NAUTICAL:
// kts
MCMult = 1;
MCXVal = 18;
MCWidth = 2;
StrCopy(MCUnitsTxt, " 0");
ctl_set_label(form_final_glide_sinkbtn1,"(kts)");
break;
case METRIC:
// m/s
MCMult = 0.5;
MCXVal = 8;
MCWidth = 4;
StrCopy(MCUnitsTxt, " 0.0");
ctl_set_label(form_final_glide_sinkbtn1,"(m/s)");
break;
default:
break;
}
WinDrawChars(MCUnitsTxt, MCWidth, MCXVal, MCYVal);
// This takes care of the rest of the values
for(x=1;x<6;x++) {
StrCopy(MCUnitsTxt, DblToStr(x*MCMult*data.config.mcrngmult, (data.config.lftunits==METRIC?1:0)));
WinDrawChars(leftpad(MCUnitsTxt, ' ', MCWidth), MCWidth, MCXVal, MCYVal+x*12);
}
// This forces the redraw of the various values when the form is
// first drawn. Useful with using with manual distance.
data.application.changed = 1;
handled = true;
break;
case form_final_glide_liftbtn:
case form_final_glide_aliftbtn:
PlayKeySound();
FrmGotoForm(form_thermal_history);
handled = true;
break;
default:
break;
}
break;
case fldEnterEvent:
switch (event->data.ctlEnter.controlID) {
case form_final_glide_curalt:
PlayKeySound();
switch ( data.config.altreftype ) {
case MSL:
WinDrawChars(data.input.alttext, 2, 136, 68);
ctl_set_label(form_final_glide_curaltbtn1, "AGL");
data.config.altreftype = AGL;
break;
case AGL:
WinDrawChars(data.input.alttext, 2, 136, 68);
ctl_set_label(form_final_glide_curaltbtn1, "QFE");
data.config.altreftype = QFE;
break;
case QFE:
// FL always in ft
WinDrawChars("ft ", 4, 136, 68);
ctl_set_label(form_final_glide_curaltbtn1, "FL ");
data.config.altreftype = PALT;
break;
case PALT:
WinDrawChars(data.input.alttext, 2, 136, 68);
ctl_set_label(form_final_glide_curaltbtn1, "MSL");
data.config.altreftype = MSL;
break;
default:
break;
}
data.application.changed = 1;
handled = true;
break;
case form_final_glide_headwind:
PlayKeySound();
FrmGotoForm( form_wind_disp );
handled = true;
break;
case form_final_glide_waypt:
case form_final_glide_wayelev:
pen_addinfo = true; // required to stop exit button on add.info screen generating a pendown event
if (data.input.destination_valid) {
PlayKeySound();
wayaddinfoedit = false;
// load Waypoint into TempWpt from waypoint database
if (OpenDBQueryRecord(waypoint_db, FindWayptRecordByName(data.input.destination_name), &waypoint_hand, &waypoint_ptr)) {
MemMove(TempWpt,waypoint_ptr,sizeof(WaypointData));
MemHandleUnlock(waypoint_hand);
FrmGotoForm( form_waypt_addinfo );
}
}
handled = true;
break;
case form_final_glide_track:
case form_final_glide_gs:
PlayKeySound();
if ((inareasector > -1) && (data.config.AATmode & AAT_MTURN) && ((data.task.waypttypes[inareasector] & AREAEXIT) == 0)) {
// open manual turn in AAT question
question->type = QturnAAT;
FrmPopupForm(form_question);
} else {
select_fg_waypoint(WAYSELECT);
}
handled = true;
break;
case form_final_glide_bearing:
case form_final_glide_dis:
PlayKeySound();
taskIndex = 0;
dispactive = true;
settaskreadonly = false;
FrmGotoForm(form_set_task);
data.application.changed = 1;
handled = true;
break;
case form_final_glide_lift:
case form_final_glide_alift:
PlayKeySound();
FrmGotoForm(form_thermal_history);
handled = true;
break;
case form_final_glide_0_alt:
case form_final_glide_1_alt:
case form_final_glide_2_alt:
case form_final_glide_3_alt:
case form_final_glide_4_alt:
case form_final_glide_5_alt:
switch (data.config.alttype) {
case REQALT:
ctl_set_label(form_final_glide_altbtn, "A.ALT");
data.config.alttype = ARVALT;
data.application.changed = 1;
break;
case ARVALT:
ctl_set_label(form_final_glide_altbtn, "D.ALT");
data.config.alttype = DLTALT;
data.application.changed = 1;
break;
case DLTALT:
ctl_set_label(form_final_glide_altbtn, "R.ALT");
data.config.alttype = REQALT;
data.application.changed = 1;
break;
default:
break;
}
handled = true;
break;
case form_final_glide_basemc:
if (data.config.MCbutton == POPUP) FrmPopupForm(form_set_mc);
handled = true;
break;
default:
break;
}
case penDownEvent:
validpendown = false;
arrowX = ARROWCENTX - ARROWCENTXOFF;
arrowY = ARROWCENTY - ARROWCENTYOFF;
RctSetRectangle (&rectP, arrowX, arrowY, ARROWAREAWIDTH, ARROWAREAWIDTH);
// HostTraceOutputTL(appErrorClass, "arrowX=|%hd|", arrowX);
// HostTraceOutputTL(appErrorClass, "arrowY=|%hd|", arrowY);
if (RctPtInRectangle (event->screenX, event->screenY, &rectP)) {
WinInvertRectangle (&rectP, 0);
validpendown = true;
saverectP = rectP;
pen_addinfo = false;
handled=true;
}
break;
case penUpEvent:
// not needed on low res screen
//if (device.HiDensityScrPresent) {
// WinSetCoordinateSystem(kCoordinatesStandard);
// event->screenX = WinScaleCoord (event->screenX, true);
// event->screenY = WinScaleCoord (event->screenY, true);
// HostTraceOutputTL(appErrorClass, "screenX=|%hd|", event->screenX);
// HostTraceOutputTL(appErrorClass, "screenY=|%hd|", event->screenY);
//}
// Modified as this is a low res screen, was:-
// arrowX = SCREEN.WIDTH/2-(SCREEN.SRES*16);
// Waypoint Direction Arrow Area - Select Waypoint
if (validpendown) {
WinInvertRectangle(&saverectP, 0);
}
arrowX = ARROWCENTX - ARROWCENTXOFF;
arrowY = ARROWCENTY - ARROWCENTYOFF;
RctSetRectangle (&rectP, arrowX, arrowY, ARROWAREAWIDTH, ARROWAREAWIDTH);
// HostTraceOutputTL(appErrorClass, "arrowX=|%hd|", arrowX);
// HostTraceOutputTL(appErrorClass, "arrowY=|%hd|", arrowY);
if (RctPtInRectangle (event->screenX, event->screenY, &rectP) && (validpendown) && (!pen_addinfo)) {
PlayKeySound();
if ((data.task.numwaypts > 0) && !taskonhold) {
if (inareasector > -1) {
selectedTaskWayIdx = inareasector;
} else {
selectedTaskWayIdx = activetskway;
}
activetasksector = true;
tsktoedit = &data.task;
FrmGotoForm(form_waypoint_sector);
}
handled = true;
}
validpendown = false;
break;
default:
break;
}
return handled;
}
Boolean form_moving_map_event_handler(EventPtr event)
{
Boolean handled=false;
RectangleType rectP;
static RectangleType saverectP;
static Boolean validpendown = false;
Coord arrowX=0, arrowY=0;
static Boolean pendown = false;
FormType *pfrm = FrmGetActiveForm();
EventType newEvent;
double xfactor, yfactor, truecse, step;
static Int16 postskway = 0;
switch (event->eType) {
case frmOpenEvent:
case frmUpdateEvent:
// HostTraceOutputTL(appErrorClass, "moving_map-OpenEvent");
FrmDrawForm(pfrm);
if (draw_log) {
origform = form_final_glide;
origform2 = form_final_glide;
} else {
origform = form_moving_map;
origform2 = form_moving_map;
}
updatemap = true;
if (device.DIACapable && !draw_log) {
//----------------------------------------------------------
//Resize the form.
//----------------------------------------------------------
rectP.topLeft.x = 0;
rectP.topLeft.y = 0;
rectP.extent.x = 320;
rectP.extent.y = 480;
WinSetWindowBounds( FrmGetWindowHandle( pfrm ), &rectP );
//------------------------------------------------------
//Set this forms's constraints.
//------------------------------------------------------
WinSetConstraintsSize( FrmGetWindowHandle(pfrm), 160, 160, 240, 160, 160, 160 );
//------------------------------------------------------
//Set the form's dynamic Input Area Policy.
//------------------------------------------------------
FrmSetDIAPolicyAttr( pfrm, frmDIAPolicyCustom );
//------------------------------------------------------
//Enable the input trigger.
//------------------------------------------------------
PINSetInputTriggerState( pinInputTriggerDisabled );
//------------------------------------------------------
//If your application wanted to close the input area to
//have as much space available as possible, you would
//use the following call.
//------------------------------------------------------
PINSetInputAreaState( pinInputAreaClosed );
FrmSetObjectPosition (pfrm, (FrmGetObjectIndex(pfrm, form_moving_map_wayselbtn)), 4, 208);
FrmSetObjectPosition (pfrm, (FrmGetObjectIndex(pfrm, form_moving_map_homebtn)), 82, 208);
ctl_set_visible(form_moving_map_homebtn, true);
ctl_set_visible(form_moving_map_wayselbtn, true);
}
if (device.HiDensityScrPresent) {
WinSetCoordinateSystem(kCoordinatesStandard);
}
// set up map scale, orientation and scale
if (!menuopen && (!recv_data || draw_log || (recv_data && (StrCompare(data.logger.gpsstat, "A") != 0)))) {
if (draw_log) {
if (draw_task) {
if (taskpreview) {
// goto first waypoint
postskway = 0;
data.input.gpslatdbl = data.task.targetlats[postskway];
data.input.gpslngdbl = data.task.targetlons[postskway];
activetskway = 1;
data.input.true_track.value = data.task.bearings[activetskway];
data.input.true_track.valid = VALID;
tskpvwdist = 0.0;
data.input.curmaporient = TRACKUP;
} else {
// center on flight
data.input.gpslatdbl = taskctrlat;
data.input.gpslngdbl = taskctrlon;
curmapscale = taskmapscale;
actualmapscale = curmapscale*data.input.disconst;
data.input.curmaporient = NORTHUP;
}
} else {
getfirstloggedpoint(selectedFltindex);
data.input.curmaporient = NORTHUP;
}
updatemap = true;
} else if (FindHomeWayptInitialize()) {
updatemap = true;
}
// Calculate the GPS Variation
data.input.deviation.value = GetDeviation();
data.input.deviation.valid = VALID;
}
HandleTask(TSKNONE);
FrmDrawForm(pfrm);
handled=true;
break;
case winDisplayChangedEvent:
// HostTraceOutputTL(appErrorClass, "winDisplayChangedEvent");
if (device.HiDensityScrPresent) {
WinSetCoordinateSystem(kCoordinatesStandard);
}
if (device.DIACapable && !draw_log) {
FrmSetObjectPosition (pfrm, (FrmGetObjectIndex(pfrm, form_moving_map_wayselbtn)), 4, 208);
FrmSetObjectPosition (pfrm, (FrmGetObjectIndex(pfrm, form_moving_map_homebtn)), 82, 208);
ctl_set_visible(form_moving_map_homebtn, true);
ctl_set_visible(form_moving_map_wayselbtn, true);
}
FrmDrawForm(pfrm);
handled=true;
break;
case frmCloseEvent:
// HostTraceOutputTL(appErrorClass, "moving_map-frmCloseEvent");
if (device.HiDensityScrPresent) {
WinSetCoordinateSystem(kCoordinatesStandard);
}
if (device.DIACapable) {
PINSetInputAreaState( pinInputAreaOpen );
}
if (draw_task) {
activetskway = 0;
draw_task = false;
if (data.task.numwaypts > 0) CalcStartFinishDirs(&data.task);
}
if (draw_log) {
draw_log = false;
curmapscale = logmapscale;
data.config.mapscaleidx = logmapscaleidx;
actualmapscale = curmapscale * data.input.disconst;
data.input.curmaporient = logmaporient;
FindHomeWayptInitialize();
}
//HandleTaskAutoZoom(0.0, 0.0, true);
handled=false;
break;
case winExitEvent:
// HostTraceOutputTL(appErrorClass, "moving_map-winExitEvent");
// HostTraceOutputTL(appErrorClass, "menuopen = true");
if (device.HiDensityScrPresent) {
WinSetCoordinateSystem(kCoordinatesStandard);
}
menuopen = true;
handled = true;
break;
case winEnterEvent:
// HostTraceOutputTL(appErrorClass, "moving_map-winEnterEvent");
if (event->data.winEnter.enterWindow == (WinHandle) FrmGetFirstForm ()) {
// HostTraceOutputTL(appErrorClass, "winEnterEvent-inside");
// HostTraceOutputTL(appErrorClass, "menuopen = false");
menuopen = false;
}
handled=true;
break;
case ctlSelectEvent:
PlayKeySound();
switch (event->data.ctlEnter.controlID) {
case form_moving_map_homebtn:
// HostTraceOutputTL(appErrorClass, "homebtn pressed");
EvtEnqueueKey (findChr, 0, commandKeyMask);
// FrmGotoForm(form_final_glide);
break;
case form_moving_map_wayselbtn:
// HostTraceOutputTL(appErrorClass, "wayselbtn pressed");
// This is a sneaky way of reusing the waypoint select
// code for the CalcButton in PreProcessEvent
newEvent.eType = keyDownEvent;
newEvent.data.keyDown.chr = calcChr;
PreprocessEvent(&newEvent);
break;
case form_moving_map_backbtn:
if (draw_task) {
activetskway = 0;
FrmGotoForm(form_list_task);
} else {
FrmGotoForm(form_flt_info);
}
break;
default:
break;
}
handled=true;
break;
case penDownEvent:
pendown = true;
validpendown = false;
// HostTraceOutputTL(appErrorClass, "penDownEvent-FormID=|%hu|", FrmGetActiveFormID());
// HostTraceOutputTL(appErrorClass, "Raw screenX=|%hd|", event->screenX);
// HostTraceOutputTL(appErrorClass, "Raw screenY=|%hd|", event->screenY);
if (device.HiDensityScrPresent) {
WinSetCoordinateSystem(device.HiDensityScrPresent);
event->screenX = WinScaleCoord (event->screenX, true);
event->screenY = WinScaleCoord (event->screenY, true);
// HostTraceOutputTL(appErrorClass, "screenX=|%hd|", event->screenX);
// HostTraceOutputTL(appErrorClass, "screenY=|%hd|", event->screenY);
}
if (!draw_log) {
// goto active task by tapping top right (task leg distance)
arrowX = SCREEN.WIDTH-(SCREEN.SRES*22);
arrowY = HEIGHT_MIN;
RctSetRectangle (&rectP, arrowX, arrowY, (SCREEN.SRES*22), (SCREEN.SRES*22));
if (RctPtInRectangle (event->screenX, event->screenY, &rectP)) {
WinInvertRectangle (&rectP, 0);
validpendown = true;
saverectP = rectP;
handled=true;
}
}
// if (!draw_log) {
// select waypoint or active task options by tapping CSE: box
arrowX = WIDTH_MIN+(SCREEN.SRES*1); // 2
arrowY = SCREEN.HEIGHT-(SCREEN.SRES*22)+TextOff; //138
RctSetRectangle (&rectP, arrowX, arrowY, (SCREEN.SRES*22), (SCREEN.SRES*22));
if (RctPtInRectangle (event->screenX, event->screenY, &rectP)) {
if (!draw_log) {
WinInvertRectangle (&rectP, 0);
validpendown = true;
saverectP = rectP;
} else if (device.StyleTapPDA == STIPHONE) {
// work around for button on map screen with StyleTap
newEvent.eType = ctlSelectEvent;
newEvent.data.ctlEnter.controlID = form_moving_map_backbtn;
EvtAddEventToQueue(&newEvent);
}
handled=true;
}
// }
if (!draw_log || (draw_task && (taskIndex == 0))) {
// goto view sector by tapping top left (task bearing)
arrowX = WIDTH_MIN;
arrowY = HEIGHT_MIN;
RctSetRectangle (&rectP, arrowX, arrowY, (SCREEN.SRES*22), (SCREEN.SRES*22));
if (RctPtInRectangle (event->screenX, event->screenY, &rectP)) {
WinInvertRectangle (&rectP, 0);
validpendown = true;
saverectP = rectP;
handled=true;
}
}
if (!draw_log || (draw_task && taskpreview)) {
// Invert the Scale Selection Area
arrowX = SCREEN.WIDTH-(SCREEN.SRES*24);
arrowY = SCREEN.HEIGHT-(SCREEN.SRES*22)+TextOff;
RctSetRectangle (&rectP, arrowX, arrowY, (SCREEN.SRES*24), (SCREEN.SRES*22));
// HostTraceOutputTL(appErrorClass, "arrowX=|%hd|", arrowX);
// HostTraceOutputTL(appErrorClass, "arrowY=|%hd|", arrowY);
if (RctPtInRectangle (event->screenX, event->screenY, &rectP)) {
WinInvertRectangle (&rectP, 0);
validpendown = true;
saverectP = rectP;
handled=true;
}
}
// Invert the R/D/A.Alt Selection Area
if (data.config.btmlabels && !draw_log) {
arrowX = SCREEN.WIDTH/2-(SCREEN.SRES*15); //65
arrowY = SCREEN.HEIGHT-(SCREEN.SRES*22)+TextOff; //138
RctSetRectangle (&rectP, arrowX, arrowY, (SCREEN.SRES*35), (SCREEN.SRES*22));
// HostTraceOutputTL(appErrorClass, "arrowX=|%hd|", arrowX);
// HostTraceOutputTL(appErrorClass, "arrowY=|%hd|", arrowY);
if (RctPtInRectangle (event->screenX, event->screenY, &rectP)) {
WinInvertRectangle (&rectP, 0);
validpendown = true;
saverectP = rectP;
handled=true;
}
}
// Invert the Altitude Selection Area
if (data.config.btmlabels && !draw_log) {
arrowX = SCREEN.WIDTH-(SCREEN.SRES*55);
arrowY = SCREEN.HEIGHT-(SCREEN.SRES*22)+TextOff;
RctSetRectangle (&rectP, arrowX, arrowY, (SCREEN.SRES*30), (SCREEN.SRES*22));
// HostTraceOutputTL(appErrorClass, "arrowX=|%hd|", arrowX);
// HostTraceOutputTL(appErrorClass, "arrowY=|%hd|", arrowY);
if (RctPtInRectangle (event->screenX, event->screenY, &rectP)) {
WinInvertRectangle (&rectP, 0);
validpendown = true;
saverectP = rectP;
handled=true;
}
}
if (!menuopen && (!recv_data || draw_log || (recv_data && (StrCompare(data.logger.gpsstat, "A") != 0)))) {
// Move Left Button
arrowX = WIDTH_MIN;
arrowY = SCREEN.HEIGHT/2-(SCREEN.SRES*11);
RctSetRectangle (&rectP, arrowX, arrowY, (SCREEN.SRES*22), (SCREEN.SRES*22));
if (RctPtInRectangle (event->screenX, event->screenY, &rectP)) {
// HostTraceOutputTL(appErrorClass, "arrowX=|%hd|", arrowX);
// HostTraceOutputTL(appErrorClass, "arrowY=|%hd|", arrowY);
FntSetFont(symbolFont);
//Left
//WinDrawInvertedChars("\003", 1, arrowX, arrowY);
WinInvertRectangle (&rectP, 0);
validpendown = true;
saverectP = rectP;
FntSetFont(stdFont);
handled=true;
}