]> git.mxchange.org Git - flightgear.git/blob - src/Main/keyboard.cxx
Continued FGViewer cleanups. FGViewer is now a base class so that we can
[flightgear.git] / src / Main / keyboard.cxx
1 // keyboard.cxx -- handle GLUT keyboard events
2 //
3 // Written by Curtis Olson, started May 1997.
4 //
5 // Copyright (C) 1997 - 1999  Curtis L. Olson  - curt@flightgear.org
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 //
21 // $Id$
22
23
24 #ifdef HAVE_CONFIG_H
25 #  include <config.h>
26 #endif
27
28 #ifdef HAVE_WINDOWS_H
29 #  include <windows.h>                     
30 #endif
31
32 #include <simgear/compiler.h>
33
34 #include <GL/glut.h>
35 #include <simgear/xgl/xgl.h>
36
37 #if defined(FX) && defined(XMESA)
38 #include <GL/xmesa.h>
39 #endif
40
41 #include <stdio.h>
42 #include <stdlib.h>
43
44 #include STL_FSTREAM
45
46 #include <plib/pu.h>            // plib include
47
48 #include <simgear/constants.h>
49 #include <simgear/debug/logstream.hxx>
50 #include <simgear/misc/fgpath.hxx>
51
52 #include <Aircraft/aircraft.hxx>
53 #include <Autopilot/auto_gui.hxx>
54 #include <Autopilot/newauto.hxx>
55 #include <Cockpit/hud.hxx>
56 #include <Cockpit/panel.hxx>
57 #include <Cockpit/panel_io.hxx>
58 #include <GUI/gui.h>
59 #include <Scenery/tilemgr.hxx>
60 #include <Objects/matlib.hxx>
61 #include <Time/light.hxx>
62 #include <Time/tmp.hxx>
63
64 #ifndef FG_OLD_WEATHER
65 #  include <WeatherCM/FGLocalWeatherDatabase.h>
66 #else
67 #  include <Weather/weather.hxx>
68 #endif
69
70 #include "bfi.hxx"
71 #include "globals.hxx"
72 #include "keyboard.hxx"
73 #include "save.hxx"
74
75                                 // From main.cxx
76 extern void fgReshape( int width, int height );
77
78
79 // Handle keyboard events
80 void GLUTkey(unsigned char k, int x, int y) {
81     FGInterface *f;
82     FGViewerRPH *v;
83     float fov, tmp;
84     static bool winding_ccw = true;
85     int speed;
86
87     f = current_aircraft.fdm_state;
88     v = globals->get_current_view();
89
90     FG_LOG( FG_INPUT, FG_DEBUG, "Key hit = " << k );
91     if ( puKeyboard(k, PU_DOWN) ) {
92         return;
93     }
94
95     if ( GLUT_ACTIVE_ALT && glutGetModifiers() ) {
96         FG_LOG( FG_INPUT, FG_DEBUG, " SHIFTED" );
97         switch (k) {
98         case 1: // Ctrl-A key
99             current_autopilot->set_AltitudeMode( 
100                   FGAutopilot::FG_ALTITUDE_LOCK );
101             current_autopilot->set_AltitudeEnabled(
102                   ! current_autopilot->get_AltitudeEnabled()
103                 );
104             return;
105         case 7: // Ctrl-G key
106             current_autopilot->set_AltitudeMode( 
107                   FGAutopilot::FG_ALTITUDE_GS1 );
108             current_autopilot->set_AltitudeEnabled(
109                   ! current_autopilot->get_AltitudeEnabled()
110                 );
111             return;
112         case 8: // Ctrl-H key
113             current_autopilot->set_HeadingMode( 
114                   FGAutopilot::FG_HEADING_LOCK );
115             current_autopilot->set_HeadingEnabled(
116                   ! current_autopilot->get_HeadingEnabled()
117                 );
118             return;
119         case 14: // Ctrl-N key
120             current_autopilot->set_HeadingMode( 
121                   FGAutopilot::FG_HEADING_NAV1 );
122             current_autopilot->set_HeadingEnabled(
123                   ! current_autopilot->get_HeadingEnabled()
124                 );
125             return;
126         case 18: // Ctrl-R key
127             // temporary
128             winding_ccw = !winding_ccw;
129             if ( winding_ccw ) {
130                 glFrontFace ( GL_CCW );
131             } else {
132                 glFrontFace ( GL_CW );
133             }
134             return;
135         case 19: // Ctrl-S key
136             current_autopilot->set_AutoThrottleEnabled(
137                   ! current_autopilot->get_AutoThrottleEnabled()
138                 );
139             return;
140         case 20: // Ctrl-T key
141             current_autopilot->set_AltitudeMode( 
142                   FGAutopilot::FG_ALTITUDE_TERRAIN );
143             current_autopilot->set_AltitudeEnabled(
144                   ! current_autopilot->get_AltitudeEnabled()
145                 );
146             return;
147         case 21: // Ctrl-U key
148             // add 1000' of emergency altitude.  Possibly good for 
149             // unflipping yourself :-)
150             {
151                 double alt = cur_fdm_state->get_Altitude() + 1000;
152                 fgFDMForceAltitude( globals->get_options()->get_flight_model(), 
153                                     alt * FEET_TO_METER );
154             }
155             return;
156         case 49: // numeric keypad 1
157             v->set_goal_view_offset( FG_PI * 0.75 );
158             if ( globals->get_options()->get_view_mode() ==
159                  FGOptions::FG_VIEW_FOLLOW )
160             {
161                 globals->get_current_view()->set_pilot_offset(-25.0, 25.0, 1.0);
162                 v->set_view_offset( FG_PI * 0.75 );
163             }
164             return;
165         case 50: // numeric keypad 2
166             v->set_goal_view_offset( FG_PI );
167             if ( globals->get_options()->get_view_mode() ==
168                  FGOptions::FG_VIEW_FOLLOW )
169             {
170                 globals->get_current_view()->set_pilot_offset(-25.0, 0.0, 1.0);
171                 v->set_view_offset( FG_PI );
172             }
173             return;
174         case 51: // numeric keypad 3
175             v->set_goal_view_offset( FG_PI * 1.25 );
176             if ( globals->get_options()->get_view_mode() ==
177                  FGOptions::FG_VIEW_FOLLOW )
178             {
179                 globals->get_current_view()->set_pilot_offset(-25.0, -25.0, 1.0);
180                 v->set_view_offset( FG_PI * 1.25 );
181             }
182             return;
183         case 52: // numeric keypad 4
184             v->set_goal_view_offset( FG_PI * 0.50 );
185             if ( globals->get_options()->get_view_mode() ==
186                  FGOptions::FG_VIEW_FOLLOW )
187             {
188                 globals->get_current_view()->set_pilot_offset(0.0, 25.0, 1.0);
189                 v->set_view_offset( FG_PI * 0.50 );
190             }
191             return;
192         case 54: // numeric keypad 6
193             v->set_goal_view_offset( FG_PI * 1.50 );
194             if ( globals->get_options()->get_view_mode() ==
195                  FGOptions::FG_VIEW_FOLLOW )
196             {
197                 globals->get_current_view()->set_pilot_offset(0.0, -25.0, 1.0);
198                 v->set_view_offset( FG_PI * 1.50 );
199             }
200             return;
201         case 55: // numeric keypad 7
202             v->set_goal_view_offset( FG_PI * 0.25 );
203             if ( globals->get_options()->get_view_mode() ==
204                  FGOptions::FG_VIEW_FOLLOW )
205             {
206                 globals->get_current_view()->set_pilot_offset(25.0, 25.0, 1.0);
207                 v->set_view_offset( FG_PI * 0.25 );
208             }
209             return;
210         case 56: // numeric keypad 8
211             v->set_goal_view_offset( 0.00 );
212             if ( globals->get_options()->get_view_mode() ==
213                  FGOptions::FG_VIEW_FOLLOW )
214             {
215                 globals->get_current_view()->set_pilot_offset(25.0, 0.0, 1.0);
216                 v->set_view_offset( 0.00 );
217             }
218             return;
219         case 57: // numeric keypad 9
220             v->set_goal_view_offset( FG_PI * 1.75 );
221             if ( globals->get_options()->get_view_mode() ==
222                  FGOptions::FG_VIEW_FOLLOW )
223             {
224                 globals->get_current_view()->set_pilot_offset(25.0, -25.0, 1.0);
225                 v->set_view_offset( FG_PI * 1.75 );
226             }
227             return;
228         case 65: // A key
229             speed = globals->get_options()->get_speed_up();
230             speed--;
231             if ( speed < 1 ) {
232                 speed = 1;
233             }
234             globals->get_options()->set_speed_up( speed );
235             return;
236         case 72: // H key
237             // status = globals->get_options()->get_hud_status();
238             // globals->get_options()->set_hud_status(!status);
239             HUD_brightkey( true );
240             return;
241         case 73: // I key
242             // Minimal Hud
243             fgHUDInit2(&current_aircraft);
244             return;
245         case 77: // M key
246             globals->inc_warp( -60 );
247             fgUpdateSkyAndLightingParams();
248             return;
249         case 80: // P key
250             globals->get_options()->toggle_panel();
251             break;
252         case 84: // T key
253             globals->inc_warp_delta( -30 );
254             fgUpdateSkyAndLightingParams();
255             return;
256         case 87: // W key
257 #if defined(FX) && !defined(WIN32)
258             global_fullscreen = ( !global_fullscreen );
259 #  if defined(XMESA_FX_FULLSCREEN) && defined(XMESA_FX_WINDOW)
260             XMesaSetFXmode( global_fullscreen ? 
261                             XMESA_FX_FULLSCREEN : XMESA_FX_WINDOW );
262 #  endif
263 #endif
264             return;
265         case 88: // X key
266             fov = globals->get_options()->get_fov();
267             fov *= 1.05;
268             if ( fov > FG_FOV_MAX ) {
269                 fov = FG_FOV_MAX;
270             }
271             globals->get_options()->set_fov(fov);
272             // v->force_update_fov_math();
273             return;
274         case 90: // Z key
275 #ifndef FG_OLD_WEATHER
276             tmp = WeatherDatabase->getWeatherVisibility();
277             tmp /= 1.10;
278             WeatherDatabase->setWeatherVisibility( tmp );
279 #else
280             tmp = current_weather.get_visibility();   // in meters
281             tmp /= 1.10;
282             current_weather.set_visibility( tmp );
283 #endif
284             return;
285         }
286     } else {
287         FG_LOG( FG_INPUT, FG_DEBUG, "" );
288         switch (k) {
289         case 50: // numeric keypad 2
290             if ( current_autopilot->get_AltitudeEnabled() ) {
291                 current_autopilot->AltitudeAdjust( 100 );
292             } else {
293                 controls.move_elevator(-0.05);
294             }
295             return;
296         case 56: // numeric keypad 8
297             if ( current_autopilot->get_AltitudeEnabled() ) {
298                 current_autopilot->AltitudeAdjust( -100 );
299             } else {
300                 controls.move_elevator(0.05);
301             }
302             return;
303         case 49: // numeric keypad 1
304             controls.move_elevator_trim(-0.001);
305             return;
306         case 55: // numeric keypad 7
307             controls.move_elevator_trim(0.001);
308             return;
309         case 52: // numeric keypad 4
310             controls.move_aileron(-0.05);
311             return;
312         case 54: // numeric keypad 6
313             controls.move_aileron(0.05);
314             return;
315         case 48: // numeric keypad Ins
316             if ( current_autopilot->get_HeadingEnabled() ) {
317                 current_autopilot->HeadingAdjust( -1 );
318             } else {
319                 controls.move_rudder(-0.05);
320             }
321             return;
322         case 13: // numeric keypad Enter
323             if ( current_autopilot->get_HeadingEnabled() ) {
324                 current_autopilot->HeadingAdjust( 1 );
325             } else {
326                 controls.move_rudder(0.05);
327             }
328             return;
329         case 53: // numeric keypad 5
330             controls.set_aileron(0.0);
331             controls.set_elevator(0.0);
332             controls.set_rudder(0.0);
333             return;
334         case 57: // numeric keypad 9 (Pg Up)
335             if ( current_autopilot->get_AutoThrottleEnabled() ) {
336                 current_autopilot->AutoThrottleAdjust( 5 );
337             } else {
338                 controls.move_throttle( FGControls::ALL_ENGINES, 0.01 );
339             }
340             return;
341         case 51: // numeric keypad 3 (Pg Dn)
342             if ( current_autopilot->get_AutoThrottleEnabled() ) {
343                 current_autopilot->AutoThrottleAdjust( -5 );
344             } else {
345                 controls.move_throttle( FGControls::ALL_ENGINES, -0.01 );
346             }
347             return;
348         case 91: // [ key
349             controls.move_flaps(-0.34);
350             FG_LOG( FG_INPUT, FG_INFO,
351                     "Set flaps to " << controls.get_flaps() );
352             return;
353         case 93: // ] key
354             controls.move_flaps(0.34);
355             FG_LOG( FG_INPUT, FG_INFO,
356                     "Set flaps to " << controls.get_flaps() );
357             return;
358         case 97: // a key
359             speed = globals->get_options()->get_speed_up();
360             speed++;
361             globals->get_options()->set_speed_up( speed );
362             return;
363         case 98: // b key
364             int b_ret;
365             double b_set;
366             b_ret = int( controls.get_brake( 0 ) );
367             b_set = double(!b_ret);
368             controls.set_brake( FGControls::ALL_WHEELS, b_set);
369             return;
370         case 44: // , key
371             if (controls.get_brake(0) > 0.0) {
372                 controls.set_brake(0, 0.0);
373             } else {
374                 controls.set_brake(0, 1.0);
375             }
376             return;
377         case 46: // . key
378             if (controls.get_brake(1) > 0.0) {
379                 controls.set_brake(1, 0.0);
380             } else {
381                 controls.set_brake(1, 1.0);
382             }
383             return;
384         case 104: // h key
385             HUD_masterswitch( true );
386             return;
387         case 105: // i key
388             fgHUDInit(&current_aircraft);  // normal HUD
389             return;
390         case 109: // m key
391             globals->inc_warp( 60 );
392             fgUpdateSkyAndLightingParams();
393             return;
394         case 112: // p key
395             globals->set_freeze( ! globals->get_freeze() );
396
397             {
398                 FGBucket p( f->get_Longitude() * RAD_TO_DEG,
399                             f->get_Latitude() * RAD_TO_DEG );
400                 FGPath tile_path( globals->get_options()->get_fg_root() );
401                 tile_path.append( "Scenery" );
402                 tile_path.append( p.gen_base_path() );
403                 tile_path.append( p.gen_index_str() );
404
405                 // printf position and attitude information
406                 FG_LOG( FG_INPUT, FG_INFO,
407                         "Lon = " << f->get_Longitude() * RAD_TO_DEG
408                         << "  Lat = " << f->get_Latitude() * RAD_TO_DEG
409                         << "  Altitude = " << f->get_Altitude() * FEET_TO_METER
410                         );
411                 FG_LOG( FG_INPUT, FG_INFO,
412                         "Heading = " << f->get_Psi() * RAD_TO_DEG 
413                         << "  Roll = " << f->get_Phi() * RAD_TO_DEG
414                         << "  Pitch = " << f->get_Theta() * RAD_TO_DEG );
415                 FG_LOG( FG_INPUT, FG_INFO, tile_path.c_str());
416             }
417             return;
418         case 116: // t key
419             globals->inc_warp_delta( 30 );
420             fgUpdateSkyAndLightingParams();
421             return;
422         case 118: // v key
423 //          globals->get_options()->cycle_view_mode();
424             if ( globals->get_options()->get_view_mode() ==
425                  FGOptions::FG_VIEW_FOLLOW )
426             {
427                 globals->get_options()->set_view_mode(FGOptions::FG_VIEW_PILOT);
428                 v->set_goal_view_offset( 0.0 );
429                 v->set_view_offset( 0.0 );
430             } else if ( globals->get_options()->get_view_mode() ==
431                         FGOptions::FG_VIEW_PILOT )
432             {
433                 globals->get_options()->set_view_mode( FGOptions::FG_VIEW_FOLLOW );
434                 v->set_goal_view_offset( FG_PI * 1.75 );
435                 v->set_view_offset( FG_PI * 1.75 );
436                 globals->get_current_view()->set_pilot_offset(25.0, -25.0, 1.0);
437             }
438             fgReshape( globals->get_options()->get_xsize(),
439                        globals->get_options()->get_ysize() );
440             return;
441         case 120: // x key
442             fov = globals->get_options()->get_fov();
443             fov /= 1.05;
444             if ( fov < FG_FOV_MIN ) {
445                 fov = FG_FOV_MIN;
446             }
447             globals->get_options()->set_fov(fov);
448             // v->force_update_fov_math();
449             return;
450         case 122: // z key
451 #ifndef FG_OLD_WEATHER
452             tmp = WeatherDatabase->getWeatherVisibility();
453             tmp *= 1.10;
454             WeatherDatabase->setWeatherVisibility( tmp );
455 #else
456             tmp = current_weather.get_visibility();   // in meters
457             tmp *= 1.10;
458             current_weather.set_visibility( tmp );
459 #endif
460             return;
461         case 27: // ESC
462             // if( fg_DebugOutput ) {
463             //   fclose( fg_DebugOutput );
464             // }
465             FG_LOG( FG_INPUT, FG_ALERT, 
466                     "Program exit requested." );
467             ConfirmExitDialog();
468             return;
469         }
470     }
471 }
472
473
474 // Handle "special" keyboard events
475 void GLUTspecialkey(int k, int x, int y) {
476     FGViewerRPH *v;
477
478     v = globals->get_current_view();
479
480     FG_LOG( FG_INPUT, FG_DEBUG, "Special key hit = " << k );
481
482     if ( puKeyboard(k + PU_KEY_GLUT_SPECIAL_OFFSET, PU_DOWN) ) {
483         return;
484     }
485
486     if ( GLUT_ACTIVE_SHIFT && glutGetModifiers() ) {
487         FG_LOG( FG_INPUT, FG_DEBUG, " SHIFTED" );
488         switch (k) {
489         case GLUT_KEY_F1: {
490             ifstream input("fgfs.sav");
491             if (input.good() && fgLoadFlight(input)) {
492                 input.close();
493                 FG_LOG(FG_INPUT, FG_INFO, "Restored flight from fgfs.sav");
494             } else {
495                 FG_LOG(FG_INPUT, FG_ALERT, "Cannot load flight from fgfs.sav");
496             }
497             return;
498         }
499         case GLUT_KEY_F2: {
500             FG_LOG(FG_INPUT, FG_INFO, "Saving flight");
501             ofstream output("fgfs.sav");
502             if (output.good() && fgSaveFlight(output)) {
503                 output.close();
504                 FG_LOG(FG_INPUT, FG_INFO, "Saved flight to fgfs.sav");
505             } else {
506                 FG_LOG(FG_INPUT, FG_ALERT, "Cannot save flight to fgfs.sav");
507             }
508             return;
509         }
510         case GLUT_KEY_F3: {
511           string panel_path =
512             current_properties.getStringValue("/sim/panel/path",
513                                               "Panels/Default/default.xml");
514           FGPanel * new_panel = fgReadPanel(panel_path);
515           if (new_panel == 0) {
516             FG_LOG(FG_INPUT, FG_ALERT,
517                    "Error reading new panel from " << panel_path);
518             return;
519           }
520           FG_LOG(FG_INPUT, FG_INFO, "Loaded new panel from " << panel_path);
521           delete current_panel;
522           current_panel = new_panel;
523           return;
524         }
525         case GLUT_KEY_F4: {
526           FGPath props_path(globals->get_options()->get_fg_root());
527           props_path.append("preferences.xml");
528           FG_LOG(FG_INPUT, FG_INFO, "Rereading global preferences");
529           if (!readPropertyList(props_path.str(), &current_properties)) {
530             FG_LOG(FG_INPUT, FG_ALERT,
531                    "Failed to reread global preferences from "
532                    << props_path.str());
533           } else {
534             FG_LOG(FG_INPUT, FG_INFO, "Finished Reading global preferences");
535           }
536           return;
537         }
538         case GLUT_KEY_F5: {
539           current_panel->setYOffset(current_panel->getYOffset() - 5);
540           fgReshape(globals->get_options()->get_xsize(),
541                     globals->get_options()->get_ysize());
542           return;
543         }
544         case GLUT_KEY_F6: {
545           current_panel->setYOffset(current_panel->getYOffset() + 5);
546           fgReshape(globals->get_options()->get_xsize(),
547                     globals->get_options()->get_ysize());
548           return;
549         }
550         case GLUT_KEY_F7: {
551           current_panel->setXOffset(current_panel->getXOffset() - 5);
552           return;
553         }
554         case GLUT_KEY_F8: {
555           current_panel->setXOffset(current_panel->getXOffset() + 5);
556           return;
557         }
558         case GLUT_KEY_END: // numeric keypad 1
559             v->set_goal_view_offset( FG_PI * 0.75 );
560             if ( globals->get_options()->get_view_mode() ==
561                  FGOptions::FG_VIEW_FOLLOW)
562             {
563                 globals->get_current_view()->set_pilot_offset(-25.0, 25.0, 1.0);
564                 v->set_view_offset( FG_PI * 0.75 );
565             }
566             return;
567         case GLUT_KEY_DOWN: // numeric keypad 2
568             v->set_goal_view_offset( FG_PI );
569             if ( globals->get_options()->get_view_mode() ==
570                  FGOptions::FG_VIEW_FOLLOW )
571             {
572                 globals->get_current_view()->set_pilot_offset(-25.0, 0.0, 1.0);
573                 v->set_view_offset( FG_PI );
574             }
575             return;
576         case GLUT_KEY_PAGE_DOWN: // numeric keypad 3
577             v->set_goal_view_offset( FG_PI * 1.25 );
578             if ( globals->get_options()->get_view_mode() ==
579                  FGOptions::FG_VIEW_FOLLOW)
580             {
581                 globals->get_current_view()->set_pilot_offset(-25.0, -25.0, 1.0);
582                 v->set_view_offset( FG_PI * 1.25 );
583             }
584             return;
585         case GLUT_KEY_LEFT: // numeric keypad 4
586             v->set_goal_view_offset( FG_PI * 0.50 );
587             if ( globals->get_options()->get_view_mode() ==
588                  FGOptions::FG_VIEW_FOLLOW )
589             {
590                 globals->get_current_view()->set_pilot_offset(0.0, 25.0, 1.0);
591                 v->set_view_offset( FG_PI * 0.50 );
592             }
593             return;
594         case GLUT_KEY_RIGHT: // numeric keypad 6
595             v->set_goal_view_offset( FG_PI * 1.50 );
596             if ( globals->get_options()->get_view_mode() ==
597                  FGOptions::FG_VIEW_FOLLOW )
598             {
599                 globals->get_current_view()->set_pilot_offset(0.0, -25.0, 1.0);
600                 v->set_view_offset( FG_PI * 1.50 );
601             }
602             return;
603         case GLUT_KEY_HOME: // numeric keypad 7
604             v->set_goal_view_offset( FG_PI * 0.25 );
605             if ( globals->get_options()->get_view_mode() ==
606                  FGOptions::FG_VIEW_FOLLOW )
607             {
608                 globals->get_current_view()->set_pilot_offset(25.0, 25.0, 1.0);
609                 v->set_view_offset( FG_PI * 0.25 );
610             }
611             return;
612         case GLUT_KEY_UP: // numeric keypad 8
613             v->set_goal_view_offset( 0.00 );
614             if ( globals->get_options()->get_view_mode() ==
615                  FGOptions::FG_VIEW_FOLLOW )
616             {
617                 globals->get_current_view()->set_pilot_offset(25.0, 0.0, 1.0);
618                 v->set_view_offset( 0.00 );
619             }
620             return;
621         case GLUT_KEY_PAGE_UP: // numeric keypad 9
622             v->set_goal_view_offset( FG_PI * 1.75 );
623             if ( globals->get_options()->get_view_mode() ==
624                  FGOptions::FG_VIEW_FOLLOW )
625             {
626                 globals->get_current_view()->set_pilot_offset(25.0, -25.0, 1.0);
627                 v->set_view_offset( FG_PI * 1.75 );
628             }
629             return;
630         }
631     } else {
632         FG_LOG( FG_INPUT, FG_DEBUG, "" );
633         switch (k) {
634         case GLUT_KEY_F2: // F2 Reload Tile Cache...
635             {
636                 bool freeze;
637                 FG_LOG(FG_INPUT, FG_INFO, "ReIniting TileCache");
638                 if ( !freeze ) 
639                     globals->set_freeze( true );
640                 BusyCursor(0);
641                 if ( global_tile_mgr.init() ) {
642                     // Load the local scenery data
643                     global_tile_mgr.update( 
644                         cur_fdm_state->get_Longitude() * RAD_TO_DEG,
645                         cur_fdm_state->get_Latitude() * RAD_TO_DEG );
646                 } else {
647                     FG_LOG( FG_GENERAL, FG_ALERT, 
648                             "Error in Tile Manager initialization!" );
649                     exit(-1);
650                 }
651                 BusyCursor(1);
652                 if ( !freeze )
653                    globals->set_freeze( false );
654                 return;
655             }
656         case GLUT_KEY_F3: // F3 Take a screen shot
657             fgDumpSnapShot();
658             return;
659         case GLUT_KEY_F6: // F6 toggles Autopilot target location
660             if ( current_autopilot->get_HeadingMode() !=
661                  FGAutopilot::FG_HEADING_WAYPOINT ) {
662                 current_autopilot->set_HeadingMode(
663                     FGAutopilot::FG_HEADING_WAYPOINT );
664                 current_autopilot->set_HeadingEnabled( true );
665             } else {
666                 current_autopilot->set_HeadingMode(
667                     FGAutopilot::FG_HEADING_LOCK );
668             }
669             return;
670         case GLUT_KEY_F8: // F8 toggles fog ... off fastest nicest...
671             globals->get_options()->cycle_fog();
672         
673             if ( globals->get_options()->get_fog() ==
674                  FGOptions::FG_FOG_DISABLED )
675             {
676                 FG_LOG( FG_INPUT, FG_INFO, "Fog disabled" );
677             } else if ( globals->get_options()->get_fog() == 
678                         FGOptions::FG_FOG_FASTEST )
679             {
680                 FG_LOG( FG_INPUT, FG_INFO, 
681                         "Fog enabled, hint set to fastest" );
682             } else if ( globals->get_options()->get_fog() ==
683                         FGOptions::FG_FOG_NICEST )
684             {
685                 FG_LOG( FG_INPUT, FG_INFO,
686                         "Fog enabled, hint set to nicest" );
687             }
688
689             return;
690         case GLUT_KEY_F9: // F9 toggles textures on and off...
691             FG_LOG( FG_INPUT, FG_INFO, "Toggling texture" );
692             if ( globals->get_options()->get_textures() ) {
693                 globals->get_options()->set_textures( false );
694                 material_lib.set_step( 1 );
695             } else {
696                 globals->get_options()->set_textures( true );
697                 material_lib.set_step( 0 );
698             }
699             return;
700         case GLUT_KEY_F10: // F10 toggles menu on and off...
701             FG_LOG(FG_INPUT, FG_INFO, "Invoking call back function");
702             guiToggleMenu();
703             return;
704         case GLUT_KEY_F11: // F11 Altitude Dialog.
705             FG_LOG(FG_INPUT, FG_INFO, "Invoking Altitude call back function");
706             NewAltitude( NULL );
707             return;
708         case GLUT_KEY_F12: // F12 Heading Dialog...
709             FG_LOG(FG_INPUT, FG_INFO, "Invoking Heading call back function");
710             NewHeading( NULL );
711             return;
712         case GLUT_KEY_UP:
713             if ( current_autopilot->get_AltitudeEnabled() ) {
714                 current_autopilot->AltitudeAdjust( -100 );
715             } else {
716                 controls.move_elevator(0.05);
717             }
718             return;
719         case GLUT_KEY_DOWN:
720             if ( current_autopilot->get_AltitudeEnabled() ) {
721                 current_autopilot->AltitudeAdjust( 100 );
722             } else {
723                 controls.move_elevator(-0.05);
724             }
725             return;
726         case GLUT_KEY_LEFT:
727             controls.move_aileron(-0.05);
728             return;
729         case GLUT_KEY_RIGHT:
730             controls.move_aileron(0.05);
731             return;
732         case GLUT_KEY_HOME: // numeric keypad 1
733             controls.move_elevator_trim(0.001);
734             return;
735         case GLUT_KEY_END: // numeric keypad 7
736             controls.move_elevator_trim(-0.001);
737             return;
738         case GLUT_KEY_INSERT: // numeric keypad Ins
739             if ( current_autopilot->get_HeadingEnabled() ) {
740                 current_autopilot->HeadingAdjust( -1 );
741             } else {
742                 controls.move_rudder(-0.05);
743             }
744             return;
745         case 13: // numeric keypad Enter
746             if ( current_autopilot->get_HeadingEnabled() ) {
747                 current_autopilot->HeadingAdjust( 1 );
748             } else {
749                 controls.move_rudder(0.05);
750             }
751             return;
752         case 53: // numeric keypad 5
753             controls.set_aileron(0.0);
754             controls.set_elevator(0.0);
755             controls.set_rudder(0.0);
756             return;
757         case GLUT_KEY_PAGE_UP: // numeric keypad 9 (Pg Up)
758             if ( current_autopilot->get_AutoThrottleEnabled() ) {
759                 current_autopilot->AutoThrottleAdjust( 5 );
760             } else {
761                 controls.move_throttle( FGControls::ALL_ENGINES, 0.01 );
762             }
763             return;
764         case GLUT_KEY_PAGE_DOWN: // numeric keypad 3 (Pg Dn)
765             if ( current_autopilot->get_AutoThrottleEnabled() ) {
766                 current_autopilot->AutoThrottleAdjust( -5 );
767             } else {
768                 controls.move_throttle( FGControls::ALL_ENGINES, -0.01 );
769             }
770             return;
771         }
772     }
773 }
774
775