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>
40 #include <simgear/compiler.h>
42 #include <simgear/constants.h>
43 #include <simgear/debug/logstream.hxx>
44 #include <simgear/props/props.hxx>
46 #include <Aircraft/aircraft.hxx>
47 #include <Autopilot/xmlauto.hxx>
48 #include <Cockpit/hud.hxx>
49 #include <Cockpit/panel.hxx>
50 #include <Cockpit/panel_io.hxx>
52 #include <Model/panelnode.hxx>
54 #include <Main/globals.hxx>
55 #include <Main/fg_props.hxx>
59 SG_USING_STD(ifstream);
63 void mouseClickHandler(int button, int updown, int x, int y);
64 void mouseMotionHandler(int x, int y);
65 void keyHandler(int key, int keymod, int mousex, int mousey);
68 ////////////////////////////////////////////////////////////////////////
70 ////////////////////////////////////////////////////////////////////////
72 static FGInput * default_input = 0;
76 ////////////////////////////////////////////////////////////////////////
77 // Implementation of FGBinding.
78 ////////////////////////////////////////////////////////////////////////
80 FGBinding::FGBinding ()
82 _arg(new SGPropertyNode),
87 FGBinding::FGBinding (const SGPropertyNode * node)
96 FGBinding::read (const SGPropertyNode * node)
98 const SGPropertyNode * conditionNode = node->getChild("condition");
99 if (conditionNode != 0)
100 setCondition(sgReadCondition(globals->get_props(), conditionNode));
102 _command_name = node->getStringValue("command", "");
103 if (_command_name.empty()) {
104 SG_LOG(SG_INPUT, SG_WARN, "No command supplied for binding.");
109 _arg = new SGPropertyNode;
111 copyProperties(node, _arg); // FIXME: don't use whole node!!!
115 FGBinding::fire () const
119 _command = globals->get_commands()->getCommand(_command_name);
121 SG_LOG(SG_INPUT, SG_WARN, "No command attached to binding");
122 } else if (!(*_command)(_arg)) {
123 SG_LOG(SG_INPUT, SG_ALERT, "Failed to execute command "
130 FGBinding::fire (double offset, double max) const
133 _arg->setDoubleValue("offset", offset/max);
139 FGBinding::fire (double setting) const
142 // A value is automatically added to
144 if (_setting == 0) // save the setting node for efficiency
145 _setting = _arg->getChild("setting", 0, true);
146 _setting->setDoubleValue(setting);
153 ////////////////////////////////////////////////////////////////////////
154 // Implementation of FGInput.
155 ////////////////////////////////////////////////////////////////////////
160 if (default_input == 0)
161 default_input = this;
166 if (default_input == this)
177 fgRegisterKeyHandler(keyHandler);
178 fgRegisterMouseClickHandler(mouseClickHandler);
179 fgRegisterMouseMotionHandler(mouseMotionHandler);
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&KEYMOD_RELEASED == 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++)
251 SG_LOG(SG_INPUT, SG_DEBUG, "User released key " << k
252 << " with modifiers " << modifiers);
254 const binding_list_t &bindings =
255 _find_key_bindings(k, modifiers);
256 int max = bindings.size();
258 for (int i = 0; i < max; i++)
267 FGInput::doMouseClick (int b, int updown, int x, int y)
269 int modifiers = fgGetKeyModifiers();
271 mouse &m = _mouse_bindings[0];
272 mouse_mode &mode = m.modes[m.current_mode];
274 // Let the property manager know.
275 if (b >= 0 && b < MAX_MOUSE_BUTTONS)
276 m.mouse_button_nodes[b]->setBoolValue(updown == MOUSE_BUTTON_DOWN);
278 // Pass on to PUI and the panel if
279 // requested, and return if one of
280 // them consumes the event.
281 if (mode.pass_through) {
282 if (puMouse(b, updown, x, y))
284 else if ((globals->get_current_panel() != 0) &&
285 globals->get_current_panel()->getVisibility() &&
286 globals->get_current_panel()->doMouseAction(b, updown, x, y))
288 else if (fgHandle3DPanelMouseEvent(b, updown, x, y))
292 // OK, PUI and the panel didn't want the click
293 if (b >= MAX_MOUSE_BUTTONS) {
294 SG_LOG(SG_INPUT, SG_ALERT, "Mouse button " << b
295 << " where only " << MAX_MOUSE_BUTTONS << " expected");
299 _update_button(m.modes[m.current_mode].buttons[b], modifiers, 0 != updown, x, y);
303 FGInput::doMouseMotion (int x, int y)
305 // Don't call fgGetKeyModifiers() here, until we are using a
306 // toolkit that supports getting the mods from outside a key
307 // callback. Glut doesn't.
308 int modifiers = KEYMOD_NONE;
310 int xsize = fgGetInt("/sim/startup/xsize", 800);
311 int ysize = fgGetInt("/sim/startup/ysize", 600);
313 mouse &m = _mouse_bindings[0];
315 if (m.current_mode < 0 || m.current_mode >= m.nModes) {
320 mouse_mode &mode = m.modes[m.current_mode];
322 // Pass on to PUI if requested, and return
323 // if PUI consumed the event.
324 if (mode.pass_through && puMouse(x, y)) {
330 // OK, PUI didn't want the event,
331 // so we can play with it.
334 for (unsigned int i = 0; i < mode.x_bindings[modifiers].size(); i++)
335 mode.x_bindings[modifiers][i]->fire(double(delta), double(xsize));
339 for (unsigned int i = 0; i < mode.y_bindings[modifiers].size(); i++)
340 mode.y_bindings[modifiers][i]->fire(double(delta), double(ysize));
343 // Constrain the mouse if requested
344 if (mode.constrained) {
345 bool need_warp = false;
349 } else if (x >= (xsize-1)) {
357 } else if (y >= (ysize-1)) {
370 FGInput::_init_keyboard ()
372 SG_LOG(SG_INPUT, SG_DEBUG, "Initializing key bindings");
373 SGPropertyNode * key_nodes = fgGetNode("/input/keyboard");
374 if (key_nodes == 0) {
375 SG_LOG(SG_INPUT, SG_WARN, "No key bindings (/input/keyboard)!!");
376 key_nodes = fgGetNode("/input/keyboard", true);
379 vector<SGPropertyNode_ptr> keys = key_nodes->getChildren("key");
380 for (unsigned int i = 0; i < keys.size(); i++) {
381 int index = keys[i]->getIndex();
382 SG_LOG(SG_INPUT, SG_DEBUG, "Binding key " << index);
384 _key_bindings[index].bindings->clear();
385 _key_bindings[index].is_repeatable = keys[i]->getBoolValue("repeatable");
386 _read_bindings(keys[i], _key_bindings[index].bindings, KEYMOD_NONE);
392 FGInput::_init_joystick ()
395 // TODO: zero the old bindings first.
396 SG_LOG(SG_INPUT, SG_DEBUG, "Initializing joystick bindings");
397 SGPropertyNode * js_nodes = fgGetNode("/input/joysticks");
399 SG_LOG(SG_INPUT, SG_WARN, "No joystick bindings (/input/joysticks)!!");
400 js_nodes = fgGetNode("/input/joysticks", true);
403 for (int i = 0; i < MAX_JOYSTICKS; i++) {
404 SGPropertyNode_ptr js_node = js_nodes->getChild("js", i);
406 SG_LOG(SG_INPUT, SG_DEBUG, "No bindings for joystick " << i);
407 js_node = js_nodes->getChild("js", i, true);
409 jsJoystick * js = new jsJoystick(i);
410 _joystick_bindings[i].js = js;
411 if (js->notWorking()) {
412 SG_LOG(SG_INPUT, SG_DEBUG, "Joystick " << i << " not found");
415 bool found_js = false;
416 const char * name = js->getName();
417 SG_LOG(SG_INPUT, SG_INFO, "Looking for bindings for joystick \""
419 vector<SGPropertyNode_ptr> nodes = js_nodes->getChildren("js-named");
420 for (unsigned int i = 0; i < nodes.size(); i++) {
421 SGPropertyNode_ptr node = nodes[i];
422 vector<SGPropertyNode_ptr> name_nodes = node->getChildren("name");
423 for (unsigned int j = 0; j < name_nodes.size(); j++) {
424 const char * js_name = name_nodes[j]->getStringValue();
425 SG_LOG(SG_INPUT, SG_INFO, " Trying \"" << js_name << '"');
426 if (!strcmp(js_name, name)) {
427 SG_LOG(SG_INPUT, SG_INFO, " Found bindings");
439 joyGetDevCaps( i, &jsCaps, sizeof(jsCaps) );
440 int nbuttons = jsCaps.wNumButtons;
441 if (nbuttons > MAX_JOYSTICK_BUTTONS) nbuttons = MAX_JOYSTICK_BUTTONS;
443 int nbuttons = MAX_JOYSTICK_BUTTONS;
446 int naxes = js->getNumAxes();
447 if (naxes > MAX_JOYSTICK_AXES) naxes = MAX_JOYSTICK_AXES;
448 _joystick_bindings[i].naxes = naxes;
449 _joystick_bindings[i].nbuttons = nbuttons;
451 SG_LOG(SG_INPUT, SG_DEBUG, "Initializing joystick " << i);
453 // Set up range arrays
454 float minRange[MAX_JOYSTICK_AXES];
455 float maxRange[MAX_JOYSTICK_AXES];
456 float center[MAX_JOYSTICK_AXES];
458 // Initialize with default values
459 js->getMinRange(minRange);
460 js->getMaxRange(maxRange);
461 js->getCenter(center);
463 // Allocate axes and buttons
464 _joystick_bindings[i].axes = new axis[naxes];
465 _joystick_bindings[i].buttons = new button[nbuttons];
469 // Initialize the axes.
471 vector<SGPropertyNode_ptr> axes = js_node->getChildren("axis");
472 size_t nb_axes = axes.size();
474 for (j = 0; j < (int)nb_axes; j++) {
475 const SGPropertyNode * axis_node = axes[j];
476 const SGPropertyNode * num_node = axis_node->getChild("number");
477 size_t n_axis = axis_node->getIndex();
479 n_axis = num_node->getIntValue(TGT_PLATFORM,n_axis);
482 axis &a = _joystick_bindings[i].axes[n_axis];
484 js->setDeadBand(n_axis, axis_node->getDoubleValue("dead-band", 0.0));
486 a.tolerance = axis_node->getDoubleValue("tolerance", 0.002);
487 minRange[n_axis] = axis_node->getDoubleValue("min-range", minRange[n_axis]);
488 maxRange[n_axis] = axis_node->getDoubleValue("max-range", maxRange[n_axis]);
489 center[n_axis] = axis_node->getDoubleValue("center", center[n_axis]);
491 _read_bindings(axis_node, a.bindings, KEYMOD_NONE);
493 // Initialize the virtual axis buttons.
494 _init_button(axis_node->getChild("low"), a.low, "low");
495 a.low_threshold = axis_node->getDoubleValue("low-threshold", -0.9);
497 _init_button(axis_node->getChild("high"), a.high, "high");
498 a.high_threshold = axis_node->getDoubleValue("high-threshold", 0.9);
499 a.interval_sec = axis_node->getDoubleValue("interval-sec",0.0);
504 // Initialize the buttons.
506 vector<SGPropertyNode_ptr> buttons = js_node->getChildren("button");
508 for (j = 0; (j < (int)buttons.size()) && (j < nbuttons); j++) {
509 const SGPropertyNode * button_node = buttons[j];
510 const SGPropertyNode * num_node = button_node->getChild("number");
511 size_t n_but = button_node->getIndex();
513 n_but = num_node->getIntValue(TGT_PLATFORM,n_but);
515 sprintf(buf, "%d", n_but);
516 SG_LOG(SG_INPUT, SG_DEBUG, "Initializing button " << n_but);
517 _init_button(button_node,
518 _joystick_bindings[i].buttons[n_but],
521 // get interval-sec property
522 button &b = _joystick_bindings[i].buttons[n_but];
523 if (button_node != 0) {
524 b.interval_sec = button_node->getDoubleValue("interval-sec",0.0);
529 js->setMinRange(minRange);
530 js->setMaxRange(maxRange);
531 js->setCenter(center);
536 // Map of all known cursor names
537 // This used to contain all the Glut cursors, but those are
538 // not defined by other toolkits. It now supports only the cursor
539 // images we actually use, in the interest of portability. Someday,
540 // it would be cool to write an OpenGL cursor renderer, with the
541 // cursors defined as textures referenced in the property tree. This
542 // list could then be eliminated. -Andy
547 } mouse_cursor_map[] = {
548 { "none", MOUSE_CURSOR_NONE },
549 { "inherit", MOUSE_CURSOR_POINTER },
550 { "wait", MOUSE_CURSOR_WAIT },
551 { "crosshair", MOUSE_CURSOR_CROSSHAIR },
552 { "left-right", MOUSE_CURSOR_LEFTRIGHT },
557 FGInput::_init_mouse ()
559 SG_LOG(SG_INPUT, SG_DEBUG, "Initializing mouse bindings");
561 SGPropertyNode * mouse_nodes = fgGetNode("/input/mice");
562 if (mouse_nodes == 0) {
563 SG_LOG(SG_INPUT, SG_WARN, "No mouse bindings (/input/mice)!!");
564 mouse_nodes = fgGetNode("/input/mice", true);
568 for (int i = 0; i < MAX_MICE; i++) {
569 SGPropertyNode * mouse_node = mouse_nodes->getChild("mouse", i, true);
570 mouse &m = _mouse_bindings[i];
572 // Grab node pointers
574 sprintf(buf, "/devices/status/mice/mouse[%d]/mode", i);
575 m.mode_node = fgGetNode(buf);
576 if (m.mode_node == NULL) {
577 m.mode_node = fgGetNode(buf, true);
578 m.mode_node->setIntValue(0);
580 for (j = 0; j < MAX_MOUSE_BUTTONS; j++) {
581 sprintf(buf, "/devices/status/mice/mouse[%d]/button[%d]", i, j);
582 m.mouse_button_nodes[j] = fgGetNode(buf, true);
583 m.mouse_button_nodes[j]->setBoolValue(false);
586 // Read all the modes
587 m.nModes = mouse_node->getIntValue("mode-count", 1);
588 m.modes = new mouse_mode[m.nModes];
590 for (int j = 0; j < m.nModes; j++) {
593 // Read the mouse cursor for this mode
594 SGPropertyNode * mode_node = mouse_node->getChild("mode", j, true);
595 const char * cursor_name =
596 mode_node->getStringValue("cursor", "inherit");
597 m.modes[j].cursor = MOUSE_CURSOR_POINTER;
598 for (k = 0; mouse_cursor_map[k].name != 0; k++) {
599 if (!strcmp(mouse_cursor_map[k].name, cursor_name)) {
600 m.modes[j].cursor = mouse_cursor_map[k].cursor;
605 // Read other properties for this mode
606 m.modes[j].constrained = mode_node->getBoolValue("constrained", false);
607 m.modes[j].pass_through = mode_node->getBoolValue("pass-through", false);
609 // Read the button bindings for this mode
610 m.modes[j].buttons = new button[MAX_MOUSE_BUTTONS];
612 for (k = 0; k < MAX_MOUSE_BUTTONS; k++) {
613 sprintf(buf, "mouse button %d", k);
614 SG_LOG(SG_INPUT, SG_DEBUG, "Initializing mouse button " << k);
615 _init_button(mode_node->getChild("button", k),
616 m.modes[j].buttons[k],
620 // Read the axis bindings for this mode
621 _read_bindings(mode_node->getChild("x-axis", 0, true),
622 m.modes[j].x_bindings,
624 _read_bindings(mode_node->getChild("y-axis", 0, true),
625 m.modes[j].y_bindings,
633 FGInput::_init_button (const SGPropertyNode * node,
638 SG_LOG(SG_INPUT, SG_DEBUG, "No bindings for button " << name);
640 b.is_repeatable = node->getBoolValue("repeatable", b.is_repeatable);
642 // Get the bindings for the button
643 _read_bindings(node, b.bindings, KEYMOD_NONE);
649 FGInput::_update_keyboard ()
656 FGInput::_update_joystick (double dt)
658 int modifiers = KEYMOD_NONE; // FIXME: any way to get the real ones?
660 // float js_val, diff;
661 float axis_values[MAX_JOYSTICK_AXES];
666 for ( i = 0; i < MAX_JOYSTICKS; i++) {
668 jsJoystick * js = _joystick_bindings[i].js;
669 if (js == 0 || js->notWorking())
672 js->read(&buttons, axis_values);
675 // Fire bindings for the axes.
676 for ( j = 0; j < _joystick_bindings[i].naxes; j++) {
677 axis &a = _joystick_bindings[i].axes[j];
679 // Do nothing if the axis position
680 // is unchanged; only a change in
681 // position fires the bindings.
682 if (fabs(axis_values[j] - a.last_value) > a.tolerance) {
683 // SG_LOG(SG_INPUT, SG_DEBUG, "Axis " << j << " has moved");
685 a.last_value = axis_values[j];
686 // SG_LOG(SG_INPUT, SG_DEBUG, "There are "
687 // << a.bindings[modifiers].size() << " bindings");
688 for (unsigned int k = 0; k < a.bindings[modifiers].size(); k++)
689 a.bindings[modifiers][k]->fire(axis_values[j]);
692 // do we have to emulate axis buttons?
694 if(a.last_dt >= a.interval_sec) {
695 if (a.low.bindings[modifiers].size())
696 _update_button(_joystick_bindings[i].axes[j].low,
698 axis_values[j] < a.low_threshold,
701 if (a.high.bindings[modifiers].size())
702 _update_button(_joystick_bindings[i].axes[j].high,
704 axis_values[j] > a.high_threshold,
706 a.last_dt -= a.interval_sec;
710 // Fire bindings for the buttons.
711 for (j = 0; j < _joystick_bindings[i].nbuttons; j++) {
712 button &b = _joystick_bindings[i].buttons[j];
714 if(b.last_dt >= b.interval_sec) {
715 _update_button(_joystick_bindings[i].buttons[j],
717 (buttons & (1 << j)) > 0,
719 b.last_dt -= b.interval_sec;
726 FGInput::_update_mouse ( double dt )
728 mouse &m = _mouse_bindings[0];
729 int mode = m.mode_node->getIntValue();
730 if (mode != m.current_mode) {
731 m.current_mode = mode;
732 m.timeout = fgGetDouble( "/sim/mouse/cursor-timeout-sec", 10.0 );
733 if (mode >= 0 && mode < m.nModes) {
734 fgSetMouseCursor(m.modes[mode].cursor);
735 m.x = fgGetInt("/sim/startup/xsize", 800) / 2;
736 m.y = fgGetInt("/sim/startup/ysize", 600) / 2;
737 fgWarpMouse(m.x, m.y);
739 SG_LOG(SG_INPUT, SG_DEBUG, "Mouse mode " << mode << " out of range");
740 fgSetMouseCursor(MOUSE_CURSOR_POINTER);
744 if ( fgGetBool( "/sim/mouse/hide-cursor", true ) ) {
745 if ( m.x != m.save_x || m.y != m.save_y ) {
746 m.timeout = fgGetDouble( "/sim/mouse/cursor-timeout-sec", 10.0 );
747 fgSetMouseCursor(m.modes[mode].cursor);
750 if ( m.timeout <= 0.0 ) {
751 fgSetMouseCursor(MOUSE_CURSOR_NONE);
761 FGInput::_update_button (button &b, int modifiers, bool pressed,
765 // The press event may be repeated.
766 if (!b.last_state || b.is_repeatable) {
767 SG_LOG( SG_INPUT, SG_DEBUG, "Button has been pressed" );
768 for (unsigned int k = 0; k < b.bindings[modifiers].size(); k++)
769 b.bindings[modifiers][k]->fire(x, y);
772 // The release event is never repeated.
774 SG_LOG( SG_INPUT, SG_DEBUG, "Button has been released" );
775 for (unsigned int k = 0; k < b.bindings[modifiers|KEYMOD_RELEASED].size(); k++)
776 b.bindings[modifiers|KEYMOD_RELEASED][k]->fire(x, y);
780 b.last_state = pressed;
785 FGInput::_read_bindings (const SGPropertyNode * node,
786 binding_list_t * binding_list,
789 SG_LOG(SG_INPUT, SG_DEBUG, "Reading all bindings");
790 vector<SGPropertyNode_ptr> bindings = node->getChildren("binding");
791 for (unsigned int i = 0; i < bindings.size(); i++) {
792 SG_LOG(SG_INPUT, SG_DEBUG, "Reading binding "
793 << bindings[i]->getStringValue("command"));
794 binding_list[modifiers].push_back(new FGBinding(bindings[i]));
797 // Read nested bindings for modifiers
798 if (node->getChild("mod-up") != 0)
799 _read_bindings(node->getChild("mod-up"), binding_list,
800 modifiers|KEYMOD_RELEASED);
802 if (node->getChild("mod-shift") != 0)
803 _read_bindings(node->getChild("mod-shift"), binding_list,
804 modifiers|KEYMOD_SHIFT);
806 if (node->getChild("mod-ctrl") != 0)
807 _read_bindings(node->getChild("mod-ctrl"), binding_list,
808 modifiers|KEYMOD_CTRL);
810 if (node->getChild("mod-alt") != 0)
811 _read_bindings(node->getChild("mod-alt"), binding_list,
812 modifiers|KEYMOD_ALT);
816 const vector<FGBinding *> &
817 FGInput::_find_key_bindings (unsigned int k, int modifiers)
819 unsigned char kc = (unsigned char)k;
820 button &b = _key_bindings[k];
822 // Try it straight, first.
823 if (b.bindings[modifiers].size() > 0)
824 return b.bindings[modifiers];
826 // Alt-Gr is CTRL+ALT
827 else if (modifiers&(KEYMOD_CTRL|KEYMOD_ALT))
828 return _find_key_bindings(k, modifiers&~(KEYMOD_CTRL|KEYMOD_ALT));
830 // Try removing the control modifier
832 else if ((modifiers&KEYMOD_CTRL) && iscntrl(kc))
833 return _find_key_bindings(k, modifiers&~KEYMOD_CTRL);
835 // Try removing shift modifier
836 // for upper case or any punctuation
837 // (since different keyboards will
838 // shift different punctuation types)
839 else if ((modifiers&KEYMOD_SHIFT) && (isupper(kc) || ispunct(kc)))
840 return _find_key_bindings(k, modifiers&~KEYMOD_SHIFT);
842 // Try removing alt modifier for
843 // high-bit characters.
844 else if ((modifiers&KEYMOD_ALT) && k >= 128 && k < 256)
845 return _find_key_bindings(k, modifiers&~KEYMOD_ALT);
847 // Give up and return the empty vector.
849 return b.bindings[modifiers];
854 ////////////////////////////////////////////////////////////////////////
855 // Implementation of FGInput::button.
856 ////////////////////////////////////////////////////////////////////////
858 FGInput::button::button ()
859 : is_repeatable(false),
864 FGInput::button::~button ()
866 // FIXME: memory leak
867 // for (int i = 0; i < KEYMOD_MAX; i++)
868 // for (int j = 0; i < bindings[i].size(); j++)
869 // delete bindings[i][j];
874 ////////////////////////////////////////////////////////////////////////
875 // Implementation of FGInput::axis.
876 ////////////////////////////////////////////////////////////////////////
878 FGInput::axis::axis ()
879 : last_value(9999999),
886 FGInput::axis::~axis ()
888 // for (int i = 0; i < KEYMOD_MAX; i++)
889 // for (int j = 0; i < bindings[i].size(); j++)
890 // delete bindings[i][j];
895 ////////////////////////////////////////////////////////////////////////
896 // Implementation of FGInput::joystick.
897 ////////////////////////////////////////////////////////////////////////
899 FGInput::joystick::joystick ()
903 FGInput::joystick::~joystick ()
912 ////////////////////////////////////////////////////////////////////////
913 // Implementation of FGInput::mouse_mode
914 ////////////////////////////////////////////////////////////////////////
916 FGInput::mouse_mode::mouse_mode ()
917 : cursor(MOUSE_CURSOR_POINTER),
924 FGInput::mouse_mode::~mouse_mode ()
926 // FIXME: memory leak
927 // for (int i = 0; i < KEYMOD_MAX; i++) {
929 // for (j = 0; i < x_bindings[i].size(); j++)
930 // delete bindings[i][j];
931 // for (j = 0; j < y_bindings[i].size(); j++)
932 // delete bindings[i][j];
939 ////////////////////////////////////////////////////////////////////////
940 // Implementation of FGInput::mouse
941 ////////////////////////////////////////////////////////////////////////
943 FGInput::mouse::mouse ()
952 FGInput::mouse::~mouse ()
957 ////////////////////////////////////////////////////////////////////////
958 // Implementation of OS callbacks.
959 ////////////////////////////////////////////////////////////////////////
961 void keyHandler(int key, int keymod, int mousex, int mousey)
963 if((keymod & KEYMOD_RELEASED) == 0)
964 if(puKeyboard(key, PU_DOWN))
968 default_input->doKey(key, keymod, mousex, mousey);
971 void mouseClickHandler(int button, int updown, int x, int y)
974 default_input->doMouseClick(button, updown, x, y);
977 void mouseMotionHandler(int x, int y)
979 if (default_input != 0)
980 default_input->doMouseMotion(x, y);