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 if (n_axis >= (size_t)naxes) {
483 SG_LOG(SG_INPUT, SG_DEBUG, "Dropping bindings for axis " << n_axis);
486 axis &a = _joystick_bindings[i].axes[n_axis];
488 js->setDeadBand(n_axis, axis_node->getDoubleValue("dead-band", 0.0));
490 a.tolerance = axis_node->getDoubleValue("tolerance", 0.002);
491 minRange[n_axis] = axis_node->getDoubleValue("min-range", minRange[n_axis]);
492 maxRange[n_axis] = axis_node->getDoubleValue("max-range", maxRange[n_axis]);
493 center[n_axis] = axis_node->getDoubleValue("center", center[n_axis]);
495 _read_bindings(axis_node, a.bindings, KEYMOD_NONE);
497 // Initialize the virtual axis buttons.
498 _init_button(axis_node->getChild("low"), a.low, "low");
499 a.low_threshold = axis_node->getDoubleValue("low-threshold", -0.9);
501 _init_button(axis_node->getChild("high"), a.high, "high");
502 a.high_threshold = axis_node->getDoubleValue("high-threshold", 0.9);
503 a.interval_sec = axis_node->getDoubleValue("interval-sec",0.0);
508 // Initialize the buttons.
510 vector<SGPropertyNode_ptr> buttons = js_node->getChildren("button");
512 for (j = 0; (j < (int)buttons.size()) && (j < nbuttons); j++) {
513 const SGPropertyNode * button_node = buttons[j];
514 const SGPropertyNode * num_node = button_node->getChild("number");
515 size_t n_but = button_node->getIndex();
517 n_but = num_node->getIntValue(TGT_PLATFORM,n_but);
520 if (n_but >= (size_t)nbuttons) {
521 SG_LOG(SG_INPUT, SG_DEBUG, "Dropping bindings for button " << n_but);
525 sprintf(buf, "%d", n_but);
526 SG_LOG(SG_INPUT, SG_DEBUG, "Initializing button " << n_but);
527 _init_button(button_node,
528 _joystick_bindings[i].buttons[n_but],
531 // get interval-sec property
532 button &b = _joystick_bindings[i].buttons[n_but];
533 if (button_node != 0) {
534 b.interval_sec = button_node->getDoubleValue("interval-sec",0.0);
539 js->setMinRange(minRange);
540 js->setMaxRange(maxRange);
541 js->setCenter(center);
546 // Map of all known cursor names
547 // This used to contain all the Glut cursors, but those are
548 // not defined by other toolkits. It now supports only the cursor
549 // images we actually use, in the interest of portability. Someday,
550 // it would be cool to write an OpenGL cursor renderer, with the
551 // cursors defined as textures referenced in the property tree. This
552 // list could then be eliminated. -Andy
557 } mouse_cursor_map[] = {
558 { "none", MOUSE_CURSOR_NONE },
559 { "inherit", MOUSE_CURSOR_POINTER },
560 { "wait", MOUSE_CURSOR_WAIT },
561 { "crosshair", MOUSE_CURSOR_CROSSHAIR },
562 { "left-right", MOUSE_CURSOR_LEFTRIGHT },
567 FGInput::_init_mouse ()
569 SG_LOG(SG_INPUT, SG_DEBUG, "Initializing mouse bindings");
571 SGPropertyNode * mouse_nodes = fgGetNode("/input/mice");
572 if (mouse_nodes == 0) {
573 SG_LOG(SG_INPUT, SG_WARN, "No mouse bindings (/input/mice)!!");
574 mouse_nodes = fgGetNode("/input/mice", true);
578 for (int i = 0; i < MAX_MICE; i++) {
579 SGPropertyNode * mouse_node = mouse_nodes->getChild("mouse", i, true);
580 mouse &m = _mouse_bindings[i];
582 // Grab node pointers
584 sprintf(buf, "/devices/status/mice/mouse[%d]/mode", i);
585 m.mode_node = fgGetNode(buf);
586 if (m.mode_node == NULL) {
587 m.mode_node = fgGetNode(buf, true);
588 m.mode_node->setIntValue(0);
590 for (j = 0; j < MAX_MOUSE_BUTTONS; j++) {
591 sprintf(buf, "/devices/status/mice/mouse[%d]/button[%d]", i, j);
592 m.mouse_button_nodes[j] = fgGetNode(buf, true);
593 m.mouse_button_nodes[j]->setBoolValue(false);
596 // Read all the modes
597 m.nModes = mouse_node->getIntValue("mode-count", 1);
598 m.modes = new mouse_mode[m.nModes];
600 for (int j = 0; j < m.nModes; j++) {
603 // Read the mouse cursor for this mode
604 SGPropertyNode * mode_node = mouse_node->getChild("mode", j, true);
605 const char * cursor_name =
606 mode_node->getStringValue("cursor", "inherit");
607 m.modes[j].cursor = MOUSE_CURSOR_POINTER;
608 for (k = 0; mouse_cursor_map[k].name != 0; k++) {
609 if (!strcmp(mouse_cursor_map[k].name, cursor_name)) {
610 m.modes[j].cursor = mouse_cursor_map[k].cursor;
615 // Read other properties for this mode
616 m.modes[j].constrained = mode_node->getBoolValue("constrained", false);
617 m.modes[j].pass_through = mode_node->getBoolValue("pass-through", false);
619 // Read the button bindings for this mode
620 m.modes[j].buttons = new button[MAX_MOUSE_BUTTONS];
622 for (k = 0; k < MAX_MOUSE_BUTTONS; k++) {
623 sprintf(buf, "mouse button %d", k);
624 SG_LOG(SG_INPUT, SG_DEBUG, "Initializing mouse button " << k);
625 _init_button(mode_node->getChild("button", k),
626 m.modes[j].buttons[k],
630 // Read the axis bindings for this mode
631 _read_bindings(mode_node->getChild("x-axis", 0, true),
632 m.modes[j].x_bindings,
634 _read_bindings(mode_node->getChild("y-axis", 0, true),
635 m.modes[j].y_bindings,
643 FGInput::_init_button (const SGPropertyNode * node,
648 SG_LOG(SG_INPUT, SG_DEBUG, "No bindings for button " << name);
650 b.is_repeatable = node->getBoolValue("repeatable", b.is_repeatable);
652 // Get the bindings for the button
653 _read_bindings(node, b.bindings, KEYMOD_NONE);
659 FGInput::_update_keyboard ()
666 FGInput::_update_joystick (double dt)
668 int modifiers = KEYMOD_NONE; // FIXME: any way to get the real ones?
670 // float js_val, diff;
671 float axis_values[MAX_JOYSTICK_AXES];
676 for ( i = 0; i < MAX_JOYSTICKS; i++) {
678 jsJoystick * js = _joystick_bindings[i].js;
679 if (js == 0 || js->notWorking())
682 js->read(&buttons, axis_values);
685 // Fire bindings for the axes.
686 for ( j = 0; j < _joystick_bindings[i].naxes; j++) {
687 axis &a = _joystick_bindings[i].axes[j];
689 // Do nothing if the axis position
690 // is unchanged; only a change in
691 // position fires the bindings.
692 if (fabs(axis_values[j] - a.last_value) > a.tolerance) {
693 // SG_LOG(SG_INPUT, SG_DEBUG, "Axis " << j << " has moved");
695 a.last_value = axis_values[j];
696 // SG_LOG(SG_INPUT, SG_DEBUG, "There are "
697 // << a.bindings[modifiers].size() << " bindings");
698 for (unsigned int k = 0; k < a.bindings[modifiers].size(); k++)
699 a.bindings[modifiers][k]->fire(axis_values[j]);
702 // do we have to emulate axis buttons?
704 if(a.last_dt >= a.interval_sec) {
705 if (a.low.bindings[modifiers].size())
706 _update_button(_joystick_bindings[i].axes[j].low,
708 axis_values[j] < a.low_threshold,
711 if (a.high.bindings[modifiers].size())
712 _update_button(_joystick_bindings[i].axes[j].high,
714 axis_values[j] > a.high_threshold,
716 a.last_dt -= a.interval_sec;
720 // Fire bindings for the buttons.
721 for (j = 0; j < _joystick_bindings[i].nbuttons; j++) {
722 button &b = _joystick_bindings[i].buttons[j];
724 if(b.last_dt >= b.interval_sec) {
725 _update_button(_joystick_bindings[i].buttons[j],
727 (buttons & (1 << j)) > 0,
729 b.last_dt -= b.interval_sec;
736 FGInput::_update_mouse ( double dt )
738 mouse &m = _mouse_bindings[0];
739 int mode = m.mode_node->getIntValue();
740 if (mode != m.current_mode) {
741 m.current_mode = mode;
742 m.timeout = fgGetDouble( "/sim/mouse/cursor-timeout-sec", 10.0 );
743 if (mode >= 0 && mode < m.nModes) {
744 fgSetMouseCursor(m.modes[mode].cursor);
745 m.x = fgGetInt("/sim/startup/xsize", 800) / 2;
746 m.y = fgGetInt("/sim/startup/ysize", 600) / 2;
747 fgWarpMouse(m.x, m.y);
749 SG_LOG(SG_INPUT, SG_DEBUG, "Mouse mode " << mode << " out of range");
750 fgSetMouseCursor(MOUSE_CURSOR_POINTER);
754 if ( fgGetBool( "/sim/mouse/hide-cursor", true ) ) {
755 if ( m.x != m.save_x || m.y != m.save_y ) {
756 m.timeout = fgGetDouble( "/sim/mouse/cursor-timeout-sec", 10.0 );
757 fgSetMouseCursor(m.modes[mode].cursor);
760 if ( m.timeout <= 0.0 ) {
761 fgSetMouseCursor(MOUSE_CURSOR_NONE);
771 FGInput::_update_button (button &b, int modifiers, bool pressed,
775 // The press event may be repeated.
776 if (!b.last_state || b.is_repeatable) {
777 SG_LOG( SG_INPUT, SG_DEBUG, "Button has been pressed" );
778 for (unsigned int k = 0; k < b.bindings[modifiers].size(); k++)
779 b.bindings[modifiers][k]->fire(x, y);
782 // The release event is never repeated.
784 SG_LOG( SG_INPUT, SG_DEBUG, "Button has been released" );
785 for (unsigned int k = 0; k < b.bindings[modifiers|KEYMOD_RELEASED].size(); k++)
786 b.bindings[modifiers|KEYMOD_RELEASED][k]->fire(x, y);
790 b.last_state = pressed;
795 FGInput::_read_bindings (const SGPropertyNode * node,
796 binding_list_t * binding_list,
799 SG_LOG(SG_INPUT, SG_DEBUG, "Reading all bindings");
800 vector<SGPropertyNode_ptr> bindings = node->getChildren("binding");
801 for (unsigned int i = 0; i < bindings.size(); i++) {
802 SG_LOG(SG_INPUT, SG_DEBUG, "Reading binding "
803 << bindings[i]->getStringValue("command"));
804 binding_list[modifiers].push_back(new FGBinding(bindings[i]));
807 // Read nested bindings for modifiers
808 if (node->getChild("mod-up") != 0)
809 _read_bindings(node->getChild("mod-up"), binding_list,
810 modifiers|KEYMOD_RELEASED);
812 if (node->getChild("mod-shift") != 0)
813 _read_bindings(node->getChild("mod-shift"), binding_list,
814 modifiers|KEYMOD_SHIFT);
816 if (node->getChild("mod-ctrl") != 0)
817 _read_bindings(node->getChild("mod-ctrl"), binding_list,
818 modifiers|KEYMOD_CTRL);
820 if (node->getChild("mod-alt") != 0)
821 _read_bindings(node->getChild("mod-alt"), binding_list,
822 modifiers|KEYMOD_ALT);
826 const vector<FGBinding *> &
827 FGInput::_find_key_bindings (unsigned int k, int modifiers)
829 unsigned char kc = (unsigned char)k;
830 button &b = _key_bindings[k];
832 // Try it straight, first.
833 if (b.bindings[modifiers].size() > 0)
834 return b.bindings[modifiers];
836 // Alt-Gr is CTRL+ALT
837 else if (modifiers&(KEYMOD_CTRL|KEYMOD_ALT))
838 return _find_key_bindings(k, modifiers&~(KEYMOD_CTRL|KEYMOD_ALT));
840 // Try removing the control modifier
842 else if ((modifiers&KEYMOD_CTRL) && iscntrl(kc))
843 return _find_key_bindings(k, modifiers&~KEYMOD_CTRL);
845 // Try removing shift modifier
846 // for upper case or any punctuation
847 // (since different keyboards will
848 // shift different punctuation types)
849 else if ((modifiers&KEYMOD_SHIFT) && (isupper(kc) || ispunct(kc)))
850 return _find_key_bindings(k, modifiers&~KEYMOD_SHIFT);
852 // Try removing alt modifier for
853 // high-bit characters.
854 else if ((modifiers&KEYMOD_ALT) && k >= 128 && k < 256)
855 return _find_key_bindings(k, modifiers&~KEYMOD_ALT);
857 // Give up and return the empty vector.
859 return b.bindings[modifiers];
864 ////////////////////////////////////////////////////////////////////////
865 // Implementation of FGInput::button.
866 ////////////////////////////////////////////////////////////////////////
868 FGInput::button::button ()
869 : is_repeatable(false),
874 FGInput::button::~button ()
876 // FIXME: memory leak
877 // for (int i = 0; i < KEYMOD_MAX; i++)
878 // for (int j = 0; i < bindings[i].size(); j++)
879 // delete bindings[i][j];
884 ////////////////////////////////////////////////////////////////////////
885 // Implementation of FGInput::axis.
886 ////////////////////////////////////////////////////////////////////////
888 FGInput::axis::axis ()
889 : last_value(9999999),
896 FGInput::axis::~axis ()
898 // for (int i = 0; i < KEYMOD_MAX; i++)
899 // for (int j = 0; i < bindings[i].size(); j++)
900 // delete bindings[i][j];
905 ////////////////////////////////////////////////////////////////////////
906 // Implementation of FGInput::joystick.
907 ////////////////////////////////////////////////////////////////////////
909 FGInput::joystick::joystick ()
913 FGInput::joystick::~joystick ()
922 ////////////////////////////////////////////////////////////////////////
923 // Implementation of FGInput::mouse_mode
924 ////////////////////////////////////////////////////////////////////////
926 FGInput::mouse_mode::mouse_mode ()
927 : cursor(MOUSE_CURSOR_POINTER),
934 FGInput::mouse_mode::~mouse_mode ()
936 // FIXME: memory leak
937 // for (int i = 0; i < KEYMOD_MAX; i++) {
939 // for (j = 0; i < x_bindings[i].size(); j++)
940 // delete bindings[i][j];
941 // for (j = 0; j < y_bindings[i].size(); j++)
942 // delete bindings[i][j];
949 ////////////////////////////////////////////////////////////////////////
950 // Implementation of FGInput::mouse
951 ////////////////////////////////////////////////////////////////////////
953 FGInput::mouse::mouse ()
962 FGInput::mouse::~mouse ()
967 ////////////////////////////////////////////////////////////////////////
968 // Implementation of OS callbacks.
969 ////////////////////////////////////////////////////////////////////////
971 void keyHandler(int key, int keymod, int mousex, int mousey)
973 if((keymod & KEYMOD_RELEASED) == 0)
974 if(puKeyboard(key, PU_DOWN))
978 default_input->doKey(key, keymod, mousex, mousey);
981 void mouseClickHandler(int button, int updown, int x, int y)
984 default_input->doMouseClick(button, updown, x, y);
987 void mouseMotionHandler(int x, int y)
989 if (default_input != 0)
990 default_input->doMouseMotion(x, y);