fgRegisterMouseMotionHandler(mouseMotionHandler);
}
+void
+FGInput::reinit ()
+{
+ init();
+}
+
void
FGInput::update (double dt)
{
_update_keyboard();
_update_joystick(dt);
- _update_mouse();
+ _update_mouse(dt);
}
void
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.
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");
vector<SGPropertyNode_ptr> 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_axe = axis_node->getIndex();
+ size_t n_axis = axis_node->getIndex();
if (num_node != 0) {
- n_axe = num_node->getIntValue(TGT_PLATFORM,n_axe);
+ n_axis = num_node->getIntValue(TGT_PLATFORM,n_axis);
}
- axis &a = _joystick_bindings[i].axes[n_axe];
+ 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_axe, axis_node->getDoubleValue("dead-band", 0.0));
+ js->setDeadBand(n_axis, axis_node->getDoubleValue("dead-band", 0.0));
a.tolerance = axis_node->getDoubleValue("tolerance", 0.002);
- minRange[n_axe] = axis_node->getDoubleValue("min-range", minRange[n_axe]);
- maxRange[n_axe] = axis_node->getDoubleValue("max-range", maxRange[n_axe]);
- center[n_axe] = axis_node->getDoubleValue("center", center[n_axe]);
+ minRange[n_axis] = axis_node->getDoubleValue("min-range", minRange[n_axis]);
+ maxRange[n_axis] = axis_node->getDoubleValue("max-range", maxRange[n_axis]);
+ center[n_axis] = axis_node->getDoubleValue("center", center[n_axis]);
_read_bindings(axis_node, a.bindings, KEYMOD_NONE);
//
vector<SGPropertyNode_ptr> buttons = js_node->getChildren("button");
char buf[32];
- for (j = 0; 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,
}
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;
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