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/misc/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)
97 FGBinding::~FGBinding ()
99 delete _arg; // Delete the saved arguments
103 FGBinding::read (const SGPropertyNode * node)
105 const SGPropertyNode * conditionNode = node->getChild("condition");
106 if (conditionNode != 0)
107 setCondition(fgReadCondition(conditionNode));
109 _command_name = node->getStringValue("command", "");
110 if (_command_name.empty()) {
111 SG_LOG(SG_INPUT, SG_WARN, "No command supplied for binding.");
117 _arg = new SGPropertyNode;
119 copyProperties(node, _arg); // FIXME: don't use whole node!!!
123 FGBinding::fire () const
127 _command = globals->get_commands()->getCommand(_command_name);
129 SG_LOG(SG_INPUT, SG_WARN, "No command attached to binding");
130 } else if (!(*_command)(_arg)) {
131 SG_LOG(SG_INPUT, SG_ALERT, "Failed to execute command "
138 FGBinding::fire (double offset, double max) const
141 _arg->setDoubleValue("offset", offset/max);
147 FGBinding::fire (double setting) const
150 // A value is automatically added to
152 if (_setting == 0) // save the setting node for efficiency
153 _setting = _arg->getChild("setting", 0, true);
154 _setting->setDoubleValue(setting);
161 ////////////////////////////////////////////////////////////////////////
162 // Implementation of FGInput.
163 ////////////////////////////////////////////////////////////////////////
168 if (default_input == 0)
169 default_input = this;
174 if (default_input == this)
185 glutKeyboardFunc(GLUTkey);
186 glutKeyboardUpFunc(GLUTkeyup);
187 glutSpecialFunc(GLUTspecialkey);
188 glutSpecialUpFunc(GLUTspecialkeyup);
189 glutMouseFunc (GLUTmouse);
190 glutMotionFunc (GLUTmotion);
191 glutPassiveMotionFunc (GLUTmotion);
195 FGInput::update (double dt)
215 FGInput::is_suspended () const
221 FGInput::makeDefault (bool status)
224 default_input = this;
225 else if (default_input == this)
230 FGInput::doKey (int k, int modifiers, int x, int y)
233 if (k < 0 || k >= MAX_KEYS) {
234 SG_LOG(SG_INPUT, SG_WARN, "Key value " << k << " out of range");
238 button &b = _key_bindings[k];
241 if (modifiers&FG_MOD_UP == 0) {
242 SG_LOG( SG_INPUT, SG_DEBUG, "User pressed key " << k
243 << " with modifiers " << modifiers );
244 if (!b.last_state || b.is_repeatable) {
245 const binding_list_t &bindings =
246 _find_key_bindings(k, modifiers);
247 int max = bindings.size();
249 for (int i = 0; i < max; i++)
258 SG_LOG(SG_INPUT, SG_DEBUG, "User released key " << k
259 << " with modifiers " << modifiers);
261 const binding_list_t &bindings =
262 _find_key_bindings(k, modifiers);
263 int max = bindings.size();
265 for (int i = 0; i < max; i++)
273 // Use the old, default actions.
274 SG_LOG( SG_INPUT, SG_DEBUG, "(No user binding.)" );
275 if (modifiers&FG_MOD_UP)
278 // everything after here will be removed sooner or later...
280 if (modifiers & FG_MOD_SHIFT) {
284 HUD_brightkey( true );
288 fgHUDInit2(¤t_aircraft);
294 SG_LOG( SG_INPUT, SG_DEBUG, "" );
297 HUD_masterswitch( true );
300 fgHUDInit(¤t_aircraft); // normal HUD
305 case 256+GLUT_KEY_F6: // F6 toggles Autopilot target location
306 if ( globals->get_autopilot()->get_HeadingMode() !=
307 FGAutopilot::FG_HEADING_WAYPOINT ) {
308 globals->get_autopilot()->set_HeadingMode(
309 FGAutopilot::FG_HEADING_WAYPOINT );
310 globals->get_autopilot()->set_HeadingEnabled( true );
312 globals->get_autopilot()->set_HeadingMode(
313 FGAutopilot::FG_TC_HEADING_LOCK );
324 FGInput::doMouseClick (int b, int updown, int x, int y)
326 int modifiers = FG_MOD_NONE; // FIXME: any way to get the real ones?
328 mouse &m = _mouse_bindings[0];
329 mouse_mode &mode = m.modes[m.current_mode];
331 // Let the property manager know.
332 if (b >= 0 && b < MAX_MOUSE_BUTTONS)
333 m.mouse_button_nodes[b]->setBoolValue(updown == GLUT_DOWN);
335 // Pass on to PUI and the panel if
336 // requested, and return if one of
337 // them consumes the event.
338 if (mode.pass_through) {
339 if (puMouse(b, updown, x, y))
341 else if ((globals->get_current_panel() != 0) &&
342 globals->get_current_panel()->getVisibility() &&
343 globals->get_current_panel()->doMouseAction(b, updown, x, y))
345 else if (fgHandle3DPanelMouseEvent(b, updown, x, y))
349 // OK, PUI and the panel didn't want the click
350 if (b >= MAX_MOUSE_BUTTONS) {
351 SG_LOG(SG_INPUT, SG_ALERT, "Mouse button " << b
352 << " where only " << MAX_MOUSE_BUTTONS << " expected");
356 _update_button(m.modes[m.current_mode].buttons[b], modifiers, 0 != updown, x, y);
360 FGInput::doMouseMotion (int x, int y)
362 int modifiers = FG_MOD_NONE; // FIXME: any way to get the real ones?
364 int xsize = fgGetInt("/sim/startup/xsize", 800);
365 int ysize = fgGetInt("/sim/startup/ysize", 600);
366 mouse &m = _mouse_bindings[0];
367 if (m.current_mode < 0 || m.current_mode >= m.nModes)
369 mouse_mode &mode = m.modes[m.current_mode];
371 // Pass on to PUI if requested, and return
372 // if PUI consumed the event.
373 if (mode.pass_through && puMouse(x, y))
376 // OK, PUI didn't want the event,
377 // so we can play with it.
380 for (unsigned int i = 0; i < mode.x_bindings[modifiers].size(); i++)
381 mode.x_bindings[modifiers][i]->fire(double(delta), double(xsize));
385 for (unsigned int i = 0; i < mode.y_bindings[modifiers].size(); i++)
386 mode.y_bindings[modifiers][i]->fire(double(delta), double(ysize));
389 // Constrain the mouse if requested
390 if (mode.constrained) {
391 bool need_warp = false;
395 } else if (x >= (xsize-1)) {
403 } else if (y >= (ysize-1)) {
409 glutWarpPointer(x, y);
416 FGInput::_init_keyboard ()
418 // TODO: zero the old bindings first.
419 SG_LOG(SG_INPUT, SG_DEBUG, "Initializing key bindings");
420 SGPropertyNode * key_nodes = fgGetNode("/input/keyboard");
421 if (key_nodes == 0) {
422 SG_LOG(SG_INPUT, SG_WARN, "No key bindings (/input/keyboard)!!");
423 key_nodes = fgGetNode("/input/keyboard", true);
426 vector<SGPropertyNode_ptr> keys = key_nodes->getChildren("key");
427 for (unsigned int i = 0; i < keys.size(); i++) {
428 int index = keys[i]->getIndex();
429 SG_LOG(SG_INPUT, SG_DEBUG, "Binding key " << index);
430 _key_bindings[index].is_repeatable = keys[i]->getBoolValue("repeatable");
431 _read_bindings(keys[i], _key_bindings[index].bindings, FG_MOD_NONE);
437 FGInput::_init_joystick ()
439 // TODO: zero the old bindings first.
440 SG_LOG(SG_INPUT, SG_DEBUG, "Initializing joystick bindings");
441 SGPropertyNode * js_nodes = fgGetNode("/input/joysticks");
443 SG_LOG(SG_INPUT, SG_WARN, "No joystick bindings (/input/joysticks)!!");
444 js_nodes = fgGetNode("/input/joysticks", true);
447 for (int i = 0; i < MAX_JOYSTICKS; i++) {
448 SGPropertyNode_ptr js_node = js_nodes->getChild("js", i);
450 SG_LOG(SG_INPUT, SG_DEBUG, "No bindings for joystick " << i);
451 js_node = js_nodes->getChild("js", i, true);
453 jsJoystick * js = new jsJoystick(i);
454 _joystick_bindings[i].js = js;
455 if (js->notWorking()) {
456 SG_LOG(SG_INPUT, SG_WARN, "Joystick " << i << " not found");
459 bool found_js = false;
460 const char * name = js->getName();
461 SG_LOG(SG_INPUT, SG_INFO, "Looking for bindings for joystick \""
463 vector<SGPropertyNode_ptr> nodes = js_nodes->getChildren("js-named");
464 for (unsigned int i = 0; i < nodes.size(); i++) {
465 SGPropertyNode_ptr node = nodes[i];
466 vector<SGPropertyNode_ptr> name_nodes = node->getChildren("name");
467 for (unsigned int j = 0; j < name_nodes.size(); j++) {
468 const char * js_name = name_nodes[j]->getStringValue();
469 SG_LOG(SG_INPUT, SG_INFO, " Trying \"" << js_name << '"');
470 if (!strcmp(js_name, name)) {
471 SG_LOG(SG_INPUT, SG_INFO, " Found bindings");
483 joyGetDevCaps( i, &jsCaps, sizeof(jsCaps) );
484 int nbuttons = jsCaps.wNumButtons;
485 if (nbuttons > MAX_JOYSTICK_BUTTONS) nbuttons = MAX_JOYSTICK_BUTTONS;
487 int nbuttons = MAX_JOYSTICK_BUTTONS;
490 int naxes = js->getNumAxes();
491 if (naxes > MAX_JOYSTICK_AXES) naxes = MAX_JOYSTICK_AXES;
492 _joystick_bindings[i].naxes = naxes;
493 _joystick_bindings[i].nbuttons = nbuttons;
495 SG_LOG(SG_INPUT, SG_DEBUG, "Initializing joystick " << i);
497 // Set up range arrays
498 float minRange[MAX_JOYSTICK_AXES];
499 float maxRange[MAX_JOYSTICK_AXES];
500 float center[MAX_JOYSTICK_AXES];
502 // Initialize with default values
503 js->getMinRange(minRange);
504 js->getMaxRange(maxRange);
505 js->getCenter(center);
507 // Allocate axes and buttons
508 _joystick_bindings[i].axes = new axis[naxes];
509 _joystick_bindings[i].buttons = new button[nbuttons];
513 // Initialize the axes.
516 for (j = 0; j < naxes; j++) {
517 const SGPropertyNode * axis_node = js_node->getChild("axis", j);
518 if (axis_node == 0) {
519 SG_LOG(SG_INPUT, SG_DEBUG, "No bindings for axis " << j);
520 axis_node = js_node->getChild("axis", j, true);
523 axis &a = _joystick_bindings[i].axes[j];
525 js->setDeadBand(j, axis_node->getDoubleValue("dead-band", 0.0));
527 a.tolerance = axis_node->getDoubleValue("tolerance", 0.002);
528 minRange[j] = axis_node->getDoubleValue("min-range", minRange[j]);
529 maxRange[j] = axis_node->getDoubleValue("max-range", maxRange[j]);
530 center[j] = axis_node->getDoubleValue("center", center[j]);
532 _read_bindings(axis_node, a.bindings, FG_MOD_NONE);
534 // Initialize the virtual axis buttons.
535 _init_button(axis_node->getChild("low"), a.low, "low");
536 a.low_threshold = axis_node->getDoubleValue("low-threshold", -0.9);
538 _init_button(axis_node->getChild("high"), a.high, "high");
539 a.high_threshold = axis_node->getDoubleValue("high-threshold", 0.9);
543 // Initialize the buttons.
546 for (j = 0; j < nbuttons; j++) {
547 sprintf(buf, "%d", j);
548 SG_LOG(SG_INPUT, SG_DEBUG, "Initializing button " << j);
549 _init_button(js_node->getChild("button", j),
550 _joystick_bindings[i].buttons[j],
555 js->setMinRange(minRange);
556 js->setMaxRange(maxRange);
557 js->setCenter(center);
562 // Map of all known GLUT cursor names
567 } mouse_cursor_map[] = {
568 { "right-arrow", GLUT_CURSOR_RIGHT_ARROW },
569 { "left-arrow", GLUT_CURSOR_LEFT_ARROW },
570 { "info", GLUT_CURSOR_INFO },
571 { "destroy", GLUT_CURSOR_DESTROY },
572 { "help", GLUT_CURSOR_HELP },
573 { "cycle", GLUT_CURSOR_CYCLE },
574 { "spray", GLUT_CURSOR_SPRAY },
575 { "wait", GLUT_CURSOR_WAIT },
576 { "text", GLUT_CURSOR_TEXT },
577 { "crosshair", GLUT_CURSOR_CROSSHAIR },
578 { "up-down", GLUT_CURSOR_UP_DOWN },
579 { "left-right", GLUT_CURSOR_LEFT_RIGHT },
580 { "top-side", GLUT_CURSOR_TOP_SIDE },
581 { "bottom-side", GLUT_CURSOR_BOTTOM_SIDE },
582 { "left-side", GLUT_CURSOR_LEFT_SIDE },
583 { "right-side", GLUT_CURSOR_RIGHT_SIDE },
584 { "top-left-corner", GLUT_CURSOR_TOP_LEFT_CORNER },
585 { "top-right-corner", GLUT_CURSOR_TOP_RIGHT_CORNER },
586 { "bottom-right-corner", GLUT_CURSOR_BOTTOM_RIGHT_CORNER },
587 { "bottom-left-corner", GLUT_CURSOR_BOTTOM_LEFT_CORNER },
588 { "inherit", GLUT_CURSOR_INHERIT },
589 { "none", GLUT_CURSOR_NONE },
590 { "full-crosshair", GLUT_CURSOR_FULL_CROSSHAIR },
597 FGInput::_init_mouse ()
599 SG_LOG(SG_INPUT, SG_DEBUG, "Initializing mouse bindings");
601 SGPropertyNode * mouse_nodes = fgGetNode("/input/mice");
602 if (mouse_nodes == 0) {
603 SG_LOG(SG_INPUT, SG_WARN, "No mouse bindings (/input/mice)!!");
604 mouse_nodes = fgGetNode("/input/mice", true);
608 for (int i = 0; i < MAX_MICE; i++) {
609 SGPropertyNode * mouse_node = mouse_nodes->getChild("mouse", i, true);
610 mouse &m = _mouse_bindings[i];
612 // Grab node pointers
614 sprintf(buf, "/devices/status/mice/mouse[%d]/mode", i);
615 m.mode_node = fgGetNode(buf, true);
616 m.mode_node->setIntValue(0);
617 for (j = 0; j < MAX_MOUSE_BUTTONS; j++) {
618 sprintf(buf, "/devices/status/mice/mouse[%d]/button[%d]", i, j);
619 m.mouse_button_nodes[j] = fgGetNode(buf, true);
620 m.mouse_button_nodes[j]->setBoolValue(false);
623 // Read all the modes
624 m.nModes = mouse_node->getIntValue("mode-count", 1);
625 m.modes = new mouse_mode[m.nModes];
627 for (int j = 0; j < m.nModes; j++) {
630 // Read the mouse cursor for this mode
631 SGPropertyNode * mode_node = mouse_node->getChild("mode", j, true);
632 const char * cursor_name =
633 mode_node->getStringValue("cursor", "inherit");
634 m.modes[j].cursor = GLUT_CURSOR_INHERIT;
635 for (k = 0; mouse_cursor_map[k].name != 0; k++) {
636 if (!strcmp(mouse_cursor_map[k].name, cursor_name)) {
637 m.modes[j].cursor = mouse_cursor_map[k].cursor;
642 // Read other properties for this mode
643 m.modes[j].constrained = mode_node->getBoolValue("constrained", false);
644 m.modes[j].pass_through = mode_node->getBoolValue("pass-through", false);
646 // Read the button bindings for this mode
647 m.modes[j].buttons = new button[MAX_MOUSE_BUTTONS];
649 for (k = 0; k < MAX_MOUSE_BUTTONS; k++) {
650 sprintf(buf, "mouse button %d", k);
651 SG_LOG(SG_INPUT, SG_DEBUG, "Initializing mouse button " << k);
652 _init_button(mode_node->getChild("button", k),
653 m.modes[j].buttons[k],
657 // Read the axis bindings for this mode
658 _read_bindings(mode_node->getChild("x-axis", 0, true),
659 m.modes[j].x_bindings,
661 _read_bindings(mode_node->getChild("y-axis", 0, true),
662 m.modes[j].y_bindings,
670 FGInput::_init_button (const SGPropertyNode * node,
675 SG_LOG(SG_INPUT, SG_DEBUG, "No bindings for button " << name);
677 b.is_repeatable = node->getBoolValue("repeatable", b.is_repeatable);
679 // Get the bindings for the button
680 _read_bindings(node, b.bindings, FG_MOD_NONE);
686 FGInput::_update_keyboard ()
693 FGInput::_update_joystick ()
695 int modifiers = FG_MOD_NONE; // FIXME: any way to get the real ones?
697 // float js_val, diff;
698 float axis_values[MAX_JOYSTICK_AXES];
703 for ( i = 0; i < MAX_JOYSTICKS; i++) {
705 jsJoystick * js = _joystick_bindings[i].js;
706 if (js == 0 || js->notWorking())
709 js->read(&buttons, axis_values);
712 // Fire bindings for the axes.
713 for ( j = 0; j < _joystick_bindings[i].naxes; j++) {
714 axis &a = _joystick_bindings[i].axes[j];
716 // Do nothing if the axis position
717 // is unchanged; only a change in
718 // position fires the bindings.
719 if (fabs(axis_values[j] - a.last_value) > a.tolerance) {
720 // SG_LOG(SG_INPUT, SG_DEBUG, "Axis " << j << " has moved");
722 a.last_value = axis_values[j];
723 // SG_LOG(SG_INPUT, SG_DEBUG, "There are "
724 // << a.bindings[modifiers].size() << " bindings");
725 for (unsigned int k = 0; k < a.bindings[modifiers].size(); k++)
726 a.bindings[modifiers][k]->fire(axis_values[j]);
729 // do we have to emulate axis buttons?
730 if (a.low.bindings[modifiers].size())
731 _update_button(_joystick_bindings[i].axes[j].low,
733 axis_values[j] < a.low_threshold,
736 if (a.high.bindings[modifiers].size())
737 _update_button(_joystick_bindings[i].axes[j].high,
739 axis_values[j] > a.high_threshold,
743 // Fire bindings for the buttons.
744 for (j = 0; j < _joystick_bindings[i].nbuttons; j++) {
745 _update_button(_joystick_bindings[i].buttons[j],
747 (buttons & (1 << j)) > 0,
754 FGInput::_update_mouse ()
756 mouse &m = _mouse_bindings[0];
757 int mode = m.mode_node->getIntValue();
758 if (mode != m.current_mode) {
759 m.current_mode = mode;
760 if (mode >= 0 && mode < m.nModes) {
761 glutSetCursor(m.modes[mode].cursor);
762 m.x = fgGetInt("/sim/startup/xsize", 800) / 2;
763 m.y = fgGetInt("/sim/startup/ysize", 600) / 2;
764 glutWarpPointer(m.x, m.y);
766 SG_LOG(SG_INPUT, SG_DEBUG, "Mouse mode " << mode << " out of range");
767 glutSetCursor(GLUT_CURSOR_INHERIT);
773 FGInput::_update_button (button &b, int modifiers, bool pressed,
777 // The press event may be repeated.
778 if (!b.last_state || b.is_repeatable) {
779 SG_LOG( SG_INPUT, SG_DEBUG, "Button has been pressed" );
780 for (unsigned int k = 0; k < b.bindings[modifiers].size(); k++)
781 b.bindings[modifiers][k]->fire(x, y);
784 // The release event is never repeated.
786 SG_LOG( SG_INPUT, SG_DEBUG, "Button has been released" );
787 for (unsigned int k = 0; k < b.bindings[modifiers|FG_MOD_UP].size(); k++)
788 b.bindings[modifiers|FG_MOD_UP][k]->fire(x, y);
792 b.last_state = pressed;
797 FGInput::_read_bindings (const SGPropertyNode * node,
798 binding_list_t * binding_list,
801 SG_LOG(SG_INPUT, SG_DEBUG, "Reading all bindings");
802 vector<SGPropertyNode_ptr> bindings = node->getChildren("binding");
803 for (unsigned int i = 0; i < bindings.size(); i++) {
804 SG_LOG(SG_INPUT, SG_DEBUG, "Reading binding "
805 << bindings[i]->getStringValue("command"));
806 binding_list[modifiers].push_back(new FGBinding(bindings[i]));
809 // Read nested bindings for modifiers
810 if (node->getChild("mod-up") != 0)
811 _read_bindings(node->getChild("mod-up"), binding_list,
812 modifiers|FG_MOD_UP);
814 if (node->getChild("mod-shift") != 0)
815 _read_bindings(node->getChild("mod-shift"), binding_list,
816 modifiers|FG_MOD_SHIFT);
818 if (node->getChild("mod-ctrl") != 0)
819 _read_bindings(node->getChild("mod-ctrl"), binding_list,
820 modifiers|FG_MOD_CTRL);
822 if (node->getChild("mod-alt") != 0)
823 _read_bindings(node->getChild("mod-alt"), binding_list,
824 modifiers|FG_MOD_ALT);
828 const vector<FGBinding *> &
829 FGInput::_find_key_bindings (unsigned int k, int modifiers)
831 button &b = _key_bindings[k];
833 // Try it straight, first.
834 if (b.bindings[modifiers].size() > 0)
835 return b.bindings[modifiers];
837 // Try removing the control modifier
839 else if ((modifiers&FG_MOD_CTRL) && iscntrl(k))
840 return _find_key_bindings(k, modifiers&~FG_MOD_CTRL);
842 // Try removing shift modifier
843 // for upper case or any punctuation
844 // (since different keyboards will
845 // shift different punctuation types)
846 else if ((modifiers&FG_MOD_SHIFT) && (isupper(k) || ispunct(k)))
847 return _find_key_bindings(k, modifiers&~FG_MOD_SHIFT);
849 // Try removing alt modifier for
850 // high-bit characters.
851 else if ((modifiers&FG_MOD_ALT) && k >= 128 && k < 256)
852 return _find_key_bindings(k, modifiers&~FG_MOD_ALT);
854 // Give up and return the empty vector.
856 return b.bindings[modifiers];
861 ////////////////////////////////////////////////////////////////////////
862 // Implementation of FGInput::button.
863 ////////////////////////////////////////////////////////////////////////
865 FGInput::button::button ()
866 : is_repeatable(false),
871 FGInput::button::~button ()
873 // FIXME: memory leak
874 // for (int i = 0; i < FG_MOD_MAX; i++)
875 // for (int j = 0; i < bindings[i].size(); j++)
876 // delete bindings[i][j];
881 ////////////////////////////////////////////////////////////////////////
882 // Implementation of FGInput::axis.
883 ////////////////////////////////////////////////////////////////////////
885 FGInput::axis::axis ()
886 : last_value(9999999),
893 FGInput::axis::~axis ()
895 // for (int i = 0; i < FG_MOD_MAX; i++)
896 // for (int j = 0; i < bindings[i].size(); j++)
897 // delete bindings[i][j];
902 ////////////////////////////////////////////////////////////////////////
903 // Implementation of FGInput::joystick.
904 ////////////////////////////////////////////////////////////////////////
906 FGInput::joystick::joystick ()
910 FGInput::joystick::~joystick ()
919 ////////////////////////////////////////////////////////////////////////
920 // Implementation of FGInput::mouse_mode
921 ////////////////////////////////////////////////////////////////////////
923 FGInput::mouse_mode::mouse_mode ()
924 : cursor(GLUT_CURSOR_INHERIT),
931 FGInput::mouse_mode::~mouse_mode ()
933 // FIXME: memory leak
934 // for (int i = 0; i < FG_MOD_MAX; i++) {
936 // for (j = 0; i < x_bindings[i].size(); j++)
937 // delete bindings[i][j];
938 // for (j = 0; j < y_bindings[i].size(); j++)
939 // delete bindings[i][j];
946 ////////////////////////////////////////////////////////////////////////
947 // Implementation of FGInput::mouse
948 ////////////////////////////////////////////////////////////////////////
950 FGInput::mouse::mouse ()
959 FGInput::mouse::~mouse ()
966 ////////////////////////////////////////////////////////////////////////
967 // Implementation of GLUT callbacks.
968 ////////////////////////////////////////////////////////////////////////
972 * Construct the modifiers.
974 static inline int get_mods ()
976 int glut_modifiers = glutGetModifiers();
979 if (glut_modifiers & GLUT_ACTIVE_SHIFT)
980 modifiers |= FGInput::FG_MOD_SHIFT;
981 if (glut_modifiers & GLUT_ACTIVE_CTRL)
982 modifiers |= FGInput::FG_MOD_CTRL;
983 if (glut_modifiers & GLUT_ACTIVE_ALT)
984 modifiers |= FGInput::FG_MOD_ALT;
991 ////////////////////////////////////////////////////////////////////////
993 ////////////////////////////////////////////////////////////////////////
996 GLUTkey(unsigned char k, int x, int y)
998 // Give PUI a chance to grab it first.
999 if (!puKeyboard(k, PU_DOWN)) {
1000 if (default_input != 0)
1001 default_input->doKey(k, get_mods(), x, y);
1006 GLUTkeyup(unsigned char k, int x, int y)
1008 if (default_input != 0)
1009 default_input->doKey(k, get_mods()|FGInput::FG_MOD_UP, x, y);
1013 GLUTspecialkey(int k, int x, int y)
1015 // Give PUI a chance to grab it first.
1016 if (!puKeyboard(k + PU_KEY_GLUT_SPECIAL_OFFSET, PU_DOWN)) {
1017 if (default_input != 0)
1018 default_input->doKey(k + 256, get_mods(), x, y);
1023 GLUTspecialkeyup(int k, int x, int y)
1025 if (default_input != 0)
1026 default_input->doKey(k + 256, get_mods()|FGInput::FG_MOD_UP, x, y);
1030 GLUTmouse (int button, int updown, int x, int y)
1032 if (default_input != 0)
1033 default_input->doMouseClick(button, updown, x, y);
1037 GLUTmotion (int x, int y)
1039 if (default_input != 0)
1040 default_input->doMouseMotion(x, y);