1 // input.cxx -- handle user input from various sources.
3 // Written by David Megginson, started May 2001.
5 // Copyright (C) 2001 David Megginson, david@megginson.com
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.
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.
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.
31 #include <simgear/compiler.h>
44 #include <simgear/compiler.h>
46 #include <simgear/constants.h>
47 #include <simgear/debug/logstream.hxx>
48 #include <simgear/props/props.hxx>
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>
57 #include <Model/panelnode.hxx>
59 #include <Main/globals.hxx>
60 #include <Main/fg_props.hxx>
64 SG_USING_STD(ifstream);
70 ////////////////////////////////////////////////////////////////////////
72 ////////////////////////////////////////////////////////////////////////
74 static FGInput * default_input = 0;
78 ////////////////////////////////////////////////////////////////////////
79 // Implementation of FGBinding.
80 ////////////////////////////////////////////////////////////////////////
82 FGBinding::FGBinding ()
84 _arg(new SGPropertyNode),
89 FGBinding::FGBinding (const SGPropertyNode * node)
98 FGBinding::read (const SGPropertyNode * node)
100 const SGPropertyNode * conditionNode = node->getChild("condition");
101 if (conditionNode != 0)
102 setCondition(sgReadCondition(globals->get_props(), conditionNode));
104 _command_name = node->getStringValue("command", "");
105 if (_command_name.empty()) {
106 SG_LOG(SG_INPUT, SG_WARN, "No command supplied for binding.");
111 _arg = new SGPropertyNode;
113 copyProperties(node, _arg); // FIXME: don't use whole node!!!
117 FGBinding::fire () const
121 _command = globals->get_commands()->getCommand(_command_name);
123 SG_LOG(SG_INPUT, SG_WARN, "No command attached to binding");
124 } else if (!(*_command)(_arg)) {
125 SG_LOG(SG_INPUT, SG_ALERT, "Failed to execute command "
132 FGBinding::fire (double offset, double max) const
135 _arg->setDoubleValue("offset", offset/max);
141 FGBinding::fire (double setting) const
144 // A value is automatically added to
146 if (_setting == 0) // save the setting node for efficiency
147 _setting = _arg->getChild("setting", 0, true);
148 _setting->setDoubleValue(setting);
155 ////////////////////////////////////////////////////////////////////////
156 // Implementation of FGInput.
157 ////////////////////////////////////////////////////////////////////////
162 if (default_input == 0)
163 default_input = this;
168 if (default_input == this)
179 glutKeyboardFunc(GLUTkey);
180 glutKeyboardUpFunc(GLUTkeyup);
181 glutSpecialFunc(GLUTspecialkey);
182 glutSpecialUpFunc(GLUTspecialkeyup);
183 glutMouseFunc (GLUTmouse);
184 glutMotionFunc (GLUTmotion);
185 glutPassiveMotionFunc (GLUTmotion);
189 FGInput::update (double dt)
192 _update_joystick(dt);
209 FGInput::is_suspended () const
215 FGInput::makeDefault (bool status)
218 default_input = this;
219 else if (default_input == this)
224 FGInput::doKey (int k, int modifiers, int x, int y)
227 if (k < 0 || k >= MAX_KEYS) {
228 SG_LOG(SG_INPUT, SG_WARN, "Key value " << k << " out of range");
232 button &b = _key_bindings[k];
235 if (modifiers&FG_MOD_UP == 0) {
236 SG_LOG( SG_INPUT, SG_DEBUG, "User pressed key " << k
237 << " with modifiers " << modifiers );
238 if (!b.last_state || b.is_repeatable) {
239 const binding_list_t &bindings =
240 _find_key_bindings(k, modifiers);
241 int max = bindings.size();
243 for (int i = 0; i < max; i++)
252 SG_LOG(SG_INPUT, SG_DEBUG, "User released key " << k
253 << " with modifiers " << modifiers);
255 const binding_list_t &bindings =
256 _find_key_bindings(k, modifiers);
257 int max = bindings.size();
259 for (int i = 0; i < max; i++)
267 // Use the old, default actions.
268 SG_LOG( SG_INPUT, SG_DEBUG, "(No user binding.)" );
269 if (modifiers&FG_MOD_UP)
272 // everything after here will be removed sooner or later...
274 if (modifiers & FG_MOD_SHIFT) {
278 HUD_brightkey( true );
282 fgHUDInit2(¤t_aircraft);
288 SG_LOG( SG_INPUT, SG_DEBUG, "" );
291 HUD_masterswitch( true );
294 fgHUDInit(¤t_aircraft); // normal HUD
299 case 256+GLUT_KEY_F6: // F6 toggles Autopilot target location
300 if ( globals->get_autopilot()->get_HeadingMode() !=
301 FGAutopilot::FG_HEADING_WAYPOINT ) {
302 globals->get_autopilot()->set_HeadingMode(
303 FGAutopilot::FG_HEADING_WAYPOINT );
304 globals->get_autopilot()->set_HeadingEnabled( true );
306 globals->get_autopilot()->set_HeadingMode(
307 FGAutopilot::FG_TC_HEADING_LOCK );
318 FGInput::doMouseClick (int b, int updown, int x, int y)
320 int modifiers = FG_MOD_NONE; // FIXME: any way to get the real ones?
322 mouse &m = _mouse_bindings[0];
323 mouse_mode &mode = m.modes[m.current_mode];
325 // Let the property manager know.
326 if (b >= 0 && b < MAX_MOUSE_BUTTONS)
327 m.mouse_button_nodes[b]->setBoolValue(updown == GLUT_DOWN);
329 // Pass on to PUI and the panel if
330 // requested, and return if one of
331 // them consumes the event.
332 if (mode.pass_through) {
333 if (puMouse(b, updown, x, y))
335 else if ((globals->get_current_panel() != 0) &&
336 globals->get_current_panel()->getVisibility() &&
337 globals->get_current_panel()->doMouseAction(b, updown, x, y))
339 else if (fgHandle3DPanelMouseEvent(b, updown, x, y))
343 // OK, PUI and the panel didn't want the click
344 if (b >= MAX_MOUSE_BUTTONS) {
345 SG_LOG(SG_INPUT, SG_ALERT, "Mouse button " << b
346 << " where only " << MAX_MOUSE_BUTTONS << " expected");
350 _update_button(m.modes[m.current_mode].buttons[b], modifiers, 0 != updown, x, y);
354 FGInput::doMouseMotion (int x, int y)
356 int modifiers = FG_MOD_NONE; // FIXME: any way to get the real ones?
358 int xsize = fgGetInt("/sim/startup/xsize", 800);
359 int ysize = fgGetInt("/sim/startup/ysize", 600);
360 mouse &m = _mouse_bindings[0];
361 if (m.current_mode < 0 || m.current_mode >= m.nModes)
363 mouse_mode &mode = m.modes[m.current_mode];
365 // Pass on to PUI if requested, and return
366 // if PUI consumed the event.
367 if (mode.pass_through && puMouse(x, y))
370 // OK, PUI didn't want the event,
371 // so we can play with it.
374 for (unsigned int i = 0; i < mode.x_bindings[modifiers].size(); i++)
375 mode.x_bindings[modifiers][i]->fire(double(delta), double(xsize));
379 for (unsigned int i = 0; i < mode.y_bindings[modifiers].size(); i++)
380 mode.y_bindings[modifiers][i]->fire(double(delta), double(ysize));
383 // Constrain the mouse if requested
384 if (mode.constrained) {
385 bool need_warp = false;
389 } else if (x >= (xsize-1)) {
397 } else if (y >= (ysize-1)) {
403 glutWarpPointer(x, y);
410 FGInput::_init_keyboard ()
412 SG_LOG(SG_INPUT, SG_DEBUG, "Initializing key bindings");
413 SGPropertyNode * key_nodes = fgGetNode("/input/keyboard");
414 if (key_nodes == 0) {
415 SG_LOG(SG_INPUT, SG_WARN, "No key bindings (/input/keyboard)!!");
416 key_nodes = fgGetNode("/input/keyboard", true);
419 vector<SGPropertyNode_ptr> keys = key_nodes->getChildren("key");
420 for (unsigned int i = 0; i < keys.size(); i++) {
421 int index = keys[i]->getIndex();
422 SG_LOG(SG_INPUT, SG_DEBUG, "Binding key " << index);
424 _key_bindings[index].bindings->clear();
425 _key_bindings[index].is_repeatable = keys[i]->getBoolValue("repeatable");
426 _read_bindings(keys[i], _key_bindings[index].bindings, FG_MOD_NONE);
432 FGInput::_init_joystick ()
434 // TODO: zero the old bindings first.
435 SG_LOG(SG_INPUT, SG_DEBUG, "Initializing joystick bindings");
436 SGPropertyNode * js_nodes = fgGetNode("/input/joysticks");
438 SG_LOG(SG_INPUT, SG_WARN, "No joystick bindings (/input/joysticks)!!");
439 js_nodes = fgGetNode("/input/joysticks", true);
442 for (int i = 0; i < MAX_JOYSTICKS; i++) {
443 SGPropertyNode_ptr js_node = js_nodes->getChild("js", i);
445 SG_LOG(SG_INPUT, SG_DEBUG, "No bindings for joystick " << i);
446 js_node = js_nodes->getChild("js", i, true);
448 jsJoystick * js = new jsJoystick(i);
449 _joystick_bindings[i].js = js;
450 if (js->notWorking()) {
451 SG_LOG(SG_INPUT, SG_DEBUG, "Joystick " << i << " not found");
454 bool found_js = false;
455 const char * name = js->getName();
456 SG_LOG(SG_INPUT, SG_INFO, "Looking for bindings for joystick \""
458 vector<SGPropertyNode_ptr> nodes = js_nodes->getChildren("js-named");
459 for (unsigned int i = 0; i < nodes.size(); i++) {
460 SGPropertyNode_ptr node = nodes[i];
461 vector<SGPropertyNode_ptr> name_nodes = node->getChildren("name");
462 for (unsigned int j = 0; j < name_nodes.size(); j++) {
463 const char * js_name = name_nodes[j]->getStringValue();
464 SG_LOG(SG_INPUT, SG_INFO, " Trying \"" << js_name << '"');
465 if (!strcmp(js_name, name)) {
466 SG_LOG(SG_INPUT, SG_INFO, " Found bindings");
478 joyGetDevCaps( i, &jsCaps, sizeof(jsCaps) );
479 int nbuttons = jsCaps.wNumButtons;
480 if (nbuttons > MAX_JOYSTICK_BUTTONS) nbuttons = MAX_JOYSTICK_BUTTONS;
482 int nbuttons = MAX_JOYSTICK_BUTTONS;
485 int naxes = js->getNumAxes();
486 if (naxes > MAX_JOYSTICK_AXES) naxes = MAX_JOYSTICK_AXES;
487 _joystick_bindings[i].naxes = naxes;
488 _joystick_bindings[i].nbuttons = nbuttons;
490 SG_LOG(SG_INPUT, SG_DEBUG, "Initializing joystick " << i);
492 // Set up range arrays
493 float minRange[MAX_JOYSTICK_AXES];
494 float maxRange[MAX_JOYSTICK_AXES];
495 float center[MAX_JOYSTICK_AXES];
497 // Initialize with default values
498 js->getMinRange(minRange);
499 js->getMaxRange(maxRange);
500 js->getCenter(center);
502 // Allocate axes and buttons
503 _joystick_bindings[i].axes = new axis[naxes];
504 _joystick_bindings[i].buttons = new button[nbuttons];
508 // Initialize the axes.
511 for (j = 0; j < naxes; j++) {
512 const SGPropertyNode * axis_node = js_node->getChild("axis", j);
513 if (axis_node == 0) {
514 SG_LOG(SG_INPUT, SG_DEBUG, "No bindings for axis " << j);
515 axis_node = js_node->getChild("axis", j, true);
518 axis &a = _joystick_bindings[i].axes[j];
520 js->setDeadBand(j, axis_node->getDoubleValue("dead-band", 0.0));
522 a.tolerance = axis_node->getDoubleValue("tolerance", 0.002);
523 minRange[j] = axis_node->getDoubleValue("min-range", minRange[j]);
524 maxRange[j] = axis_node->getDoubleValue("max-range", maxRange[j]);
525 center[j] = axis_node->getDoubleValue("center", center[j]);
527 _read_bindings(axis_node, a.bindings, FG_MOD_NONE);
529 // Initialize the virtual axis buttons.
530 _init_button(axis_node->getChild("low"), a.low, "low");
531 a.low_threshold = axis_node->getDoubleValue("low-threshold", -0.9);
533 _init_button(axis_node->getChild("high"), a.high, "high");
534 a.high_threshold = axis_node->getDoubleValue("high-threshold", 0.9);
535 a.interval_sec = axis_node->getDoubleValue("interval-sec",0.0);
540 // Initialize the buttons.
543 for (j = 0; j < nbuttons; j++) {
544 sprintf(buf, "%d", j);
545 SG_LOG(SG_INPUT, SG_DEBUG, "Initializing button " << j);
546 _init_button(js_node->getChild("button", j),
547 _joystick_bindings[i].buttons[j],
550 // get interval-sec property
551 button &b = _joystick_bindings[i].buttons[j];
552 const SGPropertyNode * button_node = js_node->getChild("button", j);
553 if (button_node != 0) {
554 b.interval_sec = button_node->getDoubleValue("interval-sec",0.0);
559 js->setMinRange(minRange);
560 js->setMaxRange(maxRange);
561 js->setCenter(center);
566 // Map of all known GLUT cursor names
571 } mouse_cursor_map[] = {
572 { "right-arrow", GLUT_CURSOR_RIGHT_ARROW },
573 { "left-arrow", GLUT_CURSOR_LEFT_ARROW },
574 { "info", GLUT_CURSOR_INFO },
575 { "destroy", GLUT_CURSOR_DESTROY },
576 { "help", GLUT_CURSOR_HELP },
577 { "cycle", GLUT_CURSOR_CYCLE },
578 { "spray", GLUT_CURSOR_SPRAY },
579 { "wait", GLUT_CURSOR_WAIT },
580 { "text", GLUT_CURSOR_TEXT },
581 { "crosshair", GLUT_CURSOR_CROSSHAIR },
582 { "up-down", GLUT_CURSOR_UP_DOWN },
583 { "left-right", GLUT_CURSOR_LEFT_RIGHT },
584 { "top-side", GLUT_CURSOR_TOP_SIDE },
585 { "bottom-side", GLUT_CURSOR_BOTTOM_SIDE },
586 { "left-side", GLUT_CURSOR_LEFT_SIDE },
587 { "right-side", GLUT_CURSOR_RIGHT_SIDE },
588 { "top-left-corner", GLUT_CURSOR_TOP_LEFT_CORNER },
589 { "top-right-corner", GLUT_CURSOR_TOP_RIGHT_CORNER },
590 { "bottom-right-corner", GLUT_CURSOR_BOTTOM_RIGHT_CORNER },
591 { "bottom-left-corner", GLUT_CURSOR_BOTTOM_LEFT_CORNER },
592 { "inherit", GLUT_CURSOR_INHERIT },
593 { "none", GLUT_CURSOR_NONE },
594 { "full-crosshair", GLUT_CURSOR_FULL_CROSSHAIR },
601 FGInput::_init_mouse ()
603 SG_LOG(SG_INPUT, SG_DEBUG, "Initializing mouse bindings");
605 SGPropertyNode * mouse_nodes = fgGetNode("/input/mice");
606 if (mouse_nodes == 0) {
607 SG_LOG(SG_INPUT, SG_WARN, "No mouse bindings (/input/mice)!!");
608 mouse_nodes = fgGetNode("/input/mice", true);
612 for (int i = 0; i < MAX_MICE; i++) {
613 SGPropertyNode * mouse_node = mouse_nodes->getChild("mouse", i, true);
614 mouse &m = _mouse_bindings[i];
616 // Grab node pointers
618 sprintf(buf, "/devices/status/mice/mouse[%d]/mode", i);
619 m.mode_node = fgGetNode(buf, true);
620 m.mode_node->setIntValue(0);
621 for (j = 0; j < MAX_MOUSE_BUTTONS; j++) {
622 sprintf(buf, "/devices/status/mice/mouse[%d]/button[%d]", i, j);
623 m.mouse_button_nodes[j] = fgGetNode(buf, true);
624 m.mouse_button_nodes[j]->setBoolValue(false);
627 // Read all the modes
628 m.nModes = mouse_node->getIntValue("mode-count", 1);
629 m.modes = new mouse_mode[m.nModes];
631 for (int j = 0; j < m.nModes; j++) {
634 // Read the mouse cursor for this mode
635 SGPropertyNode * mode_node = mouse_node->getChild("mode", j, true);
636 const char * cursor_name =
637 mode_node->getStringValue("cursor", "inherit");
638 m.modes[j].cursor = GLUT_CURSOR_INHERIT;
639 for (k = 0; mouse_cursor_map[k].name != 0; k++) {
640 if (!strcmp(mouse_cursor_map[k].name, cursor_name)) {
641 m.modes[j].cursor = mouse_cursor_map[k].cursor;
646 // Read other properties for this mode
647 m.modes[j].constrained = mode_node->getBoolValue("constrained", false);
648 m.modes[j].pass_through = mode_node->getBoolValue("pass-through", false);
650 // Read the button bindings for this mode
651 m.modes[j].buttons = new button[MAX_MOUSE_BUTTONS];
653 for (k = 0; k < MAX_MOUSE_BUTTONS; k++) {
654 sprintf(buf, "mouse button %d", k);
655 SG_LOG(SG_INPUT, SG_DEBUG, "Initializing mouse button " << k);
656 _init_button(mode_node->getChild("button", k),
657 m.modes[j].buttons[k],
661 // Read the axis bindings for this mode
662 _read_bindings(mode_node->getChild("x-axis", 0, true),
663 m.modes[j].x_bindings,
665 _read_bindings(mode_node->getChild("y-axis", 0, true),
666 m.modes[j].y_bindings,
674 FGInput::_init_button (const SGPropertyNode * node,
679 SG_LOG(SG_INPUT, SG_DEBUG, "No bindings for button " << name);
681 b.is_repeatable = node->getBoolValue("repeatable", b.is_repeatable);
683 // Get the bindings for the button
684 _read_bindings(node, b.bindings, FG_MOD_NONE);
690 FGInput::_update_keyboard ()
697 FGInput::_update_joystick (double dt)
699 int modifiers = FG_MOD_NONE; // FIXME: any way to get the real ones?
701 // float js_val, diff;
702 float axis_values[MAX_JOYSTICK_AXES];
707 for ( i = 0; i < MAX_JOYSTICKS; i++) {
709 jsJoystick * js = _joystick_bindings[i].js;
710 if (js == 0 || js->notWorking())
713 js->read(&buttons, axis_values);
716 // Fire bindings for the axes.
717 for ( j = 0; j < _joystick_bindings[i].naxes; j++) {
718 axis &a = _joystick_bindings[i].axes[j];
720 // Do nothing if the axis position
721 // is unchanged; only a change in
722 // position fires the bindings.
723 if (fabs(axis_values[j] - a.last_value) > a.tolerance) {
724 // SG_LOG(SG_INPUT, SG_DEBUG, "Axis " << j << " has moved");
726 a.last_value = axis_values[j];
727 // SG_LOG(SG_INPUT, SG_DEBUG, "There are "
728 // << a.bindings[modifiers].size() << " bindings");
729 for (unsigned int k = 0; k < a.bindings[modifiers].size(); k++)
730 a.bindings[modifiers][k]->fire(axis_values[j]);
733 // do we have to emulate axis buttons?
735 if(a.last_dt >= a.interval_sec) {
736 if (a.low.bindings[modifiers].size())
737 _update_button(_joystick_bindings[i].axes[j].low,
739 axis_values[j] < a.low_threshold,
742 if (a.high.bindings[modifiers].size())
743 _update_button(_joystick_bindings[i].axes[j].high,
745 axis_values[j] > a.high_threshold,
747 a.last_dt -= a.interval_sec;
751 // Fire bindings for the buttons.
752 for (j = 0; j < _joystick_bindings[i].nbuttons; j++) {
753 button &b = _joystick_bindings[i].buttons[j];
755 if(b.last_dt >= b.interval_sec) {
756 _update_button(_joystick_bindings[i].buttons[j],
758 (buttons & (1 << j)) > 0,
760 b.last_dt -= b.interval_sec;
767 FGInput::_update_mouse ()
769 mouse &m = _mouse_bindings[0];
770 int mode = m.mode_node->getIntValue();
771 if (mode != m.current_mode) {
772 m.current_mode = mode;
773 if (mode >= 0 && mode < m.nModes) {
774 glutSetCursor(m.modes[mode].cursor);
775 m.x = fgGetInt("/sim/startup/xsize", 800) / 2;
776 m.y = fgGetInt("/sim/startup/ysize", 600) / 2;
777 glutWarpPointer(m.x, m.y);
779 SG_LOG(SG_INPUT, SG_DEBUG, "Mouse mode " << mode << " out of range");
780 glutSetCursor(GLUT_CURSOR_INHERIT);
786 FGInput::_update_button (button &b, int modifiers, bool pressed,
790 // The press event may be repeated.
791 if (!b.last_state || b.is_repeatable) {
792 SG_LOG( SG_INPUT, SG_DEBUG, "Button has been pressed" );
793 for (unsigned int k = 0; k < b.bindings[modifiers].size(); k++)
794 b.bindings[modifiers][k]->fire(x, y);
797 // The release event is never repeated.
799 SG_LOG( SG_INPUT, SG_DEBUG, "Button has been released" );
800 for (unsigned int k = 0; k < b.bindings[modifiers|FG_MOD_UP].size(); k++)
801 b.bindings[modifiers|FG_MOD_UP][k]->fire(x, y);
805 b.last_state = pressed;
810 FGInput::_read_bindings (const SGPropertyNode * node,
811 binding_list_t * binding_list,
814 SG_LOG(SG_INPUT, SG_DEBUG, "Reading all bindings");
815 vector<SGPropertyNode_ptr> bindings = node->getChildren("binding");
816 for (unsigned int i = 0; i < bindings.size(); i++) {
817 SG_LOG(SG_INPUT, SG_DEBUG, "Reading binding "
818 << bindings[i]->getStringValue("command"));
819 binding_list[modifiers].push_back(new FGBinding(bindings[i]));
822 // Read nested bindings for modifiers
823 if (node->getChild("mod-up") != 0)
824 _read_bindings(node->getChild("mod-up"), binding_list,
825 modifiers|FG_MOD_UP);
827 if (node->getChild("mod-shift") != 0)
828 _read_bindings(node->getChild("mod-shift"), binding_list,
829 modifiers|FG_MOD_SHIFT);
831 if (node->getChild("mod-ctrl") != 0)
832 _read_bindings(node->getChild("mod-ctrl"), binding_list,
833 modifiers|FG_MOD_CTRL);
835 if (node->getChild("mod-alt") != 0)
836 _read_bindings(node->getChild("mod-alt"), binding_list,
837 modifiers|FG_MOD_ALT);
841 const vector<FGBinding *> &
842 FGInput::_find_key_bindings (unsigned int k, int modifiers)
844 unsigned char kc = (unsigned char)k;
845 button &b = _key_bindings[k];
847 // Try it straight, first.
848 if (b.bindings[modifiers].size() > 0)
849 return b.bindings[modifiers];
851 // Alt-Gr is CTRL+ALT
852 else if (modifiers&(FG_MOD_CTRL|FG_MOD_ALT))
853 return _find_key_bindings(k, modifiers&~(FG_MOD_CTRL|FG_MOD_ALT));
855 // Try removing the control modifier
857 else if ((modifiers&FG_MOD_CTRL) && iscntrl(kc))
858 return _find_key_bindings(k, modifiers&~FG_MOD_CTRL);
860 // Try removing shift modifier
861 // for upper case or any punctuation
862 // (since different keyboards will
863 // shift different punctuation types)
864 else if ((modifiers&FG_MOD_SHIFT) && (isupper(kc) || ispunct(kc)))
865 return _find_key_bindings(k, modifiers&~FG_MOD_SHIFT);
867 // Try removing alt modifier for
868 // high-bit characters.
869 else if ((modifiers&FG_MOD_ALT) && k >= 128 && k < 256)
870 return _find_key_bindings(k, modifiers&~FG_MOD_ALT);
872 // Give up and return the empty vector.
874 return b.bindings[modifiers];
879 ////////////////////////////////////////////////////////////////////////
880 // Implementation of FGInput::button.
881 ////////////////////////////////////////////////////////////////////////
883 FGInput::button::button ()
884 : is_repeatable(false),
889 FGInput::button::~button ()
891 // FIXME: memory leak
892 // for (int i = 0; i < FG_MOD_MAX; i++)
893 // for (int j = 0; i < bindings[i].size(); j++)
894 // delete bindings[i][j];
899 ////////////////////////////////////////////////////////////////////////
900 // Implementation of FGInput::axis.
901 ////////////////////////////////////////////////////////////////////////
903 FGInput::axis::axis ()
904 : last_value(9999999),
911 FGInput::axis::~axis ()
913 // for (int i = 0; i < FG_MOD_MAX; i++)
914 // for (int j = 0; i < bindings[i].size(); j++)
915 // delete bindings[i][j];
920 ////////////////////////////////////////////////////////////////////////
921 // Implementation of FGInput::joystick.
922 ////////////////////////////////////////////////////////////////////////
924 FGInput::joystick::joystick ()
928 FGInput::joystick::~joystick ()
937 ////////////////////////////////////////////////////////////////////////
938 // Implementation of FGInput::mouse_mode
939 ////////////////////////////////////////////////////////////////////////
941 FGInput::mouse_mode::mouse_mode ()
942 : cursor(GLUT_CURSOR_INHERIT),
949 FGInput::mouse_mode::~mouse_mode ()
951 // FIXME: memory leak
952 // for (int i = 0; i < FG_MOD_MAX; i++) {
954 // for (j = 0; i < x_bindings[i].size(); j++)
955 // delete bindings[i][j];
956 // for (j = 0; j < y_bindings[i].size(); j++)
957 // delete bindings[i][j];
964 ////////////////////////////////////////////////////////////////////////
965 // Implementation of FGInput::mouse
966 ////////////////////////////////////////////////////////////////////////
968 FGInput::mouse::mouse ()
977 FGInput::mouse::~mouse ()
984 ////////////////////////////////////////////////////////////////////////
985 // Implementation of GLUT callbacks.
986 ////////////////////////////////////////////////////////////////////////
990 * Construct the modifiers.
992 static inline int get_mods ()
994 int glut_modifiers = glutGetModifiers();
997 if (glut_modifiers & GLUT_ACTIVE_SHIFT)
998 modifiers |= FGInput::FG_MOD_SHIFT;
999 if (glut_modifiers & GLUT_ACTIVE_CTRL)
1000 modifiers |= FGInput::FG_MOD_CTRL;
1001 if (glut_modifiers & GLUT_ACTIVE_ALT)
1002 modifiers |= FGInput::FG_MOD_ALT;
1009 ////////////////////////////////////////////////////////////////////////
1010 // GLUT C callbacks.
1011 ////////////////////////////////////////////////////////////////////////
1014 GLUTkey(unsigned char k, int x, int y)
1016 // Give PUI a chance to grab it first.
1017 if (!puKeyboard(k, PU_DOWN)) {
1018 if (default_input != 0)
1019 default_input->doKey(k, get_mods(), x, y);
1024 GLUTkeyup(unsigned char k, int x, int y)
1026 if (default_input != 0)
1027 default_input->doKey(k, get_mods()|FGInput::FG_MOD_UP, x, y);
1031 GLUTspecialkey(int k, int x, int y)
1033 // Give PUI a chance to grab it first.
1034 if (!puKeyboard(k + PU_KEY_GLUT_SPECIAL_OFFSET, PU_DOWN)) {
1035 if (default_input != 0)
1036 default_input->doKey(k + 256, get_mods(), x, y);
1041 GLUTspecialkeyup(int k, int x, int y)
1043 if (default_input != 0)
1044 default_input->doKey(k + 256, get_mods()|FGInput::FG_MOD_UP, x, y);
1048 GLUTmouse (int button, int updown, int x, int y)
1050 if (default_input != 0)
1051 default_input->doMouseClick(button, updown, x, y);
1055 GLUTmotion (int x, int y)
1057 if (default_input != 0)
1058 default_input->doMouseMotion(x, y);