X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FInput%2Finput.cxx;h=98432a6f01803e7b43d3737015601296a27927e1;hb=f88a9aab6a097c65960e978444f64f0ea8a022a1;hp=fffc334fc3f9c824576c130c66979a8188442e5b;hpb=2069bf3eb17677a19907bfbf2832d221b60ebb87;p=flightgear.git diff --git a/src/Input/input.cxx b/src/Input/input.cxx index fffc334fc..98432a6f0 100644 --- a/src/Input/input.cxx +++ b/src/Input/input.cxx @@ -179,12 +179,18 @@ FGInput::init () fgRegisterMouseMotionHandler(mouseMotionHandler); } +void +FGInput::reinit () +{ + init(); +} + void FGInput::update (double dt) { _update_keyboard(); _update_joystick(dt); - _update_mouse(); + _update_mouse(dt); } void @@ -303,15 +309,23 @@ FGInput::doMouseMotion (int x, int y) int xsize = fgGetInt("/sim/startup/xsize", 800); int ysize = fgGetInt("/sim/startup/ysize", 600); + mouse &m = _mouse_bindings[0]; - if (m.current_mode < 0 || m.current_mode >= m.nModes) - return; + + if (m.current_mode < 0 || m.current_mode >= m.nModes) { + m.x = x; + m.y = y; + return; + } mouse_mode &mode = m.modes[m.current_mode]; // Pass on to PUI if requested, and return // if PUI consumed the event. - if (mode.pass_through && puMouse(x, y)) - return; + if (mode.pass_through && puMouse(x, y)) { + m.x = x; + m.y = y; + return; + } // OK, PUI didn't want the event, // so we can play with it. @@ -377,6 +391,7 @@ FGInput::_init_keyboard () void FGInput::_init_joystick () { + jsInit(); // TODO: zero the old bindings first. SG_LOG(SG_INPUT, SG_DEBUG, "Initializing joystick bindings"); SGPropertyNode * js_nodes = fgGetNode("/input/joysticks"); @@ -456,14 +471,23 @@ FGInput::_init_joystick () vector axes = js_node->getChildren("axis"); size_t nb_axes = axes.size(); int j; - for (j = 0; j < nb_axes; j++) { + for (j = 0; j < (int)nb_axes; j++) { const SGPropertyNode * axis_node = axes[j]; const SGPropertyNode * num_node = axis_node->getChild("number"); size_t n_axis = axis_node->getIndex(); if (num_node != 0) { - n_axis = num_node->getIntValue(TGT_PLATFORM,n_axis); + n_axis = num_node->getIntValue(TGT_PLATFORM, -1); + + // Silently ignore platforms that are not specified within the + // section + if (n_axis < 0) + continue; } + if (n_axis >= (size_t)naxes) { + SG_LOG(SG_INPUT, SG_DEBUG, "Dropping bindings for axis " << n_axis); + continue; + } axis &a = _joystick_bindings[i].axes[n_axis]; js->setDeadBand(n_axis, axis_node->getDoubleValue("dead-band", 0.0)); @@ -490,13 +514,19 @@ FGInput::_init_joystick () // vector buttons = js_node->getChildren("button"); char buf[32]; - for (j = 0; (j < buttons.size()) && (j < nbuttons); j++) { + for (j = 0; (j < (int)buttons.size()) && (j < nbuttons); j++) { const SGPropertyNode * button_node = buttons[j]; const SGPropertyNode * num_node = button_node->getChild("number"); size_t n_but = button_node->getIndex(); if (num_node != 0) { n_but = num_node->getIntValue(TGT_PLATFORM,n_but); } + + if (n_but >= (size_t)nbuttons) { + SG_LOG(SG_INPUT, SG_DEBUG, "Dropping bindings for button " << n_but); + continue; + } + sprintf(buf, "%d", n_but); SG_LOG(SG_INPUT, SG_DEBUG, "Initializing button " << n_but); _init_button(button_node, @@ -526,7 +556,7 @@ FGInput::_init_joystick () // cursors defined as textures referenced in the property tree. This // list could then be eliminated. -Andy // -struct { +static struct { const char * name; int cursor; } mouse_cursor_map[] = { @@ -708,12 +738,13 @@ FGInput::_update_joystick (double dt) } void -FGInput::_update_mouse () +FGInput::_update_mouse ( double dt ) { mouse &m = _mouse_bindings[0]; int mode = m.mode_node->getIntValue(); if (mode != m.current_mode) { m.current_mode = mode; + m.timeout = fgGetDouble( "/sim/mouse/cursor-timeout-sec", 10.0 ); if (mode >= 0 && mode < m.nModes) { fgSetMouseCursor(m.modes[mode].cursor); m.x = fgGetInt("/sim/startup/xsize", 800) / 2; @@ -724,6 +755,21 @@ FGInput::_update_mouse () fgSetMouseCursor(MOUSE_CURSOR_POINTER); } } + + if ( fgGetBool( "/sim/mouse/hide-cursor", true ) ) { + if ( m.x != m.save_x || m.y != m.save_y ) { + m.timeout = fgGetDouble( "/sim/mouse/cursor-timeout-sec", 10.0 ); + fgSetMouseCursor(m.modes[mode].cursor); + } else { + m.timeout -= dt; + if ( m.timeout <= 0.0 ) { + fgSetMouseCursor(MOUSE_CURSOR_NONE); + m.timeout = 0.0; + } + } + m.save_x = m.x; + m.save_y = m.y; + } } void