]> git.mxchange.org Git - flightgear.git/blob - Main/GLUTkey.cxx
Added support for switching between fullscreen and window mode for
[flightgear.git] / Main / GLUTkey.cxx
1 /**************************************************************************
2  * GLUTkey.c -- handle GLUT keyboard events
3  *
4  * Written by Curtis Olson, started May 1997.
5  *
6  * Copyright (C) 1997  Curtis L. Olson  - curt@infoplane.com
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of the
11  * License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  *
22  * $Id$
23  * (Log is kept at end of this file)
24  **************************************************************************/
25
26
27 #ifdef HAVE_CONFIG_H
28 #  include <config.h>
29 #endif
30
31 #ifdef HAVE_WINDOWS_H
32 #  include <windows.h>                     
33 #endif
34
35 #include <GL/glut.h>
36 #include <XGL/xgl.h>
37 #include <stdio.h>
38 #include <stdlib.h>
39
40 #include <Aircraft/aircraft.h>
41 #include <Autopilot/autopilot.h> // Added autopilot.h to list, Jeff Goeke-Smith
42 #include <Debug/fg_debug.h>
43 #include <GUI/gui.h>
44 #include <Include/fg_constants.h>
45 #include <PUI/pu.h>
46 #include <Weather/weather.h>
47
48 #include "GLUTkey.hxx"
49 #include "options.hxx"
50 #include "views.hxx"
51
52 #if defined(FX) && defined(XMESA)
53 #  include <GL/xmesa.h>
54    static int fullscreen = 1;
55 #endif
56
57 /* Handle keyboard events */
58 void GLUTkey(unsigned char k, int x, int y) {
59     fgCONTROLS *c;
60     fgOPTIONS *o;
61     fgTIME *t;
62     fgVIEW *v;
63     struct fgWEATHER *w;
64     float tmp;
65
66     c = current_aircraft.controls;
67     o = &current_options;
68     t = &cur_time_params;
69     v = &current_view;
70     w = &current_weather;
71
72     fgPrintf( FG_INPUT, FG_DEBUG, "Key hit = %d", k);
73     puKeyboard(k, PU_DOWN );
74
75     if ( GLUT_ACTIVE_ALT && glutGetModifiers() ) {
76         fgPrintf( FG_INPUT, FG_DEBUG, " SHIFTED\n");
77         switch (k) {
78         case 49: /* numeric keypad 1 */
79             v->goal_view_offset = FG_PI * 0.75;
80             return;
81         case 50: /* numeric keypad 2 */
82             v->goal_view_offset = FG_PI;
83             return;
84         case 51: /* numeric keypad 3 */
85             v->goal_view_offset = FG_PI * 1.25;
86             return;
87         case 52: /* numeric keypad 4 */
88             v->goal_view_offset = FG_PI * 0.50;
89             return;
90         case 54: /* numeric keypad 6 */
91             v->goal_view_offset = FG_PI * 1.50;
92             return;
93         case 55: /* numeric keypad 7 */
94             v->goal_view_offset = FG_PI * 0.25;
95             return;
96         case 56: /* numeric keypad 8 */
97             v->goal_view_offset = 0.00;
98             return;
99         case 57: /* numeric keypad 9 */
100             v->goal_view_offset = FG_PI * 1.75;
101             return;
102         case 72: /* H key */
103             o->hud_status = !(o->hud_status);
104             return;
105         case 77: /* M key */
106             t->warp -= 60;
107             return;
108         case 84: /* T key */
109             t->warp_delta -= 30;
110             return;
111         case 87: /* W key */
112 #if defined(FX) && !defined(WIN32)
113             fullscreen = ( !fullscreen );
114             XMesaSetFXmode(fullscreen ? XMESA_FX_FULLSCREEN : XMESA_FX_WINDOW);
115 #endif
116             return;
117         case 88: /* X key */
118             o->fov *= 1.05;
119             if ( o->fov > FG_FOV_MAX ) {
120                 o->fov = FG_FOV_MAX;
121             }
122             v->update_fov = TRUE;
123             return;
124         case 90: /* Z key */
125             tmp = fgWeatherGetVisibility();   /* in meters */
126             tmp /= 1.10;
127             fgWeatherSetVisibility( tmp );
128             return;
129         // autopilot additions
130         case 65: /* A key */
131                 fgAPSetMode(1);
132                 return;
133         case 83: /* S key */
134                 fgAPSetMode(0);
135                 return;
136         case 68: /* D key */
137                 fgAPSetHeading(AP_CURRENT_HEADING);
138                 return;
139         }
140     } else {
141         fgPrintf( FG_INPUT, FG_DEBUG, "\n");
142         switch (k) {
143         case 50: /* numeric keypad 2 */
144             fgElevMove(-0.05);
145             return;
146         case 56: /* numeric keypad 8 */
147             fgElevMove(0.05);
148             return;
149         case 49: /* numeric keypad 1 */
150             fgElevTrimMove(-0.001);
151             return;
152         case 55: /* numeric keypad 7 */
153             fgElevTrimMove(0.001);
154             return;
155         case 52: /* numeric keypad 4 */
156             fgAileronMove(-0.05);
157             return;
158         case 54: /* numeric keypad 6 */
159             fgAileronMove(0.05);
160             return;
161         case 48: /* numeric keypad Ins */
162             fgRudderMove(-0.05);
163             return;
164         case 13: /* numeric keypad Enter */
165             fgRudderMove(0.05);
166             return;
167         case 53: /* numeric keypad 5 */
168             fgAileronSet(0.0);
169             fgElevSet(0.0);
170             fgRudderSet(0.0);
171             return;
172         case 57: /* numeric keypad 9 (Pg Up) */
173             fgThrottleMove(0, 0.01);
174             return;
175         case 51: /* numeric keypad 3 (Pg Dn) */
176             fgThrottleMove(0, -0.01);
177             return;
178         case 109: /* m key */
179             t->warp += 60;
180             return;
181         case 116: /* t key */
182             t->warp_delta += 30;
183             return;
184         case 120: /* X key */
185             o->fov /= 1.05;
186             if ( o->fov < FG_FOV_MIN ) {
187                 o->fov = FG_FOV_MIN;
188             }
189             v->update_fov = TRUE;
190             return;
191         case 122: /* z key */
192             tmp = fgWeatherGetVisibility();   /* in meters */
193             tmp *= 1.10;
194             fgWeatherSetVisibility( tmp );
195             return;
196         case 27: /* ESC */
197             // if( fg_DebugOutput ) {
198             //   fclose( fg_DebugOutput );
199             // }
200             fgPrintf( FG_INPUT, FG_EXIT, 
201                       "Program exiting normally at user request.\n");
202         }
203     }
204 }
205
206
207 /* Handle "special" keyboard events */
208 void GLUTspecialkey(int k, int x, int y) {
209     fgCONTROLS *c;
210     fgVIEW *v;
211
212     c = current_aircraft.controls;
213     v = &current_view;
214
215     fgPrintf( FG_INPUT, FG_DEBUG, "Special key hit = %d", k);
216     puKeyboard(k + PU_KEY_GLUT_SPECIAL_OFFSET, PU_DOWN);
217
218     if ( GLUT_ACTIVE_SHIFT && glutGetModifiers() ) {
219         fgPrintf( FG_INPUT, FG_DEBUG, " SHIFTED\n");
220         switch (k) {
221         case GLUT_KEY_END: /* numeric keypad 1 */
222             v->goal_view_offset = FG_PI * 0.75;
223             return;
224         case GLUT_KEY_DOWN: /* numeric keypad 2 */
225             v->goal_view_offset = FG_PI;
226             return;
227         case GLUT_KEY_PAGE_DOWN: /* numeric keypad 3 */
228             v->goal_view_offset = FG_PI * 1.25;
229             return;
230         case GLUT_KEY_LEFT: /* numeric keypad 4 */
231             v->goal_view_offset = FG_PI * 0.50;
232             return;
233         case GLUT_KEY_RIGHT: /* numeric keypad 6 */
234             v->goal_view_offset = FG_PI * 1.50;
235             return;
236         case GLUT_KEY_HOME: /* numeric keypad 7 */
237             v->goal_view_offset = FG_PI * 0.25;
238             return;
239         case GLUT_KEY_UP: /* numeric keypad 8 */
240             v->goal_view_offset = 0.00;
241             return;
242         case GLUT_KEY_PAGE_UP: /* numeric keypad 9 */
243             v->goal_view_offset = FG_PI * 1.75;
244             return;
245         }
246     } else {
247         fgPrintf( FG_INPUT, FG_DEBUG, "\n");
248         switch (k) {
249         case GLUT_KEY_F10: /* F10 toggles menu on and off... */
250             printf("Invoking call back function");
251             hideMenuButton -> 
252                 setValue ((int) !(hideMenuButton -> getValue() ) );
253             hideMenuButton -> invokeCallback();
254             //exit(1);
255             return;
256         case GLUT_KEY_UP:
257             fgElevMove(0.05);
258             return;
259         case GLUT_KEY_DOWN:
260             fgElevMove(-0.05);
261             return;
262         case GLUT_KEY_LEFT:
263             fgAileronMove(-0.05);
264             return;
265         case GLUT_KEY_RIGHT:
266             fgAileronMove(0.05);
267             return;
268         case GLUT_KEY_HOME: /* numeric keypad 1 */
269             fgElevTrimMove(0.001);
270             return;
271         case GLUT_KEY_END: /* numeric keypad 7 */
272             fgElevTrimMove(-0.001);
273             return;
274         case GLUT_KEY_INSERT: /* numeric keypad Ins */
275             fgRudderMove(-0.05);
276             return;
277         case 13: /* numeric keypad Enter */
278             fgRudderMove(0.05);
279             return;
280         case 53: /* numeric keypad 5 */
281             fgAileronSet(0.0);
282             fgElevSet(0.0);
283             fgRudderSet(0.0);
284             return;
285         case GLUT_KEY_PAGE_UP: /* numeric keypad 9 (Pg Up) */
286             fgThrottleMove(0, 0.01);
287             return;
288         case GLUT_KEY_PAGE_DOWN: /* numeric keypad 3 (Pg Dn) */
289             fgThrottleMove(0, -0.01);
290             return;
291         }
292     }
293 }
294
295
296 /* $Log$
297 /* Revision 1.14  1998/07/06 02:42:02  curt
298 /* Added support for switching between fullscreen and window mode for
299 /* Mesa/3dfx/glide.
300 /*
301 /* Added a basic splash screen.  Restructured the main loop and top level
302 /* initialization routines to do this.
303 /*
304 /* Hacked in some support for playing a startup mp3 sound file while rest
305 /* of sim initializes.  Currently only works in Unix using the mpg123 player.
306 /* Waits for the mpg123 player to finish before initializing internal
307 /* sound drivers.
308 /*
309  * Revision 1.13  1998/06/27 16:54:32  curt
310  * Replaced "extern displayInstruments" with a entry in fgOPTIONS.
311  * Don't change the view port when displaying the panel.
312  *
313  * Revision 1.12  1998/06/12 14:27:26  curt
314  * Pui -> PUI, Gui -> GUI.
315  *
316  * Revision 1.11  1998/06/12 00:57:38  curt
317  * Added support for Pui/Gui.
318  * Converted fog to GL_FOG_EXP2.
319  * Link to static simulator parts.
320  * Update runfg.bat to try to be a little smarter.
321  *
322  * Revision 1.10  1998/05/27 02:24:05  curt
323  * View optimizations by Norman Vine.
324  *
325  * Revision 1.9  1998/05/16 13:05:21  curt
326  * Added limits to fov.
327  *
328  * Revision 1.8  1998/05/13 18:29:56  curt
329  * Added a keyboard binding to dynamically adjust field of view.
330  * Added a command line option to specify fov.
331  * Adjusted terrain color.
332  * Root path info moved to fgOPTIONS.
333  * Added ability to parse options out of a config file.
334  *
335  * Revision 1.7  1998/05/07 23:14:14  curt
336  * Added "D" key binding to set autopilot heading.
337  * Made frame rate calculation average out over last 10 frames.
338  * Borland C++ floating point exception workaround.
339  * Added a --tile-radius=n option.
340  *
341  * Revision 1.6  1998/04/28 01:20:20  curt
342  * Type-ified fgTIME and fgVIEW.
343  * Added a command line option to disable textures.
344  *
345  * Revision 1.5  1998/04/25 22:06:29  curt
346  * Edited cvs log messages in source files ... bad bad bad!
347  *
348  * Revision 1.4  1998/04/25 20:24:00  curt
349  * Cleaned up initialization sequence to eliminate interdependencies
350  * between sun position, lighting, and view position.  This creates a
351  * valid single pass initialization path.
352  *
353  * Revision 1.3  1998/04/24 14:19:29  curt
354  * Fog tweaks.
355  *
356  * Revision 1.2  1998/04/24 00:49:17  curt
357  * Wrapped "#include <config.h>" in "#ifdef HAVE_CONFIG_H"
358  * Trying out some different option parsing code.
359  * Some code reorganization.
360  *
361  * Revision 1.1  1998/04/22 13:25:40  curt
362  * C++ - ifing the code.
363  * Starting a bit of reorganization of lighting code.
364  *
365  * Revision 1.33  1998/04/18 04:11:25  curt
366  * Moved fg_debug to it's own library, added zlib support.
367  *
368  * Revision 1.32  1998/04/14 02:21:01  curt
369  * Incorporated autopilot heading hold contributed by:  Jeff Goeke-Smith
370  * <jgoeke@voyager.net>
371  *
372  * Revision 1.31  1998/04/08 23:34:05  curt
373  * Patch from Durk to fix trim reversal with numlock key active.
374  *
375  * Revision 1.30  1998/04/03 22:09:02  curt
376  * Converting to Gnu autoconf system.
377  *
378  * Revision 1.29  1998/02/07 15:29:40  curt
379  * Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
380  * <chotchkiss@namg.us.anritsu.com>
381  *
382  * Revision 1.28  1998/02/03 23:20:23  curt
383  * Lots of little tweaks to fix various consistency problems discovered by
384  * Solaris' CC.  Fixed a bug in fg_debug.c with how the fgPrintf() wrapper
385  * passed arguments along to the real printf().  Also incorporated HUD changes
386  * by Michele America.
387  *
388  * Revision 1.27  1998/01/27 00:47:55  curt
389  * Incorporated Paul Bleisch's <pbleisch@acm.org> new debug message
390  * system and commandline/config file processing code.
391  *
392  * Revision 1.26  1998/01/19 19:27:07  curt
393  * Merged in make system changes from Bob Kuehne <rpk@sgi.com>
394  * This should simplify things tremendously.
395  *
396  * Revision 1.25  1998/01/05 18:44:34  curt
397  * Add an option to advance/decrease time from keyboard.
398  *
399  * Revision 1.24  1997/12/30 16:36:46  curt
400  * Merged in Durk's changes ...
401  *
402  * Revision 1.23  1997/12/15 23:54:44  curt
403  * Add xgl wrappers for debugging.
404  * Generate terrain normals on the fly.
405  *
406  * Revision 1.22  1997/12/10 22:37:45  curt
407  * Prepended "fg" on the name of all global structures that didn't have it yet.
408  * i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
409  *
410  * Revision 1.21  1997/08/27 21:32:23  curt
411  * Restructured view calculation code.  Added stars.
412  *
413  * Revision 1.20  1997/08/27 03:30:13  curt
414  * Changed naming scheme of basic shared structures.
415  *
416  * Revision 1.19  1997/08/25 20:27:21  curt
417  * Merged in initial HUD and Joystick code.
418  *
419  * Revision 1.18  1997/08/22 21:34:38  curt
420  * Doing a bit of reorganizing and house cleaning.
421  *
422  * Revision 1.17  1997/07/19 22:34:02  curt
423  * Moved PI definitions to ../constants.h
424  * Moved random() stuff to ../Utils/ and renamed fg_random()
425  *
426  * Revision 1.16  1997/07/18 23:41:24  curt
427  * Tweaks for building with Cygnus Win32 compiler.
428  *
429  * Revision 1.15  1997/07/16 20:04:47  curt
430  * Minor tweaks to aid Win32 port.
431  *
432  * Revision 1.14  1997/07/12 03:50:20  curt
433  * Added an #include <Windows32/Base.h> to help compiling for Win32
434  *
435  * Revision 1.13  1997/06/25 15:39:46  curt
436  * Minor changes to compile with rsxnt/win32.
437  *
438  * Revision 1.12  1997/06/21 17:12:52  curt
439  * Capitalized subdirectory names.
440  *
441  * Revision 1.11  1997/06/18 04:10:31  curt
442  * A couple more runway tweaks ...
443  *
444  * Revision 1.10  1997/06/18 02:21:23  curt
445  * Hacked in a runway
446  *
447  * Revision 1.9  1997/06/02 03:40:06  curt
448  * A tiny bit more view tweaking.
449  *
450  * Revision 1.8  1997/06/02 03:01:38  curt
451  * Working on views (side, front, back, transitions, etc.)
452  *
453  * Revision 1.7  1997/05/31 19:16:25  curt
454  * Elevator trim added.
455  *
456  * Revision 1.6  1997/05/31 04:13:52  curt
457  * WE CAN NOW FLY!!!
458  *
459  * Continuing work on the LaRCsim flight model integration.
460  * Added some MSFS-like keyboard input handling.
461  *
462  * Revision 1.5  1997/05/30 23:26:19  curt
463  * Added elevator/aileron controls.
464  *
465  * Revision 1.4  1997/05/27 17:44:31  curt
466  * Renamed & rearranged variables and routines.   Added some initial simple
467  * timer/alarm routines so the flight model can be updated on a regular 
468  * interval.
469  *
470  * Revision 1.3  1997/05/23 15:40:25  curt
471  * Added GNU copyright headers.
472  * Fog now works!
473  *
474  * Revision 1.2  1997/05/23 00:35:12  curt
475  * Trying to get fog to work ...
476  *
477  * Revision 1.1  1997/05/21 15:57:50  curt
478  * Renamed due to added GLUT support.
479  *
480  * Revision 1.2  1997/05/19 18:22:41  curt
481  * Parameter tweaking ... starting to stub in fog support.
482  *
483  * Revision 1.1  1997/05/16 16:05:51  curt
484  * Initial revision.
485  *
486  */