- 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.
This commit is contained in:
parent
0fa47dbbdc
commit
886d003688
2 changed files with 34 additions and 7 deletions
|
@ -184,7 +184,7 @@ FGInput::update (double dt)
|
||||||
{
|
{
|
||||||
_update_keyboard();
|
_update_keyboard();
|
||||||
_update_joystick(dt);
|
_update_joystick(dt);
|
||||||
_update_mouse();
|
_update_mouse(dt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -303,15 +303,23 @@ FGInput::doMouseMotion (int x, int y)
|
||||||
|
|
||||||
int xsize = fgGetInt("/sim/startup/xsize", 800);
|
int xsize = fgGetInt("/sim/startup/xsize", 800);
|
||||||
int ysize = fgGetInt("/sim/startup/ysize", 600);
|
int ysize = fgGetInt("/sim/startup/ysize", 600);
|
||||||
|
|
||||||
mouse &m = _mouse_bindings[0];
|
mouse &m = _mouse_bindings[0];
|
||||||
if (m.current_mode < 0 || m.current_mode >= m.nModes)
|
|
||||||
|
if (m.current_mode < 0 || m.current_mode >= m.nModes) {
|
||||||
|
m.x = x;
|
||||||
|
m.y = y;
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
mouse_mode &mode = m.modes[m.current_mode];
|
mouse_mode &mode = m.modes[m.current_mode];
|
||||||
|
|
||||||
// Pass on to PUI if requested, and return
|
// Pass on to PUI if requested, and return
|
||||||
// if PUI consumed the event.
|
// if PUI consumed the event.
|
||||||
if (mode.pass_through && puMouse(x, y))
|
if (mode.pass_through && puMouse(x, y)) {
|
||||||
|
m.x = x;
|
||||||
|
m.y = y;
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// OK, PUI didn't want the event,
|
// OK, PUI didn't want the event,
|
||||||
// so we can play with it.
|
// so we can play with it.
|
||||||
|
@ -709,12 +717,13 @@ FGInput::_update_joystick (double dt)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
FGInput::_update_mouse ()
|
FGInput::_update_mouse ( double dt )
|
||||||
{
|
{
|
||||||
mouse &m = _mouse_bindings[0];
|
mouse &m = _mouse_bindings[0];
|
||||||
int mode = m.mode_node->getIntValue();
|
int mode = m.mode_node->getIntValue();
|
||||||
if (mode != m.current_mode) {
|
if (mode != m.current_mode) {
|
||||||
m.current_mode = mode;
|
m.current_mode = mode;
|
||||||
|
m.timeout = fgGetDouble( "/sim/mouse/cursor-timeout-sec", 10.0 );
|
||||||
if (mode >= 0 && mode < m.nModes) {
|
if (mode >= 0 && mode < m.nModes) {
|
||||||
fgSetMouseCursor(m.modes[mode].cursor);
|
fgSetMouseCursor(m.modes[mode].cursor);
|
||||||
m.x = fgGetInt("/sim/startup/xsize", 800) / 2;
|
m.x = fgGetInt("/sim/startup/xsize", 800) / 2;
|
||||||
|
@ -725,6 +734,21 @@ FGInput::_update_mouse ()
|
||||||
fgSetMouseCursor(MOUSE_CURSOR_POINTER);
|
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
|
void
|
||||||
|
|
|
@ -339,6 +339,9 @@ private:
|
||||||
SGPropertyNode * mouse_button_nodes[MAX_MOUSE_BUTTONS];
|
SGPropertyNode * mouse_button_nodes[MAX_MOUSE_BUTTONS];
|
||||||
int nModes;
|
int nModes;
|
||||||
int current_mode;
|
int current_mode;
|
||||||
|
double timeout;
|
||||||
|
int save_x;
|
||||||
|
int save_y;
|
||||||
mouse_mode * modes;
|
mouse_mode * modes;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -384,7 +387,7 @@ private:
|
||||||
/**
|
/**
|
||||||
* Update the mouse.
|
* Update the mouse.
|
||||||
*/
|
*/
|
||||||
void _update_mouse ();
|
void _update_mouse (double dt);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue