]> git.mxchange.org Git - flightgear.git/blob - src/GUI/apt_dlg.cxx
SG_ namespace
[flightgear.git] / src / GUI / apt_dlg.cxx
1 #ifdef HAVE_CONFIG_H
2 #  include <config.h>
3 #endif
4
5 #include <simgear/compiler.h>
6
7 #ifdef HAVE_WINDOWS_H
8 #  include <windows.h>
9 #endif
10
11 #include <stdlib.h>
12
13 #include <simgear/constants.h>
14 #include <simgear/debug/logstream.hxx>
15 #include <simgear/misc/fgpath.hxx>
16
17 #include <Include/general.hxx>
18
19 #include <GL/glut.h>
20 #include <simgear/xgl/xgl.h>
21
22 #include <Airports/simple.hxx>
23 #include <FDM/flight.hxx>
24 #include <Main/fg_init.hxx>
25 #include <Main/fg_props.hxx>
26 #include <Main/globals.hxx>
27 //#include <Time/fg_time.hxx>
28
29 #include "gui.h"
30 #include "gui_local.hxx"
31
32 /// The beginnings of teleportation :-)
33 //  Needs cleaning up but works
34 //  These statics should disapear when this is a class
35 static puDialogBox     *AptDialog = 0;
36 static puFrame         *AptDialogFrame = 0;
37 static puText          *AptDialogMessage = 0;
38 static puInput         *AptDialogInput = 0;
39
40 static char NewAirportId[16];
41 static char NewAirportLabel[] = "Enter New Airport ID"; 
42
43 static puOneShot       *AptDialogOkButton = 0;
44 static puOneShot       *AptDialogCancelButton = 0;
45 static puOneShot       *AptDialogResetButton = 0;
46
47 void AptDialog_Cancel(puObject *)
48 {
49         FG_POP_PUI_DIALOG( AptDialog );
50 }
51
52 void AptDialog_OK (puObject *)
53 {
54         FGPath path( globals->get_fg_root() );
55         path.append( "Airports" );
56         path.append( "simple.mk4" );
57         FGAirports airports( path.c_str() );
58
59         FGAirport a;
60
61         int freeze = globals->get_freeze();
62         if(!freeze)
63                 globals->set_freeze( true );
64
65         char *s;
66         AptDialogInput->getValue(&s);
67         string AptId(s);
68
69         cout << "AptDialog_OK " << AptId << " " << AptId.length() << endl;
70
71         AptDialog_Cancel( NULL );
72
73         if ( AptId.length() ) {
74                 // set initial position from airport id
75                 FG_LOG( FG_GENERAL, FG_INFO,
76                                 "Attempting to set starting position from airport code "
77                                 << AptId );
78
79                 if ( airports.search( AptId, &a ) )
80                 {
81                         fgSetString("/sim/startup/airport-id",  AptId.c_str() );
82                         // fgSetDouble("/position/altitude", -9999.0 );
83                         // fgSetPosFromAirportID( AptId );
84                         fgSetPosFromAirportIDandHdg( AptId, 
85                                                      cur_fdm_state->get_Psi() *
86                                                      SGD_RADIANS_TO_DEGREES);
87                         BusyCursor(0);
88                         fgReInitSubsystems();
89                         BusyCursor(1);
90                 } else {
91                         AptId  += " not in database.";
92                         mkDialog(AptId.c_str());
93                 }
94         }
95         if(!freeze)
96                 globals->set_freeze( false );
97 }
98
99 void AptDialog_Reset(puObject *)
100 {
101         //  strncpy( NewAirportId, fgGetString("/sim/startup/airport-id").c_str(), 16 );
102         sprintf( NewAirportId, "%s", fgGetString("/sim/startup/airport-id").c_str() );
103         AptDialogInput->setValue ( NewAirportId );
104         AptDialogInput->setCursor( 0 ) ;
105 }
106
107 void NewAirport(puObject *cb)
108 {
109         //  strncpy( NewAirportId, fgGetString("/sim/startup/airport-id").c_str(), 16 );
110         sprintf( NewAirportId, "%s", fgGetString("/sim/startup/airport-id").c_str() );
111 //      cout << "NewAirport " << NewAirportId << endl;
112         AptDialogInput->setValue( NewAirportId );
113
114         FG_PUSH_PUI_DIALOG( AptDialog );
115 }
116
117 void NewAirportInit(void)
118 {
119         sprintf( NewAirportId, "%s", fgGetString("/sim/startup/airport-id").c_str() );
120         int len = 150 - puGetStringWidth( puGetDefaultLabelFont(),
121                                                                           NewAirportLabel ) / 2;
122
123         AptDialog = new puDialogBox (150, 50);
124         {
125                 AptDialogFrame   = new puFrame           (0,0,350, 150);
126                 AptDialogMessage = new puText            (len, 110);
127                 AptDialogMessage ->    setLabel          (NewAirportLabel);
128
129                 AptDialogInput   = new puInput           (50, 70, 300, 100);
130                 AptDialogInput   ->    setValue          (NewAirportId);
131                 AptDialogInput   ->    acceptInput();
132
133                 AptDialogOkButton     =  new puOneShot   (50, 10, 110, 50);
134                 AptDialogOkButton     ->     setLegend   (gui_msg_OK);
135                 AptDialogOkButton     ->     setCallback (AptDialog_OK);
136                 AptDialogOkButton     ->     makeReturnDefault(TRUE);
137
138                 AptDialogCancelButton =  new puOneShot   (140, 10, 210, 50);
139                 AptDialogCancelButton ->     setLegend   (gui_msg_CANCEL);
140                 AptDialogCancelButton ->     setCallback (AptDialog_Cancel);
141
142                 AptDialogResetButton  =  new puOneShot   (240, 10, 300, 50);
143                 AptDialogResetButton  ->     setLegend   (gui_msg_RESET);
144                 AptDialogResetButton  ->     setCallback (AptDialog_Reset);
145         }
146         cout << "NewAirportInit " << NewAirportId << endl;
147         FG_FINALIZE_PUI_DIALOG( AptDialog );
148 }