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);
183 FGInput::update (double dt)
186 _update_joystick(dt);
203 FGInput::is_suspended () const
209 FGInput::makeDefault (bool status)
212 default_input = this;
213 else if (default_input == this)
218 FGInput::doKey (int k, int modifiers, int x, int y)
221 if (k < 0 || k >= MAX_KEYS) {
222 SG_LOG(SG_INPUT, SG_WARN, "Key value " << k << " out of range");
226 button &b = _key_bindings[k];
229 if (modifiers&KEYMOD_RELEASED == 0) {
230 SG_LOG( SG_INPUT, SG_DEBUG, "User pressed key " << k
231 << " with modifiers " << modifiers );
232 if (!b.last_state || b.is_repeatable) {
233 const binding_list_t &bindings =
234 _find_key_bindings(k, modifiers);
235 int max = bindings.size();
237 for (int i = 0; i < max; i++)
246 SG_LOG(SG_INPUT, SG_DEBUG, "User released key " << k
247 << " with modifiers " << modifiers);
249 const binding_list_t &bindings =
250 _find_key_bindings(k, modifiers);
251 int max = bindings.size();
253 for (int i = 0; i < max; i++)
259 // Use the old, default actions.
260 SG_LOG( SG_INPUT, SG_DEBUG, "(No user binding.)" );
262 if (modifiers & KEYMOD_RELEASED)
265 // Hard-coded legacy key handlers.
266 // These need to be turned into FGCommand bindings and mapped via
267 // the input configuration...
270 HUD_brightkey( true );
273 HUD_masterswitch( true );
276 fgHUDInit2(¤t_aircraft); // Minimal Hud
279 fgHUDInit(¤t_aircraft); // normal HUD
285 FGInput::doMouseClick (int b, int updown, int x, int y)
287 int modifiers = fgGetKeyModifiers();
289 mouse &m = _mouse_bindings[0];
290 mouse_mode &mode = m.modes[m.current_mode];
292 // Let the property manager know.
293 if (b >= 0 && b < MAX_MOUSE_BUTTONS)
294 m.mouse_button_nodes[b]->setBoolValue(updown == MOUSE_BUTTON_DOWN);
296 // Pass on to PUI and the panel if
297 // requested, and return if one of
298 // them consumes the event.
299 if (mode.pass_through) {
300 if (puMouse(b, updown, x, y))
302 else if ((globals->get_current_panel() != 0) &&
303 globals->get_current_panel()->getVisibility() &&
304 globals->get_current_panel()->doMouseAction(b, updown, x, y))
306 else if (fgHandle3DPanelMouseEvent(b, updown, x, y))
310 // OK, PUI and the panel didn't want the click
311 if (b >= MAX_MOUSE_BUTTONS) {
312 SG_LOG(SG_INPUT, SG_ALERT, "Mouse button " << b
313 << " where only " << MAX_MOUSE_BUTTONS << " expected");
317 _update_button(m.modes[m.current_mode].buttons[b], modifiers, 0 != updown, x, y);
321 FGInput::doMouseMotion (int x, int y)
323 // Don't call fgGetKeyModifiers() here, until we are using a
324 // toolkit that supports getting the mods from outside a key
325 // callback. Glut doesn't.
326 int modifiers = KEYMOD_NONE;
328 int xsize = fgGetInt("/sim/startup/xsize", 800);
329 int ysize = fgGetInt("/sim/startup/ysize", 600);
330 mouse &m = _mouse_bindings[0];
331 if (m.current_mode < 0 || m.current_mode >= m.nModes)
333 mouse_mode &mode = m.modes[m.current_mode];
335 // Pass on to PUI if requested, and return
336 // if PUI consumed the event.
337 if (mode.pass_through && puMouse(x, y))
340 // OK, PUI didn't want the event,
341 // so we can play with it.
344 for (unsigned int i = 0; i < mode.x_bindings[modifiers].size(); i++)
345 mode.x_bindings[modifiers][i]->fire(double(delta), double(xsize));
349 for (unsigned int i = 0; i < mode.y_bindings[modifiers].size(); i++)
350 mode.y_bindings[modifiers][i]->fire(double(delta), double(ysize));
353 // Constrain the mouse if requested
354 if (mode.constrained) {
355 bool need_warp = false;
359 } else if (x >= (xsize-1)) {
367 } else if (y >= (ysize-1)) {
380 FGInput::_init_keyboard ()
382 SG_LOG(SG_INPUT, SG_DEBUG, "Initializing key bindings");
383 SGPropertyNode * key_nodes = fgGetNode("/input/keyboard");
384 if (key_nodes == 0) {
385 SG_LOG(SG_INPUT, SG_WARN, "No key bindings (/input/keyboard)!!");
386 key_nodes = fgGetNode("/input/keyboard", true);
389 vector<SGPropertyNode_ptr> keys = key_nodes->getChildren("key");
390 for (unsigned int i = 0; i < keys.size(); i++) {
391 int index = keys[i]->getIndex();
392 SG_LOG(SG_INPUT, SG_DEBUG, "Binding key " << index);
394 _key_bindings[index].bindings->clear();
395 _key_bindings[index].is_repeatable = keys[i]->getBoolValue("repeatable");
396 _read_bindings(keys[i], _key_bindings[index].bindings, KEYMOD_NONE);
402 FGInput::_init_joystick ()
404 // TODO: zero the old bindings first.
405 SG_LOG(SG_INPUT, SG_DEBUG, "Initializing joystick bindings");
406 SGPropertyNode * js_nodes = fgGetNode("/input/joysticks");
408 SG_LOG(SG_INPUT, SG_WARN, "No joystick bindings (/input/joysticks)!!");
409 js_nodes = fgGetNode("/input/joysticks", true);
412 for (int i = 0; i < MAX_JOYSTICKS; i++) {
413 SGPropertyNode_ptr js_node = js_nodes->getChild("js", i);
415 SG_LOG(SG_INPUT, SG_DEBUG, "No bindings for joystick " << i);
416 js_node = js_nodes->getChild("js", i, true);
418 jsJoystick * js = new jsJoystick(i);
419 _joystick_bindings[i].js = js;
420 if (js->notWorking()) {
421 SG_LOG(SG_INPUT, SG_DEBUG, "Joystick " << i << " not found");
424 bool found_js = false;
425 const char * name = js->getName();
426 SG_LOG(SG_INPUT, SG_INFO, "Looking for bindings for joystick \""
428 vector<SGPropertyNode_ptr> nodes = js_nodes->getChildren("js-named");
429 for (unsigned int i = 0; i < nodes.size(); i++) {
430 SGPropertyNode_ptr node = nodes[i];
431 vector<SGPropertyNode_ptr> name_nodes = node->getChildren("name");
432 for (unsigned int j = 0; j < name_nodes.size(); j++) {
433 const char * js_name = name_nodes[j]->getStringValue();
434 SG_LOG(SG_INPUT, SG_INFO, " Trying \"" << js_name << '"');
435 if (!strcmp(js_name, name)) {
436 SG_LOG(SG_INPUT, SG_INFO, " Found bindings");
448 joyGetDevCaps( i, &jsCaps, sizeof(jsCaps) );
449 int nbuttons = jsCaps.wNumButtons;
450 if (nbuttons > MAX_JOYSTICK_BUTTONS) nbuttons = MAX_JOYSTICK_BUTTONS;
452 int nbuttons = MAX_JOYSTICK_BUTTONS;
455 int naxes = js->getNumAxes();
456 if (naxes > MAX_JOYSTICK_AXES) naxes = MAX_JOYSTICK_AXES;
457 _joystick_bindings[i].naxes = naxes;
458 _joystick_bindings[i].nbuttons = nbuttons;
460 SG_LOG(SG_INPUT, SG_DEBUG, "Initializing joystick " << i);
462 // Set up range arrays
463 float minRange[MAX_JOYSTICK_AXES];
464 float maxRange[MAX_JOYSTICK_AXES];
465 float center[MAX_JOYSTICK_AXES];
467 // Initialize with default values
468 js->getMinRange(minRange);
469 js->getMaxRange(maxRange);
470 js->getCenter(center);
472 // Allocate axes and buttons
473 _joystick_bindings[i].axes = new axis[naxes];
474 _joystick_bindings[i].buttons = new button[nbuttons];
478 // Initialize the axes.
481 for (j = 0; j < naxes; j++) {
482 const SGPropertyNode * axis_node = js_node->getChild("axis", j);
483 if (axis_node == 0) {
484 SG_LOG(SG_INPUT, SG_DEBUG, "No bindings for axis " << j);
485 axis_node = js_node->getChild("axis", j, true);
488 axis &a = _joystick_bindings[i].axes[j];
490 js->setDeadBand(j, axis_node->getDoubleValue("dead-band", 0.0));
492 a.tolerance = axis_node->getDoubleValue("tolerance", 0.002);
493 minRange[j] = axis_node->getDoubleValue("min-range", minRange[j]);
494 maxRange[j] = axis_node->getDoubleValue("max-range", maxRange[j]);
495 center[j] = axis_node->getDoubleValue("center", center[j]);
497 _read_bindings(axis_node, a.bindings, KEYMOD_NONE);
499 // Initialize the virtual axis buttons.
500 _init_button(axis_node->getChild("low"), a.low, "low");
501 a.low_threshold = axis_node->getDoubleValue("low-threshold", -0.9);
503 _init_button(axis_node->getChild("high"), a.high, "high");
504 a.high_threshold = axis_node->getDoubleValue("high-threshold", 0.9);
505 a.interval_sec = axis_node->getDoubleValue("interval-sec",0.0);
510 // Initialize the buttons.
513 for (j = 0; j < nbuttons; j++) {
514 sprintf(buf, "%d", j);
515 SG_LOG(SG_INPUT, SG_DEBUG, "Initializing button " << j);
516 _init_button(js_node->getChild("button", j),
517 _joystick_bindings[i].buttons[j],
520 // get interval-sec property
521 button &b = _joystick_bindings[i].buttons[j];
522 const SGPropertyNode * button_node = js_node->getChild("button", j);
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 ()
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 if (mode >= 0 && mode < m.nModes) {
733 fgSetMouseCursor(m.modes[mode].cursor);
734 m.x = fgGetInt("/sim/startup/xsize", 800) / 2;
735 m.y = fgGetInt("/sim/startup/ysize", 600) / 2;
736 fgWarpMouse(m.x, m.y);
738 SG_LOG(SG_INPUT, SG_DEBUG, "Mouse mode " << mode << " out of range");
739 fgSetMouseCursor(MOUSE_CURSOR_POINTER);
745 FGInput::_update_button (button &b, int modifiers, bool pressed,
749 // The press event may be repeated.
750 if (!b.last_state || b.is_repeatable) {
751 SG_LOG( SG_INPUT, SG_DEBUG, "Button has been pressed" );
752 for (unsigned int k = 0; k < b.bindings[modifiers].size(); k++)
753 b.bindings[modifiers][k]->fire(x, y);
756 // The release event is never repeated.
758 SG_LOG( SG_INPUT, SG_DEBUG, "Button has been released" );
759 for (unsigned int k = 0; k < b.bindings[modifiers|KEYMOD_RELEASED].size(); k++)
760 b.bindings[modifiers|KEYMOD_RELEASED][k]->fire(x, y);
764 b.last_state = pressed;
769 FGInput::_read_bindings (const SGPropertyNode * node,
770 binding_list_t * binding_list,
773 SG_LOG(SG_INPUT, SG_DEBUG, "Reading all bindings");
774 vector<SGPropertyNode_ptr> bindings = node->getChildren("binding");
775 for (unsigned int i = 0; i < bindings.size(); i++) {
776 SG_LOG(SG_INPUT, SG_DEBUG, "Reading binding "
777 << bindings[i]->getStringValue("command"));
778 binding_list[modifiers].push_back(new FGBinding(bindings[i]));
781 // Read nested bindings for modifiers
782 if (node->getChild("mod-up") != 0)
783 _read_bindings(node->getChild("mod-up"), binding_list,
784 modifiers|KEYMOD_RELEASED);
786 if (node->getChild("mod-shift") != 0)
787 _read_bindings(node->getChild("mod-shift"), binding_list,
788 modifiers|KEYMOD_SHIFT);
790 if (node->getChild("mod-ctrl") != 0)
791 _read_bindings(node->getChild("mod-ctrl"), binding_list,
792 modifiers|KEYMOD_CTRL);
794 if (node->getChild("mod-alt") != 0)
795 _read_bindings(node->getChild("mod-alt"), binding_list,
796 modifiers|KEYMOD_ALT);
800 const vector<FGBinding *> &
801 FGInput::_find_key_bindings (unsigned int k, int modifiers)
803 unsigned char kc = (unsigned char)k;
804 button &b = _key_bindings[k];
806 // Try it straight, first.
807 if (b.bindings[modifiers].size() > 0)
808 return b.bindings[modifiers];
810 // Alt-Gr is CTRL+ALT
811 else if (modifiers&(KEYMOD_CTRL|KEYMOD_ALT))
812 return _find_key_bindings(k, modifiers&~(KEYMOD_CTRL|KEYMOD_ALT));
814 // Try removing the control modifier
816 else if ((modifiers&KEYMOD_CTRL) && iscntrl(kc))
817 return _find_key_bindings(k, modifiers&~KEYMOD_CTRL);
819 // Try removing shift modifier
820 // for upper case or any punctuation
821 // (since different keyboards will
822 // shift different punctuation types)
823 else if ((modifiers&KEYMOD_SHIFT) && (isupper(kc) || ispunct(kc)))
824 return _find_key_bindings(k, modifiers&~KEYMOD_SHIFT);
826 // Try removing alt modifier for
827 // high-bit characters.
828 else if ((modifiers&KEYMOD_ALT) && k >= 128 && k < 256)
829 return _find_key_bindings(k, modifiers&~KEYMOD_ALT);
831 // Give up and return the empty vector.
833 return b.bindings[modifiers];
838 ////////////////////////////////////////////////////////////////////////
839 // Implementation of FGInput::button.
840 ////////////////////////////////////////////////////////////////////////
842 FGInput::button::button ()
843 : is_repeatable(false),
848 FGInput::button::~button ()
850 // FIXME: memory leak
851 // for (int i = 0; i < KEYMOD_MAX; i++)
852 // for (int j = 0; i < bindings[i].size(); j++)
853 // delete bindings[i][j];
858 ////////////////////////////////////////////////////////////////////////
859 // Implementation of FGInput::axis.
860 ////////////////////////////////////////////////////////////////////////
862 FGInput::axis::axis ()
863 : last_value(9999999),
870 FGInput::axis::~axis ()
872 // for (int i = 0; i < KEYMOD_MAX; i++)
873 // for (int j = 0; i < bindings[i].size(); j++)
874 // delete bindings[i][j];
879 ////////////////////////////////////////////////////////////////////////
880 // Implementation of FGInput::joystick.
881 ////////////////////////////////////////////////////////////////////////
883 FGInput::joystick::joystick ()
887 FGInput::joystick::~joystick ()
896 ////////////////////////////////////////////////////////////////////////
897 // Implementation of FGInput::mouse_mode
898 ////////////////////////////////////////////////////////////////////////
900 FGInput::mouse_mode::mouse_mode ()
901 : cursor(MOUSE_CURSOR_POINTER),
908 FGInput::mouse_mode::~mouse_mode ()
910 // FIXME: memory leak
911 // for (int i = 0; i < KEYMOD_MAX; i++) {
913 // for (j = 0; i < x_bindings[i].size(); j++)
914 // delete bindings[i][j];
915 // for (j = 0; j < y_bindings[i].size(); j++)
916 // delete bindings[i][j];
923 ////////////////////////////////////////////////////////////////////////
924 // Implementation of FGInput::mouse
925 ////////////////////////////////////////////////////////////////////////
927 FGInput::mouse::mouse ()
936 FGInput::mouse::~mouse ()
941 ////////////////////////////////////////////////////////////////////////
942 // Implementation of OS callbacks.
943 ////////////////////////////////////////////////////////////////////////
945 void keyHandler(int key, int keymod, int mousex, int mousey)
947 if((keymod & KEYMOD_RELEASED) == 0)
948 if(puKeyboard(key, PU_DOWN))
952 default_input->doKey(key, keymod, mousex, mousey);
955 void mouseClickHandler(int button, int updown, int x, int y)
958 default_input->doMouseClick(button, updown, x, y);
961 void mouseMotionHandler(int x, int y)
963 if (default_input != 0)
964 default_input->doMouseMotion(x, y);