fgRegisterMouseMotionHandler(mouseMotionHandler);
}
+void
+FGInput::reinit ()
+{
+ init();
+}
+
void
FGInput::update (double dt)
{
_update_keyboard();
_update_joystick(dt);
- _update_mouse();
+ _update_mouse(dt);
}
void
}
}
}
-
// Key released.
else {
SG_LOG(SG_INPUT, SG_DEBUG, "User released key " << k
return;
}
}
- }
- // Use the old, default actions.
- SG_LOG( SG_INPUT, SG_DEBUG, "(No user binding.)" );
-
- if (modifiers & KEYMOD_RELEASED)
- return;
-
- // Hard-coded legacy key handlers.
- // These need to be turned into FGCommand bindings and mapped via
- // the input configuration...
- switch (k) {
- case 'H':
- HUD_brightkey( true );
- break;
- case 'h':
- HUD_masterswitch( true );
- break;
- case 'I':
- fgHUDInit2(¤t_aircraft); // Minimal Hud
- break;
- case 'i':
- fgHUDInit(¤t_aircraft); // normal HUD
- break;
}
}
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");
//
// Initialize the axes.
//
+ vector<SGPropertyNode_ptr> axes = js_node->getChildren("axis");
+ size_t nb_axes = axes.size();
int j;
- for (j = 0; j < naxes; j++) {
- const SGPropertyNode * axis_node = js_node->getChild("axis", j);
- if (axis_node == 0) {
- SG_LOG(SG_INPUT, SG_DEBUG, "No bindings for axis " << j);
- axis_node = js_node->getChild("axis", j, true);
+ 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);
}
-
- axis &a = _joystick_bindings[i].axes[j];
- js->setDeadBand(j, axis_node->getDoubleValue("dead-band", 0.0));
+ 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));
a.tolerance = axis_node->getDoubleValue("tolerance", 0.002);
- minRange[j] = axis_node->getDoubleValue("min-range", minRange[j]);
- maxRange[j] = axis_node->getDoubleValue("max-range", maxRange[j]);
- center[j] = axis_node->getDoubleValue("center", center[j]);
+ 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);
//
// Initialize the buttons.
//
+ vector<SGPropertyNode_ptr> buttons = js_node->getChildren("button");
char buf[32];
- for (j = 0; j < nbuttons; j++) {
- sprintf(buf, "%d", j);
- SG_LOG(SG_INPUT, SG_DEBUG, "Initializing button " << j);
- _init_button(js_node->getChild("button", j),
- _joystick_bindings[i].buttons[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,
+ _joystick_bindings[i].buttons[n_but],
buf);
// get interval-sec property
- button &b = _joystick_bindings[i].buttons[j];
- const SGPropertyNode * button_node = js_node->getChild("button", j);
+ button &b = _joystick_bindings[i].buttons[n_but];
if (button_node != 0) {
b.interval_sec = button_node->getDoubleValue("interval-sec",0.0);
b.last_dt = 0.0;
}
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