From 886d0036885ec162c9bac3ef0bc97db5d316f9e8 Mon Sep 17 00:00:00 2001 From: curt Date: Mon, 14 Jun 2004 18:46:58 +0000 Subject: [PATCH] - Track a saved mouse pointer location from the previous frame so we can detect motion. - Track a timeout value so we can optionally hide the mouse pointer after some user specified timeout period. - in doMouseMotion() always update m.x and m.y even if we return early because pui wanted the event. Without this, we can't reliably detect motion vs. inactivity. - in _update_mouse() add a dt parameter so we can decriment the timeout value in "real" time. - in _update_mouse() optionally hide the mouse pointer if m.timeout goes to zero. Restore the pointer (and the timeout counter) if the mouse is moved. --- src/Input/input.cxx | 36 ++++++++++++++++++++++++++++++------ src/Input/input.hxx | 5 ++++- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/Input/input.cxx b/src/Input/input.cxx index 0c5ce80fb..dea8995c5 100644 --- a/src/Input/input.cxx +++ b/src/Input/input.cxx @@ -184,7 +184,7 @@ FGInput::update (double dt) { _update_keyboard(); _update_joystick(dt); - _update_mouse(); + _update_mouse(dt); } void @@ -303,15 +303,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. @@ -709,12 +717,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; @@ -725,6 +734,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 diff --git a/src/Input/input.hxx b/src/Input/input.hxx index ac59a6627..755b6d66f 100644 --- a/src/Input/input.hxx +++ b/src/Input/input.hxx @@ -339,6 +339,9 @@ private: SGPropertyNode * mouse_button_nodes[MAX_MOUSE_BUTTONS]; int nModes; int current_mode; + double timeout; + int save_x; + int save_y; mouse_mode * modes; }; @@ -384,7 +387,7 @@ private: /** * Update the mouse. */ - void _update_mouse (); + void _update_mouse (double dt); /**