]> git.mxchange.org Git - flightgear.git/blob - src/GUI/apt_dlg.cxx
Fixes to remove dependencies on depricated plib code (that just happened to
[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/sg_path.hxx>
16
17 #include <Include/general.hxx>
18
19 #include <GL/glut.h>
20 #include <GL/gl.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 <Scenery/tilemgr.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     SGPath 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         SG_LOG( SG_GENERAL, SG_INFO,
76                 "Attempting to set starting position from airport code "
77                 << AptId );
78
79         if ( airports.search( AptId, &a ) )
80             {
81                 AptId = a.id.c_str();  /// NHV fix wrong case crash
82                 fgSetString("/sim/startup/airport-id",  AptId.c_str() );
83                 // fgSetDouble("/position/altitude-ft", -9999.0 );
84                 // fgSetPosFromAirportID( AptId );
85                 fgSetPosFromAirportIDandHdg( AptId, 
86                                              cur_fdm_state->get_Psi() *
87                                              SGD_RADIANS_TO_DEGREES);
88                 BusyCursor(0);
89                 fgReInitSubsystems();
90                 if ( global_tile_mgr.init() ) {
91                     // Load the local scenery data
92                     global_tile_mgr.update( 
93                                            cur_fdm_state->get_Longitude()
94                                            * SGD_RADIANS_TO_DEGREES,
95                                            cur_fdm_state->get_Latitude()
96                                            * SGD_RADIANS_TO_DEGREES );
97                 } else {
98                     SG_LOG( SG_GENERAL, SG_ALERT, 
99                             "Error in Tile Manager initialization!" );
100                     exit(-1);
101                 }
102                 BusyCursor(1);
103             } else {
104                 AptId  += " not in database.";
105                 mkDialog(AptId.c_str());
106             }
107     }
108     if(!freeze)
109         globals->set_freeze( false );
110 }
111
112
113 void AptDialog_Reset(puObject *)
114 {
115     //  strncpy( NewAirportId, fgGetString("/sim/startup/airport-id").c_str(), 16 );
116     sprintf( NewAirportId, "%s", fgGetString("/sim/startup/airport-id").c_str() );
117     AptDialogInput->setValue ( NewAirportId );
118     AptDialogInput->setCursor( 0 ) ;
119 }
120
121 void NewAirport(puObject *cb)
122 {
123     //  strncpy( NewAirportId, fgGetString("/sim/startup/airport-id").c_str(), 16 );
124     sprintf( NewAirportId, "%s", fgGetString("/sim/startup/airport-id").c_str() );
125     //  cout << "NewAirport " << NewAirportId << endl;
126     AptDialogInput->setValue( NewAirportId );
127
128     FG_PUSH_PUI_DIALOG( AptDialog );
129 }
130
131 void NewAirportInit(void)
132 {
133     sprintf( NewAirportId, "%s", fgGetString("/sim/startup/airport-id").c_str() );
134     int len = 150
135         - puGetDefaultLabelFont().getStringWidth( NewAirportLabel ) / 2;
136
137     AptDialog = new puDialogBox (150, 50);
138     {
139         AptDialogFrame   = new puFrame           (0,0,350, 150);
140         AptDialogMessage = new puText            (len, 110);
141         AptDialogMessage ->    setLabel          (NewAirportLabel);
142
143         AptDialogInput   = new puInput           (50, 70, 300, 100);
144         AptDialogInput   ->    setValue          (NewAirportId);
145         AptDialogInput   ->    acceptInput();
146
147         AptDialogOkButton     =  new puOneShot   (50, 10, 110, 50);
148         AptDialogOkButton     ->     setLegend   (gui_msg_OK);
149         AptDialogOkButton     ->     setCallback (AptDialog_OK);
150         AptDialogOkButton     ->     makeReturnDefault(TRUE);
151
152         AptDialogCancelButton =  new puOneShot   (140, 10, 210, 50);
153         AptDialogCancelButton ->     setLegend   (gui_msg_CANCEL);
154         AptDialogCancelButton ->     setCallback (AptDialog_Cancel);
155
156         AptDialogResetButton  =  new puOneShot   (240, 10, 300, 50);
157         AptDialogResetButton  ->     setLegend   (gui_msg_RESET);
158         AptDialogResetButton  ->     setCallback (AptDialog_Reset);
159     }
160     cout << "NewAirportInit " << NewAirportId << endl;
161     FG_FINALIZE_PUI_DIALOG( AptDialog );
162 }