Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

Keyboard.cpp

Go to the documentation of this file.
00001 /*
00002  * Keyboard.cpp
00003  *
00004  * Part of Fly! Legacy project
00005  *
00006  * Copyright 2003 Chris Wallace
00007  *
00008  * Fly! Legacy is free software; you can redistribute it and/or modify
00009  *   it under the terms of the GNU General Public License as published by
00010  *   the Free Software Foundation; either version 2 of the License, or
00011  *   (at your option) any later version.
00012  *
00013  * Fly! Legacy is distributed in the hope that it will be useful,
00014  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  *   GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  *   along with Fly! Legacy; if not, write to the Free Software
00020  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021  *
00022  */
00023 
00028 #include "../Include/FlyLegacy.h"
00029 #include "../Include/Ui.h"
00030 #include "../Include/Globals.h"
00031 #include "../Include/UserVehicles.h"
00032 #include "../Include/Situation.h"
00033 #include "../Include/Cameras.h"
00034 #include "../Include/KeyMap.h"
00035 
00036 
00037 bool KeyMenuLoadScenario (int keyid, int code, int modifiers)
00038 {
00039   return false;
00040 }
00041 
00042 bool KeyMenuSaveScenario (int keyid, int code, int modifiers)
00043 {
00044   return false;
00045 }
00046 
00047 bool KeyMenuSaveScenarioAs (int keyid, int code, int modifiers)
00048 {
00049   return false;
00050 }
00051 
00052 bool KeyMenuQuit (int keyid, int code, int modifiers)
00053 {
00054   // Quit gracefully by setting application mode.  This will cause shutdown
00055   //   on the next redraw() cycle
00056   globals->appState = APP_EXIT_SCREEN;
00057   return true;
00058 }
00059 
00060 
00061 static void BindMenuKeys (CKeyMap *keymap)
00062 {
00063   // 'esc ' Escape
00064   // 'retn' Return
00065   // 'entr' Enter
00066 //  keymap->Bind ('clos', KeyMenuCloseWindow);
00067   keymap->Bind ('load', KeyMenuLoadScenario);
00068   keymap->Bind ('save', KeyMenuSaveScenario);
00069   keymap->Bind ('sava', KeyMenuSaveScenarioAs);
00070 //  keymap->Bind ('prnt', KeyMenuPrint);
00071   keymap->Bind ('quit', KeyMenuQuit);
00072 //  keymap->Bind ('ogrp', KeyMenuGraphics);
00073 //  keymap->Bind ('osnd', KeyMenuSound);
00074 //  keymap->Bind ('keys', KeyMenuKeysButtons);
00075 //  keymap->Bind ('axes', KeyMenuAxes);
00076 //  keymap->Bind ('tstc', KeyMenuTestControls);
00077 //  keymap->Bind ('ockp', KeyMenuCockpit);
00078 //  keymap->Bind ('otun', KeyMenuTuneRadios);
00079 //  keymap->Bind ('oair', KeyMenuAircraft);
00080 //  keymap->Bind ('real', KeyMenuRealism);
00081 //  keymap->Bind ('tree', KeyMenuScenery);
00082 //  keymap->Bind ('date', KeyMenuDateTime);
00083 //  keymap->Bind ('gogo', KeyMenuStartup);
00084 //  keymap->Bind ('mute', KeyMenuMute);
00085 //  keymap->Bind ('sfly', KeyMenuAdventures);
00086 //  keymap->Bind ('qfly', KeyMenuQuickFlight);
00087 //  keymap->Bind ('goto', KeyMenuTeleport);
00088 }
00089 
00090 
00091 /*
00092  * Global Keys
00093  */
00094 
00095 bool KeyGlobalCockpitToggle (int keyid, int code, int modifiers)
00096 {
00097   return false;
00098 }
00099 
00100 bool KeyGlobalNextVehicle (int keyid, int code, int modifiers)
00101 {
00102   return false;
00103 }
00104 
00105 bool KeyGlobalPrevVehicle (int keyid, int code, int modifiers)
00106 {
00107   return false;
00108 }
00109 
00110 bool KeyGlobalHomeVehicle (int keyid, int code, int modifiers)
00111 {
00112   return false;
00113 }
00114 
00115 bool KeyGlobalCameraNext (int keyid, int code, int modifiers)
00116 {
00117   // Command camera manager of user vehicle to cycle to the next camera
00118   CCameraManager *cam = globals->sit->user->GetCameraManager ();
00119   cam->NextCamera ();
00120 
00121   return true;
00122 }
00123 
00124 bool KeyGlobalCameraPrev (int keyid, int code, int modifiers)
00125 {
00126   // Command camera manager of user vehicle to cycle to the next camera
00127   CCameraManager *cam = globals->sit->user->GetCameraManager ();
00128   cam->PrevCamera ();
00129 
00130   return true;
00131 }
00132 
00133 bool KeyGlobalMenu (int keyid, int code, int modifiers)
00134 {
00135   toggle_menu ();
00136 
00137   return true;
00138 }
00139 
00140 bool KeyGlobalTimeForward (int keyid, int code, int modifiers)
00141 {
00142   SDateTimeDelta delta;
00143   delta.dYears = delta.dMonths = delta.dDays = delta.dHours = 0;
00144   delta.dMinutes = 30;
00145   delta.dSeconds = delta.dMillisecs = 0;
00146 
00147   SDateTime dt = globals->timemgr->GetUTCDateTime ();
00148   dt = globals->timemgr->AddTimeDelta (dt, delta);
00149   globals->timemgr->SetUTCDateTime (dt);
00150 
00151   // 
00152   // Archived code increases the sim timescale x2
00153   //
00154 /*
00155   float scale = globals->timemgr->GetTimeScale ();
00156   globals->timemgr->SetTimeScale (scale * 2);
00157 
00158   // Display a message to the user indicating the new time scale
00159   char msg[80];
00160   sprintf (msg, "Time Scale = %2.1fx", globals->timemgr->GetTimeScale());
00161   DrawNoticeToUser (msg, 5);
00162 */
00163 
00164   return true;
00165 }
00166 
00167 bool KeyGlobalTimeBackward (int keyid, int code, int modifiers)
00168 {
00169   SDateTimeDelta delta;
00170   delta.dYears = delta.dMonths = delta.dDays = delta.dHours = 0;
00171   delta.dMinutes = 30;
00172   delta.dSeconds = delta.dMillisecs = 0;
00173 
00174   SDateTime dt = globals->timemgr->GetUTCDateTime ();
00175   dt = globals->timemgr->SubtractTimeDelta (dt, delta);
00176   globals->timemgr->SetUTCDateTime (dt);
00177 
00178   // 
00179   // Archived code increases the sim timescale x2
00180   //
00181 /*
00182   float scale = globals->timemgr->GetTimeScale ();
00183   globals->timemgr->SetTimeScale (scale / 2);
00184 
00185   // Display a message to the user indicating the new time scale
00186   char msg[80];
00187   sprintf (msg, "Time Scale = %2.1fx", globals->timemgr->GetTimeScale());
00188   DrawNoticeToUser (msg, 5);
00189 */
00190 
00191   return true;
00192 }
00193 
00194 bool KeyGlobalPause (int keyid, int code, int modifiers)
00195 {
00196   if (globals->timemgr->GetPauseState ()) {
00197     globals->timemgr->Pause ();
00198   } else {
00199     globals->timemgr->Unpause ();
00200   }
00201 
00202   return true;
00203 }
00204 
00205 
00206 bool KeyGlobal (int id, int code, int modifiers)
00207 {
00208   bool rc = false;
00209 
00210   switch (id) {
00211   case 'mwin':
00212     // Map window
00213     globals->fuimgr->CreateFuiWindow (MapNotify,
00214                                       FUI_WINDOW_MAP,
00215                                       "UI\\TEMPLATES\\SLCTMAP.WIN");
00216     rc = true;
00217     break;
00218 
00219   case 'vwin':
00220     // Vector map window
00221     globals->fuimgr->CreateFuiWindow (VectorMapNotify,
00222                                       FUI_WINDOW_VECTOR_MAP,
00223                                       "UI\\TEMPLATES\\RASTRMAP.WIN");
00224     rc = true;
00225     break;
00226 
00227   case 'fpsw':
00228     // Frame rate window
00229     globals->fuimgr->CreateFuiWindow (FrameRateNotify,
00230                                       FUI_WINDOW_FRAME_RATE,
00231                                       "UI\\TEMPLATES\\FRAMRATE.WIN");
00232     rc = true;
00233     break;
00234   }
00235 
00236   return rc;
00237 }
00238 
00239 
00240 static void BindGlobalKeys (CKeyMap *keymap)
00241 {
00242   keymap->Bind ('cock', KeyGlobalCockpitToggle);
00243   keymap->Bind ('nveh', KeyGlobalNextVehicle);
00244   keymap->Bind ('pveh', KeyGlobalPrevVehicle);
00245   keymap->Bind ('hveh', KeyGlobalHomeVehicle);
00246   keymap->Bind ('camn', KeyGlobalCameraNext);
00247   keymap->Bind ('camn', KeyGlobalCameraPrev);
00248   keymap->Bind ('menu', KeyGlobalMenu);
00249   keymap->Bind ('timf', KeyGlobalTimeForward);
00250   keymap->Bind ('timb', KeyGlobalTimeBackward);
00251   keymap->Bind ('paus', KeyGlobalPause);
00252   keymap->Bind ('mwin', KeyGlobal);
00253   keymap->Bind ('vwin', KeyGlobal);
00254   keymap->Bind ('fpsw', KeyGlobal);
00255 
00256 /*
00257 KeySet 'glob' Global Keys
00258   'stat' Status Bar
00259   'rsit' Reset Situation
00260   'ival' Increase Value
00261   'dval' Decrease Value
00262   'cycl' Cycle Windows
00263   'mwin' Map Window
00264   'vwin' Vector Window
00265   'gwin' GPS Window
00266   'cklw' Checklist Window
00267   'ssht' Screen Shot
00268   'cdis' Compress Distance
00269   'ddis' Decompress Distance
00270   'bbox' Instant Replay
00271   'mike' Microphone/LiveMic
00272   'axis' Axis Window
00273   'menu' Menu Bar
00274   'mnud' Menu Down
00275   'mnuu' Menu Up
00276   'mnul' Menu Left
00277   'mnur' Menu Right
00278   'mnua' Menu Accept
00279   'mnux' Menu Abort
00280   'atct' ATC On/Off
00281   'attn' Auto Tune Comm 1
00282   'atcm' ATC Menu
00283   'atc1' ATC Phrase #1
00284   'atc2' ATC Phrase #2
00285   'atc3' ATC Phrase #3
00286   'atc4' ATC Phrase #4
00287   'atc5' ATC Phrase #5
00288   'atc6' ATC Phrase #6
00289   'atc7' ATC Phrase #7
00290   'atc8' ATC Phrase #8
00291   'atc9' ATC Phrase #9
00292   'atc0' ATC Phrase #10
00293   'chat' Chat Window
00294   'phlp' Range Finder
00295   'vsfr' Sim Frame Rate
00296   'ifr_' Toggle VFR/IFR Panels
00297   'sprf' Show Profiler Dialog
00298   'skyt' Sky Tweaker
00299   'dbgS' Sim Debug Displays
00300   'dllw' DLL Task Window
00301   'carg' Jettison Cargo
00302   'repr' Repair & Revive
00303   'moov' Toggle Movie Capture
00304   'jpeg' JPEG Screenshot
00305   'g430' GNS430 Popup Window
00306   'ftkR' FlyTrak Record
00307   'ftkP' FlyTrak Playback
00308   'ftkC' FlyTrak Configuration
00309 */
00310 }
00311 
00312 
00313 //
00314 // The following key mappings are camera mode selectors which are sent to the
00315 //   camera manager, not specifically to the current camera
00316 //
00317 
00318 bool KeyCameraCockpit (int id, int code, int mod)
00319 {
00320   // Command camera manager of user vehicle to cycle to the next camera
00321   CCameraManager *cam = globals->sit->user->GetCameraManager ();
00322   cam->SelectCamera (CAMERA_COCKPIT);
00323 
00324   return true;
00325 }
00326 
00327 bool KeyCameraSpot (int id, int code, int mod)
00328 {
00329   // Command camera manager of user vehicle to cycle to the next camera
00330   CCameraManager *cam = globals->sit->user->GetCameraManager ();
00331   cam->SelectCamera (CAMERA_SPOT);
00332 
00333   return true;
00334 }
00335 
00336 bool KeyCameraChase (int id, int code, int mod)
00337 {
00338   return false;
00339 }
00340 
00341 bool KeyCameraStationary (int id, int code, int mod)
00342 {
00343   return false;
00344 }
00345 
00346 bool KeyCameraFlyby (int id, int code, int mod)
00347 {
00348   // Command camera manager of user vehicle to cycle to the next camera
00349   CCameraManager *cam = globals->sit->user->GetCameraManager ();
00350   cam->SelectCamera (CAMERA_FLYBY);
00351 
00352   return true;
00353 }
00354 
00355 bool KeyCameraTower (int id, int code, int mod)
00356 {
00357   // Command camera manager of user vehicle to cycle to the next camera
00358   CCameraManager *cam = globals->sit->user->GetCameraManager ();
00359   cam->SelectCamera (CAMERA_TOWER);
00360 
00361   return true;
00362 }
00363 
00364 
00365 //
00366 // The following camera key mappings are generally applicable to external cameras
00367 //
00368 bool KeyCameraZoomIn (int id, int code, int mod)
00369 {
00370   CCamera *cam = globals->sit->GetCurrentCamera ();
00371   cam->ZoomIn ();
00372 
00373   return true;
00374 }
00375 
00376 bool KeyCameraZoomInSlow (int id, int code, int mod)
00377 {
00378   CCamera *cam = globals->sit->GetCurrentCamera ();
00379   cam->ZoomInSlow ();
00380 
00381   return true;
00382 }
00383 
00384 bool KeyCameraZoomInFast (int id, int code, int mod)
00385 {
00386   CCamera *cam = globals->sit->GetCurrentCamera ();
00387   cam->ZoomInFast ();
00388 
00389   return true;
00390 }
00391 
00392 bool KeyCameraZoomOut (int id, int code, int mod)
00393 {
00394   CCamera *cam = globals->sit->GetCurrentCamera ();
00395   cam->ZoomOut ();
00396 
00397   return true;
00398 }
00399 
00400 bool KeyCameraZoomOutSlow (int id, int code, int mod)
00401 {
00402   CCamera *cam = globals->sit->GetCurrentCamera ();
00403   cam->ZoomOutSlow ();
00404 
00405   return true;
00406 }
00407 
00408 bool KeyCameraZoomOutFast (int id, int code, int mod)
00409 {
00410   CCamera *cam = globals->sit->GetCurrentCamera ();
00411   cam->ZoomOutFast ();
00412 
00413   return true;
00414 }
00415 
00416 bool KeyCameraZoomReset (int id, int code, int mod)
00417 {
00418   CCamera *cam = globals->sit->GetCurrentCamera ();
00419   cam->ZoomReset ();
00420 
00421   return true;
00422 }
00423 
00424 bool KeyCameraZoomRatioIn (int id, int code, int mod)
00425 {
00426   CCamera *cam = globals->sit->GetCurrentCamera ();
00427   cam->ZoomRatioIn ();
00428 
00429   return true;
00430 }
00431 
00432 bool KeyCameraZoomRatioOut (int id, int code, int mod)
00433 {
00434   CCamera *cam = globals->sit->GetCurrentCamera ();
00435   cam->ZoomRatioOut ();
00436 
00437   return true;
00438 }
00439 
00440 bool KeyCameraPanLeft (int id, int code, int mod)
00441 {
00442   CCamera *cam = globals->sit->GetCurrentCamera ();
00443   cam->PanLeft ();
00444 
00445   return true;
00446 }
00447 
00448 bool KeyCameraPanRight (int id, int code, int mod)
00449 {
00450   CCamera *cam = globals->sit->GetCurrentCamera ();
00451   cam->PanRight ();
00452 
00453   return true;
00454 }
00455 
00456 bool KeyCameraPanUp (int id, int code, int mod)
00457 {
00458   CCamera *cam = globals->sit->GetCurrentCamera ();
00459   cam->PanUp ();
00460 
00461   return true;
00462 }
00463 
00464 bool KeyCameraPanDown (int id, int code, int mod)
00465 {
00466   CCamera *cam = globals->sit->GetCurrentCamera ();
00467   cam->PanDown ();
00468 
00469   return true;
00470 }
00471 
00472 //
00473 // The following camera key mappings are applicable only to interior cameras
00474 //
00475 
00476 bool KeyCameraUser1 (int id, int code, int mod)
00477 {
00478   CCamera *cam = globals->sit->GetCurrentCamera ();
00479   cam->User1 ();
00480 
00481   return true;
00482 }
00483 
00484 bool KeyCameraDefineUser1 (int id, int code, int mod)
00485 {
00486   CCamera *cam = globals->sit->GetCurrentCamera ();
00487   cam->DefineUser1 ();
00488 
00489   return true;
00490 }
00491 
00492 bool KeyCameraUser2 (int id, int code, int mod)
00493 {
00494   CCamera *cam = globals->sit->GetCurrentCamera ();
00495   cam->User2 ();
00496 
00497   return true;
00498 }
00499 
00500 bool KeyCameraDefineUser2 (int id, int code, int mod)
00501 {
00502   CCamera *cam = globals->sit->GetCurrentCamera ();
00503   cam->DefineUser2 ();
00504 
00505   return true;
00506 }
00507 
00508 bool KeyCameraUser3 (int id, int code, int mod)
00509 {
00510   CCamera *cam = globals->sit->GetCurrentCamera ();
00511   cam->User3 ();
00512 
00513   return true;
00514 }
00515 
00516 bool KeyCameraDefineUser3 (int id, int code, int mod)
00517 {
00518   CCamera *cam = globals->sit->GetCurrentCamera ();
00519   cam->DefineUser3 ();
00520 
00521   return true;
00522 }
00523 
00524 bool KeyCameraUser4 (int id, int code, int mod)
00525 {
00526   CCamera *cam = globals->sit->GetCurrentCamera ();
00527   cam->User4 ();
00528 
00529   return true;
00530 }
00531 
00532 bool KeyCameraDefineUser4 (int id, int code, int mod)
00533 {
00534   CCamera *cam = globals->sit->GetCurrentCamera ();
00535   cam->DefineUser4 ();
00536 
00537   return true;
00538 }
00539 
00540 bool KeyCameraUser5 (int id, int code, int mod)
00541 {
00542   CCamera *cam = globals->sit->GetCurrentCamera ();
00543   cam->User5 ();
00544 
00545   return true;
00546 }
00547 
00548 bool KeyCameraDefineUser5 (int id, int code, int mod)
00549 {
00550   CCamera *cam = globals->sit->GetCurrentCamera ();
00551   cam->DefineUser5 ();
00552 
00553   return true;
00554 }
00555 
00556 bool KeyCameraUser6 (int id, int code, int mod)
00557 {
00558   CCamera *cam = globals->sit->GetCurrentCamera ();
00559   cam->User6 ();
00560 
00561   return true;
00562 }
00563 
00564 bool KeyCameraDefineUser6 (int id, int code, int mod)
00565 {
00566   CCamera *cam = globals->sit->GetCurrentCamera ();
00567   cam->DefineUser6 ();
00568 
00569   return true;
00570 }
00571 
00572 bool KeyCameraUser7 (int id, int code, int mod)
00573 {
00574   CCamera *cam = globals->sit->GetCurrentCamera ();
00575   cam->User7 ();
00576 
00577   return true;
00578 }
00579 
00580 bool KeyCameraDefineUser7 (int id, int code, int mod)
00581 {
00582   CCamera *cam = globals->sit->GetCurrentCamera ();
00583   cam->DefineUser7 ();
00584 
00585   return true;
00586 }
00587 
00588 bool KeyCameraUser8 (int id, int code, int mod)
00589 {
00590   CCamera *cam = globals->sit->GetCurrentCamera ();
00591   cam->User8 ();
00592 
00593   return true;
00594 }
00595 
00596 bool KeyCameraDefineUser8 (int id, int code, int mod)
00597 {
00598   CCamera *cam = globals->sit->GetCurrentCamera ();
00599   cam->DefineUser8 ();
00600 
00601   return true;
00602 }
00603 
00604 bool KeyCameraHeadPitchUp (int id, int code, int mod)
00605 {
00606   CCamera *cam = globals->sit->GetCurrentCamera ();
00607   cam->HeadPitchUp ();
00608 
00609   return true;
00610 }
00611 
00612 bool KeyCameraHeadPitchDown (int id, int code, int mod)
00613 {
00614   CCamera *cam = globals->sit->GetCurrentCamera ();
00615   cam->HeadPitchDown ();
00616 
00617   return true;
00618 }
00619 
00620 bool KeyCameraCockpitScrollUp (int id, int code, int mod)
00621 {
00622   CPanel *panel = globals->sit->GetCurrentPanel ();
00623   if (panel != NULL) panel->ScrollUp ();
00624 
00625   return true;
00626 }
00627 
00628 bool KeyCameraCockpitScrollDown (int id, int code, int mod)
00629 {
00630   CPanel *panel = globals->sit->GetCurrentPanel ();
00631   if (panel != NULL) panel->ScrollDown ();
00632 
00633   return true;
00634 }
00635 
00636 bool KeyCameraCockpitScrollLeft (int id, int code, int mod)
00637 {
00638   CPanel *panel = globals->sit->GetCurrentPanel ();
00639   if (panel != NULL) panel->ScrollLeft ();
00640 
00641   return true;
00642 }
00643 
00644 bool KeyCameraCockpitScrollRight (int id, int code, int mod)
00645 {
00646   CPanel *panel = globals->sit->GetCurrentPanel ();
00647   if (panel != NULL) panel->ScrollRight ();
00648 
00649   return true;
00650 }
00651 
00652 bool KeyCameraCockpitHome (int id, int code, int mod)
00653 {
00654 //  CPanel *panel = globals->sit->GetCurrentPanel ();
00655 //  panel->CockpitPageUp ();
00656   return false;
00657 }
00658 
00659 bool KeyCameraCockpitPageUp (int id, int code, int mod)
00660 {
00661 //  CPanel *panel = globals->sit->GetCurrentPanel ();
00662 //  panel->CockpitPageUp ();
00663   return false;
00664 }
00665 
00666 bool KeyCameraCockpitPageDown (int id, int code, int mod)
00667 {
00668 //  CPanel *panel = globals->sit->GetCurrentPanel ();
00669 //  panel->CockpitPageUp ();
00670   return false;
00671 }
00672 
00673   
00674 static void BindCameraKeys (CKeyMap *keymap)
00675 {
00676   keymap->Bind ('czin', KeyCameraZoomIn);
00677   keymap->Bind ('czis', KeyCameraZoomInSlow);
00678   keymap->Bind ('czif', KeyCameraZoomInFast);
00679   keymap->Bind ('czot', KeyCameraZoomOut);
00680   keymap->Bind ('czos', KeyCameraZoomOutSlow);
00681   keymap->Bind ('czof', KeyCameraZoomOutFast);
00682   keymap->Bind ('czrs', KeyCameraZoomReset);
00683 
00684   keymap->Bind ('cs01', KeyCameraUser1);
00685   keymap->Bind ('cd01', KeyCameraDefineUser1);
00686   keymap->Bind ('cs02', KeyCameraUser2);
00687   keymap->Bind ('cd02', KeyCameraDefineUser1);
00688   keymap->Bind ('cs03', KeyCameraUser3);
00689   keymap->Bind ('cd03', KeyCameraDefineUser1);
00690   keymap->Bind ('cs04', KeyCameraUser4);
00691   keymap->Bind ('cd04', KeyCameraDefineUser1);
00692   keymap->Bind ('cs05', KeyCameraUser5);
00693   keymap->Bind ('cd05', KeyCameraDefineUser1);
00694   keymap->Bind ('cs06', KeyCameraUser6);
00695   keymap->Bind ('cd06', KeyCameraDefineUser1);
00696   keymap->Bind ('cs07', KeyCameraUser7);
00697   keymap->Bind ('cd07', KeyCameraDefineUser1);
00698   keymap->Bind ('cs08', KeyCameraUser8);
00699   keymap->Bind ('cd08', KeyCameraDefineUser1);
00700   keymap->Bind ('chpu', KeyCameraHeadPitchUp);
00701   keymap->Bind ('chpd', KeyCameraHeadPitchDown);
00702   keymap->Bind ('czri', KeyCameraZoomRatioIn);
00703   keymap->Bind ('czr0', KeyCameraZoomRatioOut);
00704   keymap->Bind ('cam1', KeyCameraCockpit);
00705   keymap->Bind ('cam2', KeyCameraSpot);
00706   keymap->Bind ('cam3', KeyCameraChase);
00707   keymap->Bind ('cam4', KeyCameraStationary);
00708   keymap->Bind ('cam5', KeyCameraFlyby);
00709   keymap->Bind ('cam6', KeyCameraTower);
00710   keymap->Bind ('cplf', KeyCameraPanLeft);
00711   keymap->Bind ('cprt', KeyCameraPanRight);
00712   keymap->Bind ('cpup', KeyCameraPanUp);
00713   keymap->Bind ('cpdn', KeyCameraPanDown);
00714   keymap->Bind ('ckup', KeyCameraCockpitScrollUp);
00715   keymap->Bind ('ckdn', KeyCameraCockpitScrollDown);
00716   keymap->Bind ('cklf', KeyCameraCockpitScrollLeft);
00717   keymap->Bind ('ckri', KeyCameraCockpitScrollRight);
00718   keymap->Bind ('ckhm', KeyCameraCockpitHome);
00719   keymap->Bind ('ckpu', KeyCameraCockpitPageUp);
00720   keymap->Bind ('ckpd', KeyCameraCockpitPageDown);
00721 }
00722 
00723 
00724 /*
00725  * Flight Planner Keys
00726  */
00727 
00728 /*
00729   'sfpl' Flight Planner
00730   'navl' Navigation Log...
00731   'fpck' FP CheckList...
00732   'logb' Log Book...
00733   'vdir' Directory...
00734   'cwpt' Current Waypoint
00735   'sair' Select Aircraft
00736   'ouch' Damage Report
00737   'sful' Setup Fuel
00738   'sbag' Weight & Baggage
00739   'cgin' CG Indicator
00740   'adet' Aircraft Details
00741   'envo' Weather Overview
00742   'envc' Clouds
00743   'envw' Winds
00744   'envm' Other Weather
00745   'metr' Load METAR
00746   'MPst' Multiplayer...
00747   'dcon' Disconnect
00748   'fndp' Find Pilot...
00749   'motd' Show MOTD...
00750   'admn' Sysop...
00751   'who ' About Fly
00752   'webs' Support Web Site
00753   'webt' TRI Web Site
00754   'webg' Gathering Web Site
00755   'uedt' UI Editor...
00756   'thmn' Theme Manager...
00757   'medt' Model Editor...
00758   'sedt' Scenery Editor...
00759  */
00760 
00761 /*
00762  * Airplane Control Keys
00763  */
00764 
00765 bool KeyAirplane (int id, int code, int mod)
00766 {
00767   // These keys are only applicable if the user vehicle is an airplane
00768   EFlyObjectType type = globals->sit->GetUserVehicleType ();
00769   if (type != TYPE_FLY_AIRPLANE) {
00770     return false;
00771   }
00772 
00773   // Inhibit aircraft control when in slew mode
00774   if (globals->slewmgr->IsEnabled ()) {
00775     return false;
00776   }
00777 
00778   bool rc = true;
00779   CAirplane *plane = ((CAirplaneObject *)globals->sit->GetUserVehicle ())->pAirplane;
00780 
00781   switch (id) {
00782   case 'adel':
00783     // Elevator down
00784     plane->ElevatorDecr ();
00785     break;
00786 
00787   case 'auel':
00788     // Elevator up
00789     plane->ElevatorIncr ();
00790     break;
00791 
00792   case 'alai':
00793     // Aileron Left
00794     plane->AileronDecr ();
00795     break;
00796 
00797   case 'arai':
00798     // Aileron Right
00799     plane->AileronIncr ();
00800     break;
00801 
00802   case 'alrd':
00803     // Rudder Left
00804     plane->RudderDecr ();
00805     break;
00806 
00807   case 'arrd':
00808     // Rudder Right
00809     plane->RudderIncr ();
00810     break;
00811 
00812   case 'adtr':
00813     // Trim Elevator Down
00814     plane->ElevatorTrimDecr ();
00815     break;
00816 
00817   case 'autr':
00818     // Trim Elevator Up
00819     plane->ElevatorTrimIncr ();
00820     break;
00821 
00822   case 'atal':
00823     // Trim Aileron Left
00824     plane->AileronTrimDecr ();
00825     break;
00826 
00827   case 'atar':
00828     // Trim Aileron Right
00829     plane->AileronTrimIncr ();
00830     break;
00831 
00832   case 'atrl':
00833     // Trim Rudder Left
00834     plane->RudderTrimIncr ();
00835     break;
00836 
00837   case 'atlr':
00838     // Trim Rudder Right
00839     plane->RudderTrimIncr ();
00840     break;
00841 
00842   default:
00843     rc = false;
00844   }
00845 
00846   return rc;
00847 }
00848 
00849 
00850 static void BindAirplaneKeys (CKeyMap *keymap)
00851 {
00852   keymap->Bind ('adel', KeyAirplane);
00853   keymap->Bind ('auel', KeyAirplane);
00854   keymap->Bind ('arai', KeyAirplane);
00855   keymap->Bind ('alai', KeyAirplane);
00856   keymap->Bind ('alrd', KeyAirplane);
00857   keymap->Bind ('arrd', KeyAirplane);
00858   keymap->Bind ('actr', KeyAirplane);
00859   keymap->Bind ('acta', KeyAirplane);
00860   keymap->Bind ('autr', KeyAirplane);
00861   keymap->Bind ('adtr', KeyAirplane);
00862   keymap->Bind ('atal', KeyAirplane);
00863   keymap->Bind ('atar', KeyAirplane);
00864   keymap->Bind ('atrl', KeyAirplane);
00865   keymap->Bind ('atrr', KeyAirplane);
00866 
00867 /*
00868   'amfl' Mixture Full Lean
00869   'amfr' Mixture Full Rich
00870   'admx' Mixture Down
00871   'aimx' Mixture Up
00872   'amix' Mixture Power|Economy
00873   'appl' Prop Pitch Low
00874   'apph' Prop Pitch High
00875   'appd' Prop Pitch Decrease
00876   'appi' Prop Pitch Increase
00877   'amit' Throttle Off
00878   'amat' Throttle Full
00879   'adth' Throttle Down
00880   'aith' Throttle Up
00881   'adt2' Throttle Down (Alt.)
00882   'ait2' Throttle Up (Alt.)
00883   'arev' Reverse Thrust (On/Off)
00884   'beta' Beta Thrust (On/Off)
00885   'affu' Flaps (Full Up)
00886   'afrt' Flaps (Retract)
00887   'afex' Flaps (Extend)
00888   'affd' Flaps (Full Down)
00889   'actn' Coordinated Turn
00890   'abrk' Brakes (Ground)
00891   'pbrk' Brakes (Parking)
00892   'lbrk' Brakes (Left)
00893   'rbrk' Brakes (Right)
00894   'aabk' Brakes (Air)
00895   'aabm' Brakes (Air,Max)
00896   'aeng' Engine On/Off
00897   'aenf' Engine Focus (next)
00898   'aefp' Engine Focus (prev)
00899   'agtg' Gear Up/Down
00900   'agfd' Gear Down (Forced)
00901   'aspl' Extend/Retract Spoilers
00902   'aasp' Arm auto-spoilers
00903   'acht' Carburetor Heat On/Off
00904   'apht' Pitot Heat On/Off
00905   'alnd' Auto Land
00906   'aipa' Co-Pilot Abort
00907   'aprm' Engine Primer
00908   'acfg' Toggle Hi Lift Device
00909   'amag' Magneto switch
00910   'aifr' IFR Hood On/Off
00911   'apen' Autopilot Enable
00912   'aphg' Autopilot Hdg Hold
00913   'apal' Autopilot Alt Hold
00914   'apSy' Autopilot Sync
00915   'anlt' Lights (Navigation)
00916   'allt' Lights (Landing/Taxi)
00917   'acpl' Lights (Panel)
00918   'aadf' Select ADF
00919   'acom' Select COM radio
00920   'adme' Select DME
00921   'anav' Select NAV radio
00922   'atns' Select Transponder
00923   'aobs' Select OBS
00924   'rad1' Select Radio 1
00925   'rad2' Select Radio 2
00926   'rad3' Select Radio 3
00927   'rad4' Select Radio 4
00928 */
00929 }
00930 
00931 /*
00932  * Helicopter keys
00933  */
00934 
00935 /*
00936 KeySet 'heli' Helicopter Keys
00937   'fcyc' Fore Cyclic
00938   'acyc' Aft Cyclic
00939   'rcyc' Right Cyclic
00940   'lcyc' Left Cyclic
00941   'ltrt' Left Tail Rotor
00942   'rtrt' Right Tail Rotor
00943   'upcl' Up Collective
00944   'dncl' Down Collective
00945   'mfcy' Max Fore Cyclic
00946   'macy' Max Aft Cyclic
00947   'mrcy' Max Right Cyclic
00948   'mlcy' Max Left Cyclic
00949   'mltr' Max Left Tail Rotor
00950   'mrtr' Max Right Tail Rotor
00951   'mucl' Max Up Collective
00952   'mdcl' Max Down Collective
00953   'mvrt' Min Vertical Rate
00954   'zvrt' Zero Vertical Rate
00955   'altt' Altimeter Mode
00956   'hctr' Center Controls (Partial)
00957   'hcta' Center Controls (All)
00958   'hmit' Throttle Off
00959   'hmat' Throttle Full
00960   'hdth' Throttle Down
00961   'hith' Throttle Up
00962   'fcyT' Fore Cyclic Trim
00963   'acyT' Aft Cyclic Trim
00964   'rcyT' Right Cyclic Trim
00965   'lcyT' Left Cyclic Trim
00966   'ltrT' Left Tail Rotor Trim
00967   'rtrT' Right Tail Rotor Trim
00968   'upcT' Up Collective Trim
00969   'dncT' Down Collective Trim
00970 KeySet 'grnd' Ground Vehicle Keys
00971   'strl' Steer Left
00972   'strr' Steer Right
00973   'trup' Throttle Up
00974   'trdn' Throttle Down
00975   'maxs' Max Speed
00976   'mins' Min Speed
00977   'gctr' Center Controls (Partial)
00978   'gcta' Center Controls (All)
00979 */
00980 
00981 /*
00982  * Slew Keys
00983  */
00984 
00985 bool KeySlew (int id, int code, int mod)
00986 {
00987   CSlewManager *slew = globals->slewmgr;
00988   if (slew->IsEnabled ()) {
00989     slew->Disable ();
00990   } else {
00991     slew->Enable ();
00992   }
00993 
00994   return true;
00995 }
00996 
00997 bool KeySlewForward (int id, int code, int mod)
00998 {
00999   bool rc = false;
01000 
01001   CSlewManager *slew = globals->slewmgr;
01002 
01003   if (slew->IsEnabled ()) {
01004     slew->SetNorthRate (slew->GetNorthRate() + 1.0);
01005     rc = true;
01006   }
01007 
01008   return rc;
01009 }
01010 
01011 bool KeySlewBackward (int id, int code, int mod)
01012 {
01013   bool rc = false;
01014 
01015   CSlewManager *slew = globals->slewmgr;
01016 
01017   if (slew->IsEnabled ()) {
01018     slew->SetNorthRate (slew->GetNorthRate() - 1.0);
01019     rc = true;
01020   }
01021 
01022   return rc;
01023 }
01024 
01025 bool KeySlewLeft (int id, int code, int mod)
01026 {
01027   bool rc = false;
01028 
01029   CSlewManager *slew = globals->slewmgr;
01030 
01031   if (slew->IsEnabled ()) {
01032     slew->SetEastRate (slew->GetEastRate() - 1.0);
01033     rc = true;
01034   }
01035 
01036   return rc;
01037 }
01038 
01039 bool KeySlewRight (int id, int code, int mod)
01040 {
01041   bool rc = false;
01042 
01043   CSlewManager *slew = globals->slewmgr;
01044 
01045   if (slew->IsEnabled ()) {
01046     slew->SetEastRate (slew->GetEastRate() + 1.0);
01047     rc = true;
01048   }
01049 
01050   return rc;
01051 }
01052 
01053 bool KeySlewBankLeft (int id, int code, int mod)
01054 {
01055   bool rc = false;
01056 
01057   CSlewManager *slew = globals->slewmgr;
01058 
01059   if (slew->IsEnabled ()) {
01060     // Get current user vehicle orientation
01061     CVehicleObject *vehicle = globals->sit->GetUserVehicle();
01062     SVector v = vehicle->GetOrientation();
01063 
01064     // Update orientation
01065     v.h += DegToRad (1.0f);
01066     vehicle->SetOrientation (v);
01067 
01068     rc = true;
01069   }
01070 
01071   return rc;
01072 }
01073 
01074 bool KeySlewBankRight (int id, int code, int mod)
01075 {
01076   bool rc = false;
01077 
01078   CSlewManager *slew = globals->slewmgr;
01079 
01080   if (slew->IsEnabled ()) {
01081     // Get current user vehicle orientation
01082     CVehicleObject *vehicle = globals->sit->GetUserVehicle();
01083     SVector v = vehicle->GetOrientation();
01084 
01085     // Update orientation
01086     v.h += DegToRad (-1.0f);
01087     vehicle->SetOrientation (v);
01088 
01089     rc = true;
01090   }
01091 
01092   return rc;
01093 }
01094 
01095 bool KeySlewRotateLeft (int id, int code, int mod)
01096 {
01097   bool rc = false;
01098 
01099   CSlewManager *slew = globals->slewmgr;
01100 
01101   if (slew->IsEnabled ()) {
01102     // Get current user vehicle orientation
01103     CVehicleObject *vehicle = globals->sit->GetUserVehicle();
01104     SVector v = vehicle->GetOrientation();
01105 
01106     // Update orientation
01107     v.r += DegToRad (1.0f);
01108     vehicle->SetOrientation (v);
01109 
01110     rc = true;
01111   }
01112 
01113   return rc;
01114 }
01115 
01116 bool KeySlewRotateRight (int id, int code, int mod)
01117 {
01118   bool rc = false;
01119 
01120   CSlewManager *slew = globals->slewmgr;
01121 
01122   if (slew->IsEnabled ()) {
01123     // Get current user vehicle orientation
01124     CVehicleObject *vehicle = globals->sit->GetUserVehicle();
01125     SVector v = vehicle->GetOrientation();
01126 
01127     // Update orientation
01128     v.r += DegToRad (-1.0f);
01129     vehicle->SetOrientation (v);
01130 
01131     rc = true;
01132   }
01133 
01134   return rc;
01135 }
01136 
01137 bool KeySlewRotateLeft45 (int id, int code, int mod)
01138 {
01139   bool rc = false;
01140 
01141   CSlewManager *slew = globals->slewmgr;
01142 
01143   if (slew->IsEnabled ()) {
01144     // Get current user vehicle orientation
01145     CVehicleObject *vehicle = globals->sit->GetUserVehicle();
01146     SVector v = vehicle->GetOrientation();
01147 
01148     // Update orientation
01149     v.r += DegToRad (45.0f);
01150     vehicle->SetOrientation (v);
01151 
01152     rc = true;
01153   }
01154 
01155   return rc;
01156 }
01157 
01158 bool KeySlewRotateRight45 (int id, int code, int mod)
01159 {
01160   bool rc = false;
01161 
01162   CSlewManager *slew = globals->slewmgr;
01163 
01164   if (slew->IsEnabled ()) {
01165     // Get current user vehicle orientation
01166     CVehicleObject *vehicle = globals->sit->GetUserVehicle();
01167     SVector v = vehicle->GetOrientation();
01168 
01169     // Update orientation
01170     v.r += DegToRad (-45.0f);
01171     vehicle->SetOrientation (v);
01172 
01173     rc = true;
01174   }
01175 
01176   return rc;
01177 }
01178 
01179 bool KeySlewPitchUp (int id, int code, int mod)
01180 {
01181   bool rc = false;
01182 
01183   CSlewManager *slew = globals->slewmgr;
01184 
01185   if (slew->IsEnabled ()) {
01186     // Get current user vehicle orientation
01187     CVehicleObject *vehicle = globals->sit->GetUserVehicle();
01188     SVector v = vehicle->GetOrientation();
01189 
01190     // Update orientation
01191     v.p += DegToRad (-1.0f);
01192     vehicle->SetOrientation (v);
01193 
01194     rc = true;
01195   }
01196 
01197   DrawNoticeToUser ("Slew pitch up", 1);
01198   return rc;
01199 }
01200 
01201 bool KeySlewPitchDown (int id, int code, int mod)
01202 {
01203   bool rc = false;
01204 
01205   CSlewManager *slew = globals->slewmgr;
01206 
01207   if (slew->IsEnabled ()) {
01208     // Get current user vehicle orientation
01209     CVehicleObject *vehicle = globals->sit->GetUserVehicle();
01210     SVector v = vehicle->GetOrientation();
01211 
01212     // Update orientation
01213     v.p += DegToRad (1.0f);
01214     vehicle->SetOrientation (v);
01215 
01216     rc = true;
01217   }
01218 
01219   DrawNoticeToUser ("Slew pitch down", 1);
01220   return rc;
01221 }
01222 
01223 bool KeySlewUp (int id, int code, int mod)
01224 {
01225   bool rc = false;
01226 
01227   CSlewManager *slew = globals->slewmgr;
01228 
01229   if (slew->IsEnabled ()) {
01230     slew->SetAltRate (slew->GetAltRate() + 10.0);
01231     rc = true;
01232   }
01233 
01234   return rc;
01235 }
01236 
01237 bool KeySlewDown (int id, int code, int mod)
01238 {
01239   bool rc = false;
01240 
01241   CSlewManager *slew = globals->slewmgr;
01242 
01243   if (slew->IsEnabled ()) {
01244     slew->SetAltRate (slew->GetAltRate() - 10.0);
01245     rc = true;
01246   }
01247 
01248   return rc;
01249 }
01250 
01251 bool KeySlewReorient (int id, int code, int mod)
01252 {
01253   bool rc = false;
01254 
01255   CSlewManager *slew = globals->slewmgr;
01256 
01257   if (slew->IsEnabled ()) {
01259     rc = true;
01260   }
01261 
01262   return rc;
01263 }
01264 
01265 bool KeySlewStop (int id, int code, int mod)
01266 {
01267   bool rc = false;
01268 
01269   CSlewManager *slew = globals->slewmgr;
01270 
01271   if (slew->IsEnabled ()) {
01272     slew->ZeroRate ();
01273     rc = true;
01274   }
01275 
01276   return rc;
01277 }
01278 
01279 static void BindSlewKeys (CKeyMap *keymap)
01280 {
01281   keymap->Bind ('slew', KeySlew);
01282   keymap->Bind ('sfwd', KeySlewForward);
01283   keymap->Bind ('sbkw', KeySlewBackward);
01284   keymap->Bind ('slft', KeySlewLeft);
01285   keymap->Bind ('srgt', KeySlewRight);
01286   keymap->Bind ('sbnl', KeySlewBankLeft);
01287   keymap->Bind ('sbnr', KeySlewBankRight);
01288   keymap->Bind ('srtl', KeySlewRotateLeft);
01289   keymap->Bind ('srtr', KeySlewRotateRight);
01290   keymap->Bind ('srl4', KeySlewRotateLeft45);
01291   keymap->Bind ('srr4', KeySlewRotateRight45);
01292   keymap->Bind ('sptu', KeySlewPitchUp);
01293   keymap->Bind ('sptd', KeySlewPitchDown);
01294   keymap->Bind ('slup', KeySlewUp);
01295   keymap->Bind ('sldn', KeySlewDown);
01296   keymap->Bind ('sreo', KeySlewReorient);
01297   keymap->Bind ('sstp', KeySlewStop);
01298 }
01299 
01300 
01301 /*
01302  * Debug Keys
01303  */
01304 
01305 /*
01306   KeySet 'dbug' Debug Keys
01307   'grph' Graph
01308   'dbps' Debug Pause
01309   'dbss' Debug Single Step
01310   'aipl' AI Pilot
01311   'wpln' Weapon Launch
01312   'pttr' Pitch Trim
01313   'hovr' Hover
01314   'ahld' Altitude Hold
01315   'hhld' Heading Hold
01316   'phld' Pitch Hold
01317   'bhld' Bank Hold
01318   'shld' Speed Hold
01319   'aagl' Altitude AGL Hold
01320   'vrhl' Vertical Rate Hold
01321   'albu' Altitude Bump Up
01322   'hdbu' Heading Bump Up
01323   'ptbu' Pitch Bump Up
01324   'bnbu' Bank Bump Up
01325   'spbu' Speed Bump Up
01326   'aabu' Altitude AGL Bump Up
01327   'vrbu' Vertical Rate BumpUp
01328   'mxvr' Max Vertical Rate
01329   'albd' Altitude Bump Down
01330   'hdbd' Heading Bump Down
01331   'ptbd' Pitch Bump Down
01332   'bbdn' Bank Bump Down
01333   'spbd' Speed Bump Down
01334   'aabd' Altitude AGL Bump Dn
01335   'vrbd' Vertical Rate BumpDn
01336   'push' Push
01337   'pshb' Push Back
01338   'mrep' Memory report
01339   'clon' Clone
01340   'kill' Kill
01341 KeySet 'misc' Misc Vehicle Keys
01342   'vvup' Virtual View Up
01343   'vvdn' Virtual View Down
01344   'vvlt' Virtual View Left
01345   'vvrt' Virtual View Right
01346   'mids' Mid Speed
01347   'away' Add Waypoint
01348 */
01349 
01350 
01351 void BindAllKeys (CKeyMap *keymap)
01352 {
01353   BindMenuKeys (keymap);
01354   BindGlobalKeys (keymap);
01355   BindCameraKeys (keymap);
01356   BindAirplaneKeys (keymap);
01357   BindSlewKeys (keymap);
01358 }
01359 
01360 /*
01361  * Keyboard input handlers
01362  */
01363 
01364 //
01365 // This table is a simple mapping of GLUT key codes to FlyLegacy key codes.
01366 //
01367 typedef struct {
01368   int           glut;
01369   EKeyboardKeys flylegacy;
01370 } SGlutToFlyLegacyKey;
01371 
01373 SGlutToFlyLegacyKey glutKeyMap[] =
01374 {
01375   // Control keys
01376   { 1,            KB_KEY_A },
01377   { 2,            KB_KEY_B },
01378   { 3,            KB_KEY_C },
01379   { 4,            KB_KEY_D },
01380   { 5,            KB_KEY_E },
01381   { 6,            KB_KEY_F },
01382   { 7,            KB_KEY_G },
01383   { 8,            KB_KEY_H },
01384   { 9,            KB_KEY_I },
01385   { 10,           KB_KEY_J },
01386   { 11,           KB_KEY_K },
01387   { 12,           KB_KEY_L },
01388   { 13,           KB_KEY_M },
01389   { 14,           KB_KEY_N },
01390   { 15,           KB_KEY_O },
01391   { 16,           KB_KEY_P },
01392   { 17,           KB_KEY_Q },
01393   { 18,           KB_KEY_R },
01394   { 19,           KB_KEY_S },
01395   { 20,           KB_KEY_T },
01396   { 21,           KB_KEY_U },
01397   { 22,           KB_KEY_V },
01398   { 23,           KB_KEY_W },
01399   { 24,           KB_KEY_X },
01400   { 25,           KB_KEY_Y },
01401   { 26,           KB_KEY_Z },
01402 
01403   // Top row
01404   { 27,           KB_KEY_ESC },
01405   { '`',          KB_KEY_REVERSE_SINGLE_QUOTE },
01406   { '1',          KB_KEY_1 },
01407   { '2',          KB_KEY_2 },
01408   { '3',          KB_KEY_3 },
01409   { '4',          KB_KEY_4 },
01410   { '5',          KB_KEY_5  },
01411   { '6',          KB_KEY_6 },
01412   { '7',          KB_KEY_7 },
01413   { '8',          KB_KEY_8 },
01414   { '9',          KB_KEY_9 },
01415   { '0',          KB_KEY_0 },
01416   { '-',          KB_KEY_MINUS },
01417   { '=',          KB_KEY_EQUALS },
01418 
01419   // Shifted top row
01420   { '~',          KB_KEY_REVERSE_SINGLE_QUOTE },
01421   { '!',          KB_KEY_1 },
01422   { '@',          KB_KEY_2 },
01423   { '#',          KB_KEY_3 },
01424   { '$',          KB_KEY_4 },
01425   { '%',          KB_KEY_5  },
01426   { '^',          KB_KEY_6 },
01427   { '&',          KB_KEY_7 },
01428   { '*',          KB_KEY_8 },
01429   { '(',          KB_KEY_9 },
01430   { ')',          KB_KEY_0 },
01431   { '_',          KB_KEY_MINUS },
01432   { '+',          KB_KEY_EQUALS },
01433 
01434   // Second row
01435   { '\t',         KB_KEY_TAB },
01436   { 'q',          KB_KEY_Q },
01437   { 'w',          KB_KEY_W },
01438   { 'e',          KB_KEY_E },
01439   { 'r',          KB_KEY_R },
01440   { 't',          KB_KEY_T },
01441   { 'y',          KB_KEY_Y },
01442   { 'u',          KB_KEY_U },
01443   { 'i',          KB_KEY_I },
01444   { 'o',          KB_KEY_O },
01445   { 'p',          KB_KEY_P },
01446   { '[',          KB_KEY_FORWARD_BRACKET },
01447   { ']',          KB_KEY_REVERSE_BRACKET },
01448   { '\\',         KB_KEY_BACKSLASH },
01449 
01450   // Shifted second row
01451   { 'Q',          KB_KEY_Q },
01452   { 'W',          KB_KEY_W },
01453   { 'E',          KB_KEY_E },
01454   { 'R',          KB_KEY_R },
01455   { 'T',          KB_KEY_T },
01456   { 'Y',          KB_KEY_Y },
01457   { 'U',          KB_KEY_U },
01458   { 'I',          KB_KEY_I },
01459   { 'O',          KB_KEY_O },
01460   { 'P',          KB_KEY_P },
01461   { '{',          KB_KEY_FORWARD_BRACKET },
01462   { '}',          KB_KEY_REVERSE_BRACKET },
01463   { '|',          KB_KEY_BACKSLASH },
01464 
01465   // Third row
01466   { 'a',          KB_KEY_A },
01467   { 's',          KB_KEY_S },
01468   { 'd',          KB_KEY_D },
01469   { 'f',          KB_KEY_F },
01470   { 'g',          KB_KEY_G },
01471   { 'h',          KB_KEY_H },
01472   { 'j',          KB_KEY_J },
01473   { 'k',          KB_KEY_K },
01474   { 'l',          KB_KEY_L },
01475   { ';',          KB_KEY_SEMI_COLON },
01476   { '\'',         KB_KEY_SINGLE_QUOTE},
01477   { '\13',        KB_KEY_ENTER},
01478 
01479   // Shifted third row
01480   { 'A',          KB_KEY_A },
01481   { 'S',          KB_KEY_S },
01482   { 'D',          KB_KEY_D },
01483   { 'F',          KB_KEY_F },
01484   { 'G',          KB_KEY_G },
01485   { 'H',          KB_KEY_H },
01486   { 'J',          KB_KEY_J },
01487   { 'K',          KB_KEY_K },
01488   { 'L',          KB_KEY_L },
01489   { ':',          KB_KEY_SEMI_COLON },
01490   { '\"',         KB_KEY_SINGLE_QUOTE},
01491 
01492   // Fourth row
01493   { 'z',          KB_KEY_Z },
01494   { 'x',          KB_KEY_X },
01495   { 'c',          KB_KEY_C },
01496   { 'v',          KB_KEY_V },
01497   { 'b',          KB_KEY_B },
01498   { 'n',          KB_KEY_N },
01499   { 'm',          KB_KEY_M },
01500   { ',',          KB_KEY_COMMA },
01501   { '.',          KB_KEY_PERIOD },
01502   { '/',          KB_KEY_SLASH },
01503 
01504   // Shifted fourth row
01505   { 'Z',          KB_KEY_Z },
01506   { 'X',          KB_KEY_X },
01507   { 'C',          KB_KEY_C },
01508   { 'V',          KB_KEY_V },
01509   { 'B',          KB_KEY_B },
01510   { 'N',          KB_KEY_N },
01511   { 'M',          KB_KEY_M },
01512   { '<',          KB_KEY_COMMA },
01513   { '>',          KB_KEY_PERIOD },
01514   { '?',          KB_KEY_SLASH },
01515 
01516   // Space
01517   { ' ',          KB_KEY_SPACE },
01518 };
01519 
01520 SGlutToFlyLegacyKey glutSpecialMap[] =
01521 {
01522   { GLUT_KEY_F1,      KB_KEY_F1 },
01523   { GLUT_KEY_F2,      KB_KEY_F2 },
01524   { GLUT_KEY_F3,      KB_KEY_F3 },
01525   { GLUT_KEY_F4,      KB_KEY_F4 },
01526   { GLUT_KEY_F5,      KB_KEY_F5 },
01527   { GLUT_KEY_F6,      KB_KEY_F6 },
01528   { GLUT_KEY_F7,      KB_KEY_F7 },
01529   { GLUT_KEY_F8,      KB_KEY_F8 },
01530   { GLUT_KEY_F9,      KB_KEY_F9 },
01531   { GLUT_KEY_F10,     KB_KEY_F10 },
01532   { GLUT_KEY_F11,     KB_KEY_F11 },
01533   { GLUT_KEY_F12,     KB_KEY_F12 },
01534   { GLUT_KEY_HOME,    KB_KEY_HOME },
01535   { GLUT_KEY_UP,      KB_KEY_UP },
01536   { GLUT_KEY_PAGE_UP,   KB_KEY_PGUP },
01537   { GLUT_KEY_LEFT,    KB_KEY_LEFT },
01538   { GLUT_KEY_RIGHT,   KB_KEY_RIGHT },
01539   { GLUT_KEY_END,     KB_KEY_END },
01540   { GLUT_KEY_DOWN,    KB_KEY_DOWN },
01541   { GLUT_KEY_PAGE_DOWN, KB_KEY_PGDN },
01542   { GLUT_KEY_INSERT,    KB_KEY_INSERT },
01543   { 127,          KB_KEY_DEL }
01544 };
01545 
01546 SGlutToFlyLegacyKey glutKeyboard[128];
01547 SGlutToFlyLegacyKey glutSpecial[128];
01548 
01549 EKeyboardModifiers glutModifiersToFlyLegacyModifiers (int glutmod)
01550 {
01551   int flymod = KB_MODIFIER_NONE;
01552   if (glutmod & GLUT_ACTIVE_SHIFT) flymod |= KB_MODIFIER_SHIFT;
01553   if (glutmod & GLUT_ACTIVE_CTRL) flymod |= KB_MODIFIER_CTRL;
01554   if (glutmod & GLUT_ACTIVE_ALT) flymod |= KB_MODIFIER_ALT;
01555 
01556   return (EKeyboardModifiers)flymod;
01557 }
01558 
01559 
01560 bool glutKeyToFlyLegacyKey (int glutkey, EKeyboardKeys *flykey)
01561 {
01562   *flykey = glutKeyboard[glutkey].flylegacy;
01563 
01564 //  char debug[80];
01565 //  sprintf (debug, "glut=%d flylegacy=%d", glutkey, *flykey);
01566 //  DrawNoticeToUser (debug, 2);
01567 
01568   return (*flykey != KB_KEY_META);
01569 }
01570 
01571 
01572 bool glutSpecialToFlyLegacyKey (int glutkey, EKeyboardKeys *flykey)
01573 {
01574   *flykey = glutSpecial[glutkey].flylegacy;
01575 
01576 //  char debug[80];
01577 //  sprintf (debug, "glut=%d flylegacy=%d", glutkey, *flykey);
01578 //  DrawNoticeToUser (debug, 2);
01579 
01580   return (*flykey != KB_KEY_META);
01581 }
01582 
01583 
01584 /*
01585  * Keyboard initialization
01586  *
01587  * This function must be called prior to any keyboard events being handled
01588  */
01589 
01590 void init_keyboard (void)
01591 {
01592   int i;
01593 
01594   // Load key mappings
01595   globals->keymap = new CKeyMap ("System\\default.key");
01596   BindAllKeys (globals->keymap);
01597 
01598   // Initialize all entries in GLUT->FlyLegacy mapping tables to META (unused)
01599   for (i=0; i<128; i++) {
01600     glutKeyboard[i].glut = i;
01601     glutKeyboard[i].flylegacy = KB_KEY_META;
01602     glutSpecial[i].glut = i;
01603     glutSpecial[i].flylegacy = KB_KEY_META;
01604   }
01605 
01606   // Now set all values specified in the actual maps
01607   int nKeys = sizeof (glutKeyMap) / sizeof (SGlutToFlyLegacyKey);
01608   for (i=0; i<nKeys; i++) {
01609     glutKeyboard[glutKeyMap[i].glut].flylegacy = glutKeyMap[i].flylegacy;
01610   }
01611 
01612   int nSpecialKeys = sizeof (glutSpecialMap) / sizeof (SGlutToFlyLegacyKey);
01613   for (i=0; i<nSpecialKeys; i++) {
01614     glutSpecial[glutSpecialMap[i].glut].flylegacy = glutSpecialMap[i].flylegacy;
01615   }
01616 }
01617 
SourceForge.net Logo Documentation generated by doxygen