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