]> git.mxchange.org Git - flightgear.git/blob - src/Input/input.cxx
ebbc2a62e9ecb9583ada73fcd6de1c8e3294c1d0
[flightgear.git] / src / Input / input.cxx
1 // input.cxx -- handle user input from various sources.
2 //
3 // Written by David Megginson, started May 2001.
4 //
5 // Copyright (C) 2001 David Megginson, david@megginson.com
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 #ifdef HAVE_CONFIG_H
24 #  include <config.h>
25 #endif
26
27 #ifdef HAVE_WINDOWS_H
28 #  include <windows.h>                     
29 #endif
30
31 #include <simgear/compiler.h>
32
33 #include <math.h>
34 #include <ctype.h>
35
36 #include STL_FSTREAM
37 #include STL_STRING
38 #include <vector>
39
40 #include <GL/glut.h>
41
42 #include <plib/pu.h>
43
44 #include <simgear/compiler.h>
45
46 #include <simgear/constants.h>
47 #include <simgear/debug/logstream.hxx>
48 #include <simgear/misc/props.hxx>
49
50 #include <Aircraft/aircraft.hxx>
51 #include <Autopilot/auto_gui.hxx>
52 #include <Autopilot/newauto.hxx>
53 #include <Cockpit/hud.hxx>
54 #include <Cockpit/panel.hxx>
55 #include <Cockpit/panel_io.hxx>
56 #include <GUI/gui.h>
57
58 #include <Main/globals.hxx>
59 #include <Main/fg_props.hxx>
60
61 #include "input.hxx"
62
63 #if !defined(SG_HAVE_NATIVE_SGI_COMPILERS)
64 SG_USING_STD(ifstream);
65 #endif
66 SG_USING_STD(string);
67 SG_USING_STD(vector);
68
69
70 \f
71 ////////////////////////////////////////////////////////////////////////
72 // Local data structures.
73 ////////////////////////////////////////////////////////////////////////
74
75 \f
76 ////////////////////////////////////////////////////////////////////////
77 // Implementation of FGBinding.
78 ////////////////////////////////////////////////////////////////////////
79
80 FGBinding::FGBinding ()
81   : _command(0),
82     _arg(new SGPropertyNode),
83     _setting(0),
84     _command_state(0)
85 {
86 }
87
88 FGBinding::FGBinding (const SGPropertyNode * node)
89   : _command(0),
90     _arg(new SGPropertyNode),
91     _setting(0),
92     _command_state(0)
93 {
94   read(node);
95 }
96
97 FGBinding::~FGBinding ()
98 {
99 //   delete _arg;                       // Delete the saved arguments
100 //   delete _command_state;     // Delete the saved command state
101 }
102
103 void
104 FGBinding::read (const SGPropertyNode * node)
105 {
106   const SGPropertyNode * conditionNode = node->getChild("condition");
107   if (conditionNode != 0) {
108     cerr << "Adding condition to binding" << endl;
109     setCondition(fgReadCondition(conditionNode));
110   }
111
112   _command_name = node->getStringValue("command", "");
113   if (_command_name.empty()) {
114     SG_LOG(SG_INPUT, SG_WARN, "No command supplied for binding.");
115     _command = 0;
116     return;
117   }
118
119   _command = globals->get_commands()->getCommand(_command_name);
120   if (_command == 0) {
121     SG_LOG(SG_INPUT, SG_ALERT, "Command " << _command_name << " is undefined");
122     _arg = 0;
123     return;
124   }
125
126   delete _arg;
127   _arg = new SGPropertyNode;
128   _setting = 0;
129   copyProperties(node, _arg);  // FIXME: don't use whole node!!!
130 }
131
132 void
133 FGBinding::fire () const
134 {
135   if (test()) {
136     if (_command == 0) {
137       SG_LOG(SG_INPUT, SG_WARN, "No command attached to binding");
138     } else if (!(*_command)(_arg, &_command_state)) {
139       SG_LOG(SG_INPUT, SG_ALERT, "Failed to execute command "
140              << _command_name);
141     }
142   }
143 }
144
145 void
146 FGBinding::fire (int x, int y) const
147 {
148   if (test()) {
149     if (x >= 0)
150       _arg->setIntValue("x-pos", x);
151     if (y >= 0)
152       _arg->setIntValue("y-pos", y);
153     fire();
154   }
155 }
156
157 void
158 FGBinding::fire (double setting) const
159 {
160   if (test()) {
161                                 // A value is automatically added to
162                                 // the args
163     if (_setting == 0)          // save the setting node for efficiency
164       _setting = _arg->getChild("setting", 0, true);
165     _setting->setDoubleValue(setting);
166     fire();
167   }
168 }
169
170
171 \f
172 ////////////////////////////////////////////////////////////////////////
173 // Implementation of FGInput.
174 ////////////////////////////////////////////////////////////////////////
175
176                                 // From main.cxx
177 extern void fgReshape( int width, int height );
178
179 FGInput current_input;
180
181
182 FGInput::FGInput ()
183   : _mouse_mode(0)
184 {
185   // no op
186 }
187
188 FGInput::~FGInput ()
189 {
190   // no op
191 }
192
193 void
194 FGInput::init ()
195 {
196   _init_keyboard();
197   _init_joystick();
198   _init_mouse();
199 }
200
201 void
202 FGInput::bind ()
203 {
204   // no op
205 }
206
207 void
208 FGInput::unbind ()
209 {
210   // no op
211 }
212
213 void 
214 FGInput::update (int dt)
215 {
216   _update_keyboard();
217   _update_joystick();
218   _update_mouse();
219 }
220
221 void
222 FGInput::doKey (int k, int modifiers, int x, int y)
223 {
224   SG_LOG( SG_INPUT, SG_DEBUG, "User pressed key " << k
225           << " with modifiers " << modifiers );
226
227                                 // Sanity check.
228   if (k < 0 || k >= MAX_KEYS) {
229     SG_LOG(SG_INPUT, SG_WARN, "Key value " << k << " out of range");
230     return;
231   }
232
233   button &b = _key_bindings[k];
234
235                                 // Key pressed.
236   if (modifiers&FG_MOD_UP == 0) {
237     SG_LOG( SG_INPUT, SG_DEBUG, "User pressed key " << k
238             << " with modifiers " << modifiers );
239     if (!b.last_state || b.is_repeatable) {
240       const binding_list_t &bindings =
241         _find_key_bindings(k, modifiers);
242       int max = bindings.size();
243       if (max > 0) {
244         for (int i = 0; i < max; i++)
245           bindings[i]->fire();
246         return;
247       }
248     }
249   }
250
251                                 // Key released.
252   else {
253     SG_LOG(SG_INPUT, SG_DEBUG, "User released key " << k
254            << " with modifiers " << modifiers);
255     if (b.last_state) {
256       const binding_list_t &bindings =
257         _find_key_bindings(k, modifiers);
258       int max = bindings.size();
259       if (max > 0) {
260         for (int i = 0; i < max; i++)
261           bindings[i]->fire();
262         return;
263       }
264     }
265   }
266
267
268                                 // Use the old, default actions.
269   SG_LOG( SG_INPUT, SG_DEBUG, "(No user binding.)" );
270   if (modifiers&FG_MOD_UP)
271     return;
272
273   // everything after here will be removed sooner or later...
274
275   if (modifiers & FG_MOD_SHIFT) {
276
277         switch (k) {
278         case 72: // H key
279             HUD_brightkey( true );
280             return;
281         case 73: // I key
282             // Minimal Hud
283             fgHUDInit2(&current_aircraft);
284             return;
285         }
286
287
288     } else {
289         SG_LOG( SG_INPUT, SG_DEBUG, "" );
290         switch (k) {
291         case 104: // h key
292             HUD_masterswitch( true );
293             return;
294         case 105: // i key
295             fgHUDInit(&current_aircraft);  // normal HUD
296             return;
297
298 // START SPECIALS
299
300         case 256+GLUT_KEY_F6: // F6 toggles Autopilot target location
301             if ( globals->get_autopilot()->get_HeadingMode() !=
302                  FGAutopilot::FG_HEADING_WAYPOINT ) {
303                 globals->get_autopilot()->set_HeadingMode(
304                     FGAutopilot::FG_HEADING_WAYPOINT );
305                 globals->get_autopilot()->set_HeadingEnabled( true );
306             } else {
307                 globals->get_autopilot()->set_HeadingMode(
308                     FGAutopilot::FG_TC_HEADING_LOCK );
309             }
310             return;
311         case 256+GLUT_KEY_F8: {// F8 toggles fog ... off fastest nicest...
312             const string &fog = fgGetString("/sim/rendering/fog");
313             if (fog == "disabled") {
314               fgSetString("/sim/rendering/fog", "fastest");
315               SG_LOG(SG_INPUT, SG_INFO, "Fog enabled, hint=fastest");
316             } else if (fog == "fastest") {
317               fgSetString("/sim/rendering/fog", "nicest");
318               SG_LOG(SG_INPUT, SG_INFO, "Fog enabled, hint=nicest");
319             } else if (fog == "nicest") {
320               fgSetString("/sim/rendering/fog", "disabled");
321               SG_LOG(SG_INPUT, SG_INFO, "Fog disabled");
322             } else {
323               fgSetString("/sim/rendering/fog", "disabled");
324               SG_LOG(SG_INPUT, SG_ALERT, "Unrecognized fog type "
325                      << fog << ", changed to 'disabled'");
326             }
327             return;
328         }
329         case 256+GLUT_KEY_F10: // F10 toggles menu on and off...
330             SG_LOG(SG_INPUT, SG_INFO, "Invoking call back function");
331             guiToggleMenu();
332             return;
333         case 256+GLUT_KEY_F11: // F11 Altitude Dialog.
334             SG_LOG(SG_INPUT, SG_INFO, "Invoking Altitude call back function");
335             NewAltitude( NULL );
336             return;
337         case 256+GLUT_KEY_F12: // F12 Heading Dialog...
338             SG_LOG(SG_INPUT, SG_INFO, "Invoking Heading call back function");
339             NewHeading( NULL );
340             return;
341         }
342
343 // END SPECIALS
344
345     }
346 }
347
348 void
349 FGInput::doMouseClick (int b, int updown, int x, int y)
350 {
351   std::cout << "Mouse click " << b << ',' << updown << std::endl;
352   int modifiers = FG_MOD_NONE;  // FIXME: any way to get the real ones?
353
354   _update_button(_mouse_bindings[0].buttons[b], modifiers, updown, x, y);
355 }
356
357 void
358 FGInput::doMouseMotion (int x, int y)
359 {
360   // TODO
361 }
362
363 void
364 FGInput::_init_keyboard ()
365 {
366                                 // TODO: zero the old bindings first.
367   SG_LOG(SG_INPUT, SG_DEBUG, "Initializing key bindings");
368   SGPropertyNode * key_nodes = fgGetNode("/input/keyboard");
369   if (key_nodes == 0) {
370     SG_LOG(SG_INPUT, SG_WARN, "No key bindings (/input/keyboard)!!");
371     key_nodes = fgGetNode("/input/keyboard", true);
372   }
373   
374   vector<SGPropertyNode *> keys = key_nodes->getChildren("key");
375   for (unsigned int i = 0; i < keys.size(); i++) {
376     int index = keys[i]->getIndex();
377     SG_LOG(SG_INPUT, SG_DEBUG, "Binding key " << index);
378     _key_bindings[index].is_repeatable = keys[i]->getBoolValue("repeatable");
379     _read_bindings(keys[i], _key_bindings[index].bindings, FG_MOD_NONE);
380   }
381 }
382
383
384 void
385 FGInput::_init_joystick ()
386 {
387                                 // TODO: zero the old bindings first.
388   SG_LOG(SG_INPUT, SG_DEBUG, "Initializing joystick bindings");
389   SGPropertyNode * js_nodes = fgGetNode("/input/joysticks");
390   if (js_nodes == 0) {
391     SG_LOG(SG_INPUT, SG_WARN, "No joystick bindings (/input/joysticks)!!");
392     js_nodes = fgGetNode("/input/joysticks", true);
393   }
394
395   for (int i = 0; i < MAX_JOYSTICKS; i++) {
396     SGPropertyNode * js_node = js_nodes->getChild("js", i);
397     if (js_node == 0) {
398       SG_LOG(SG_INPUT, SG_DEBUG, "No bindings for joystick " << i);
399       js_node = js_nodes->getChild("js", i, true);
400     }
401     jsJoystick * js = new jsJoystick(i);
402     _joystick_bindings[i].js = js;
403     if (js->notWorking()) {
404       SG_LOG(SG_INPUT, SG_WARN, "Joystick " << i << " not found");
405       continue;
406     }
407 #ifdef WIN32
408     JOYCAPS jsCaps ;
409     joyGetDevCaps( i, &jsCaps, sizeof(jsCaps) );
410     int nbuttons = jsCaps.wNumButtons;
411     if (nbuttons > MAX_JOYSTICK_BUTTONS) nbuttons = MAX_JOYSTICK_BUTTONS;
412 #else
413     int nbuttons = MAX_JOYSTICK_BUTTONS;
414 #endif
415         
416     int naxes = js->getNumAxes();
417     if (naxes > MAX_JOYSTICK_AXES) naxes = MAX_JOYSTICK_AXES;
418     _joystick_bindings[i].naxes = naxes;
419     _joystick_bindings[i].nbuttons = nbuttons;
420
421     SG_LOG(SG_INPUT, SG_DEBUG, "Initializing joystick " << i);
422
423                                 // Set up range arrays
424     float minRange[MAX_JOYSTICK_AXES];
425     float maxRange[MAX_JOYSTICK_AXES];
426     float center[MAX_JOYSTICK_AXES];
427
428                                 // Initialize with default values
429     js->getMinRange(minRange);
430     js->getMaxRange(maxRange);
431     js->getCenter(center);
432
433                                 // Allocate axes and buttons
434     _joystick_bindings[i].axes = new axis[naxes];
435     _joystick_bindings[i].buttons = new button[nbuttons];
436
437
438     //
439     // Initialize the axes.
440     //
441     int j;
442     for (j = 0; j < naxes; j++) {
443       const SGPropertyNode * axis_node = js_node->getChild("axis", j);
444       if (axis_node == 0) {
445         SG_LOG(SG_INPUT, SG_DEBUG, "No bindings for axis " << j);
446         axis_node = js_node->getChild("axis", j, true);
447       }
448       
449       axis &a = _joystick_bindings[i].axes[j];
450
451       js->setDeadBand(j, axis_node->getDoubleValue("dead-band", 0.0));
452
453       a.tolerance = axis_node->getDoubleValue("tolerance", 0.002);
454       minRange[j] = axis_node->getDoubleValue("min-range", minRange[j]);
455       maxRange[j] = axis_node->getDoubleValue("max-range", maxRange[j]);
456       center[j] = axis_node->getDoubleValue("center", center[j]);
457
458       _read_bindings(axis_node, a.bindings, FG_MOD_NONE);
459
460       // Initialize the virtual axis buttons.
461       _init_button(axis_node->getChild("low"), a.low, "low");
462       a.low_threshold = axis_node->getDoubleValue("low-threshold", -0.9);
463       
464       _init_button(axis_node->getChild("high"), a.high, "high");
465       a.high_threshold = axis_node->getDoubleValue("high-threshold", 0.9);
466     }
467
468     //
469     // Initialize the buttons.
470     //
471     char buf[8];
472     for (j = 0; j < nbuttons; j++) {
473       sprintf(buf, "%d", j);
474       SG_LOG(SG_INPUT, SG_DEBUG, "Initializing button " << j);
475       _init_button(js_node->getChild("button", j),
476                    _joystick_bindings[i].buttons[j],
477                    buf);
478                    
479     }
480
481     js->setMinRange(minRange);
482     js->setMaxRange(maxRange);
483     js->setCenter(center);
484   }
485 }
486
487
488 void
489 FGInput::_init_mouse ()
490 {
491   SG_LOG(SG_INPUT, SG_DEBUG, "Initializing mouse bindings");
492
493   SGPropertyNode * mouse_nodes = fgGetNode("/input/mice");
494   if (mouse_nodes == 0) {
495     SG_LOG(SG_INPUT, SG_WARN, "No mouse bindings (/input/mice)!!");
496     mouse_nodes = fgGetNode("/input/mice", true);
497   }
498
499   for (int i = 0; i < MAX_MICE; i++) {
500     const SGPropertyNode * mouse_node = mouse_nodes->getChild("mouse", i);
501     _mouse_bindings[i].buttons = new button[MAX_MOUSE_BUTTONS];
502     if (mouse_node == 0) {
503       SG_LOG(SG_INPUT, SG_DEBUG, "No bindings for mouse " << i);
504       mouse_node = mouse_nodes->getChild("mouse", i, true);
505     }
506     char buf[8];
507     for (int j = 0; j < MAX_MOUSE_BUTTONS; j++) {
508       sprintf(buf, "%d", j);
509       SG_LOG(SG_INPUT, SG_DEBUG, "Initializing mouse button " << j);
510       _init_button(mouse_node->getChild("button", j),
511                    _mouse_bindings[i].buttons[j],
512                    buf);
513     }
514   }
515 }
516
517
518 void
519 FGInput::_init_button (const SGPropertyNode * node,
520                        button &b,
521                        const string name)
522 {       
523   if (node == 0) {
524     SG_LOG(SG_INPUT, SG_DEBUG, "No bindings for button " << name);
525   } else {
526     b.is_repeatable = node->getBoolValue("repeatable", b.is_repeatable);
527     
528                 // Get the bindings for the button
529     _read_bindings(node, b.bindings, FG_MOD_NONE);
530   }
531 }
532
533
534 void
535 FGInput::_update_keyboard ()
536 {
537   // no-op
538 }
539
540
541 void
542 FGInput::_update_joystick ()
543 {
544   int modifiers = FG_MOD_NONE;  // FIXME: any way to get the real ones?
545   int buttons;
546   // float js_val, diff;
547   float axis_values[MAX_JOYSTICK_AXES];
548
549   int i;
550   int j;
551
552   for ( i = 0; i < MAX_JOYSTICKS; i++) {
553
554     jsJoystick * js = _joystick_bindings[i].js;
555     if (js == 0 || js->notWorking())
556       continue;
557
558     js->read(&buttons, axis_values);
559
560
561                                 // Fire bindings for the axes.
562     for ( j = 0; j < _joystick_bindings[i].naxes; j++) {
563       axis &a = _joystick_bindings[i].axes[j];
564       
565                                 // Do nothing if the axis position
566                                 // is unchanged; only a change in
567                                 // position fires the bindings.
568       if (fabs(axis_values[j] - a.last_value) > a.tolerance) {
569 //      SG_LOG(SG_INPUT, SG_DEBUG, "Axis " << j << " has moved");
570         SGPropertyNode node;
571         a.last_value = axis_values[j];
572 //      SG_LOG(SG_INPUT, SG_DEBUG, "There are "
573 //             << a.bindings[modifiers].size() << " bindings");
574         for (unsigned int k = 0; k < a.bindings[modifiers].size(); k++)
575           a.bindings[modifiers][k]->fire(axis_values[j]);
576       }
577      
578                                 // do we have to emulate axis buttons?
579       if (a.low.bindings[modifiers].size())
580         _update_button(_joystick_bindings[i].axes[j].low,
581                        modifiers,
582                        axis_values[j] < a.low_threshold,
583                        -1, -1);
584       
585       if (a.high.bindings[modifiers].size())
586         _update_button(_joystick_bindings[i].axes[j].high,
587                        modifiers,
588                        axis_values[j] > a.high_threshold,
589                        -1, -1);
590     }
591
592                                 // Fire bindings for the buttons.
593     for (j = 0; j < _joystick_bindings[i].nbuttons; j++) {
594       _update_button(_joystick_bindings[i].buttons[j],
595                      modifiers,
596                      (buttons & (1 << j)) > 0,
597                      -1, -1);
598     }
599   }
600 }
601
602 void
603 FGInput::_update_mouse ()
604 {
605   // no-op
606 }
607
608 void
609 FGInput::_update_button (button &b, int modifiers, bool pressed,
610                          int x, int y)
611 {
612   if (pressed) {
613                                 // The press event may be repeated.
614     if (!b.last_state || b.is_repeatable) {
615       SG_LOG( SG_INPUT, SG_DEBUG, "Button has been pressed" );
616       for (unsigned int k = 0; k < b.bindings[modifiers].size(); k++)
617         b.bindings[modifiers][k]->fire(x, y);
618     }
619   } else {
620                                 // The release event is never repeated.
621     if (b.last_state) {
622       SG_LOG( SG_INPUT, SG_DEBUG, "Button has been released" );
623       for (unsigned int k = 0; k < b.bindings[modifiers|FG_MOD_UP].size(); k++)
624         b.bindings[modifiers|FG_MOD_UP][k]->fire(x, y);
625     }
626   }
627           
628   b.last_state = pressed;
629 }  
630
631
632 void
633 FGInput::_read_bindings (const SGPropertyNode * node, 
634                          binding_list_t * binding_list,
635                          int modifiers)
636 {
637   SG_LOG(SG_INPUT, SG_DEBUG, "Reading all bindings");
638   vector<const SGPropertyNode *> bindings = node->getChildren("binding");
639   for (unsigned int i = 0; i < bindings.size(); i++) {
640     SG_LOG(SG_INPUT, SG_DEBUG, "Reading binding "
641            << bindings[i]->getStringValue("command"));
642     binding_list[modifiers].push_back(new FGBinding(bindings[i]));
643   }
644
645                                 // Read nested bindings for modifiers
646   if (node->getChild("mod-up") != 0)
647     _read_bindings(node->getChild("mod-up"), binding_list,
648                    modifiers|FG_MOD_UP);
649
650   if (node->getChild("mod-shift") != 0)
651     _read_bindings(node->getChild("mod-shift"), binding_list,
652                    modifiers|FG_MOD_SHIFT);
653
654   if (node->getChild("mod-ctrl") != 0)
655     _read_bindings(node->getChild("mod-ctrl"), binding_list,
656                    modifiers|FG_MOD_CTRL);
657
658   if (node->getChild("mod-alt") != 0)
659     _read_bindings(node->getChild("mod-alt"), binding_list,
660                    modifiers|FG_MOD_ALT);
661 }
662
663
664 const vector<FGBinding *> &
665 FGInput::_find_key_bindings (unsigned int k, int modifiers)
666 {
667   button &b = _key_bindings[k];
668
669                                 // Try it straight, first.
670   if (b.bindings[modifiers].size() > 0)
671     return b.bindings[modifiers];
672
673                                 // Try removing the control modifier
674                                 // for control keys.
675   else if ((modifiers&FG_MOD_CTRL) && iscntrl(k))
676     return _find_key_bindings(k, modifiers&~FG_MOD_CTRL);
677
678                                 // Try removing shift modifier 
679                                 // for upper case or any punctuation
680                                 // (since different keyboards will
681                                 // shift different punctuation types)
682   else if ((modifiers&FG_MOD_SHIFT) && (isupper(k) || ispunct(k)))
683     return _find_key_bindings(k, modifiers&~FG_MOD_SHIFT);
684
685                                 // Try removing alt modifier for
686                                 // high-bit characters.
687   else if ((modifiers&FG_MOD_ALT) && k >= 128 && k < 256)
688     return _find_key_bindings(k, modifiers&~FG_MOD_ALT);
689
690                                 // Give up and return the empty vector.
691   else
692     return b.bindings[modifiers];
693 }
694
695
696 \f
697 ////////////////////////////////////////////////////////////////////////
698 // Implementation of FGInput::button.
699 ////////////////////////////////////////////////////////////////////////
700
701 FGInput::button::button ()
702   : is_repeatable(false),
703     last_state(-1)
704 {
705 }
706
707 FGInput::button::~button ()
708 {
709                                 // FIXME: memory leak
710 //   for (int i = 0; i < FG_MOD_MAX; i++)
711 //     for (int j = 0; i < bindings[i].size(); j++)
712 //       delete bindings[i][j];
713 }
714
715
716 \f
717 ////////////////////////////////////////////////////////////////////////
718 // Implementation of FGInput::axis.
719 ////////////////////////////////////////////////////////////////////////
720
721 FGInput::axis::axis ()
722   : last_value(9999999),
723     tolerance(0.002),
724     low_threshold(-0.9),
725     high_threshold(0.9)
726 {
727 }
728
729 FGInput::axis::~axis ()
730 {
731 //   for (int i = 0; i < FG_MOD_MAX; i++)
732 //     for (int j = 0; i < bindings[i].size(); j++)
733 //       delete bindings[i][j];
734 }
735
736
737 \f
738 ////////////////////////////////////////////////////////////////////////
739 // Implementation of FGInput::joystick.
740 ////////////////////////////////////////////////////////////////////////
741
742 FGInput::joystick::joystick ()
743 {
744 }
745
746 FGInput::joystick::~joystick ()
747 {
748 //   delete js;
749   delete[] axes;
750   delete[] buttons;
751 }
752
753
754 \f
755 ////////////////////////////////////////////////////////////////////////
756 // Implementation of FGInput::mouse
757 ////////////////////////////////////////////////////////////////////////
758
759 FGInput::mouse::mouse ()
760 {
761 }
762
763 FGInput::mouse::~mouse ()
764 {
765   delete [] buttons;
766 }
767
768
769 \f
770 ////////////////////////////////////////////////////////////////////////
771 // Implementation of GLUT callbacks.
772 ////////////////////////////////////////////////////////////////////////
773
774
775 /**
776  * Construct the modifiers.
777  */
778 static inline int get_mods ()
779 {
780   int glut_modifiers = glutGetModifiers();
781   int modifiers = 0;
782
783   if (glut_modifiers & GLUT_ACTIVE_SHIFT)
784     modifiers |= FGInput::FG_MOD_SHIFT;
785   if (glut_modifiers & GLUT_ACTIVE_CTRL)
786     modifiers |= FGInput::FG_MOD_CTRL;
787   if (glut_modifiers & GLUT_ACTIVE_ALT)
788     modifiers |= FGInput::FG_MOD_ALT;
789
790   return modifiers;
791 }
792
793
794 \f
795 ////////////////////////////////////////////////////////////////////////
796 // GLUT C callbacks.
797 ////////////////////////////////////////////////////////////////////////
798
799 void
800 GLUTkey(unsigned char k, int x, int y)
801 {
802                                 // Give PUI a chance to grab it first.
803   if (!puKeyboard(k, PU_DOWN))
804     current_input.doKey(k, get_mods(), x, y);
805 }
806
807 void
808 GLUTkeyup(unsigned char k, int x, int y)
809 {
810   current_input.doKey(k, get_mods()|FGInput::FG_MOD_UP, x, y);
811 }
812
813 void
814 GLUTspecialkey(int k, int x, int y)
815 {
816                                 // Give PUI a chance to grab it first.
817   if (!puKeyboard(k + PU_KEY_GLUT_SPECIAL_OFFSET, PU_DOWN))
818     current_input.doKey(k + 256, get_mods(), x, y);
819 }
820
821 void
822 GLUTspecialkeyup(int k, int x, int y)
823 {
824   current_input.doKey(k + 256, get_mods()|FGInput::FG_MOD_UP, x, y);
825 }
826
827 void
828 GLUTmouse (int button, int updown, int x, int y)
829 {
830   current_input.doMouseClick(button, updown == GLUT_DOWN, x, y);
831 }
832
833 void
834 GLUTmotion (int x, int y)
835 {
836   puMouse(x, y);
837 //   glutPostRedisplay();
838   current_input.doMouseMotion(x, y);
839 }
840
841 // end of input.cxx