glutKeyboardUpFunc(GLUTkeyup);
glutSpecialFunc(GLUTspecialkey);
glutSpecialUpFunc(GLUTspecialkeyup);
-#ifdef FG_NEW_MOUSE
glutMouseFunc (GLUTmouse);
glutMotionFunc (GLUTmotion);
glutPassiveMotionFunc (GLUTmotion);
-#endif
}
void
}
void
-FGInput::update (int dt)
+FGInput::update (double dt)
{
_update_keyboard();
_update_joystick();
return;
}
- _update_button(m.modes[m.current_mode].buttons[b], modifiers, updown, x, y);
+ _update_button(m.modes[m.current_mode].buttons[b], modifiers, 0 != updown, x, y);
}
void
// so we can play with it.
if (x != m.x) {
int delta = x - m.x;
- for (int i = 0; i < mode.x_bindings[modifiers].size(); i++)
+ for (unsigned int i = 0; i < mode.x_bindings[modifiers].size(); i++)
mode.x_bindings[modifiers][i]->fire(double(delta), double(xsize));
}
if (y != m.y) {
int delta = y - m.y;
- for (int i = 0; i < mode.y_bindings[modifiers].size(); i++)
+ for (unsigned int i = 0; i < mode.y_bindings[modifiers].size(); i++)
mode.y_bindings[modifiers][i]->fire(double(delta), double(ysize));
}
// Constrain the mouse if requested
if (mode.constrained) {
bool need_warp = false;
- if (x < 0) {
- x = xsize - 1;
+ if (x <= 0) {
+ x = xsize - 2;
need_warp = true;
- } else if (x >= xsize) {
- x = 0;
+ } else if (x >= (xsize-1)) {
+ x = 1;
need_warp = true;
}
- if (y < 0) {
- y = ysize - 1;
+ if (y <= 0) {
+ y = ysize - 2;
need_warp = true;
- } else if (y >= ysize) {
- y = 0;
+ } else if (y >= (ysize-1)) {
+ y = 1;
need_warp = true;
}
key_nodes = fgGetNode("/input/keyboard", true);
}
- vector<SGPropertyNode *> keys = key_nodes->getChildren("key");
+ vector<SGPropertyNode_ptr> keys = key_nodes->getChildren("key");
for (unsigned int i = 0; i < keys.size(); i++) {
int index = keys[i]->getIndex();
SG_LOG(SG_INPUT, SG_DEBUG, "Binding key " << index);
}
for (int i = 0; i < MAX_JOYSTICKS; i++) {
- SGPropertyNode * js_node = js_nodes->getChild("js", i);
+ SGPropertyNode_ptr js_node = js_nodes->getChild("js", i);
if (js_node == 0) {
SG_LOG(SG_INPUT, SG_DEBUG, "No bindings for joystick " << i);
js_node = js_nodes->getChild("js", i, true);
if (js->notWorking()) {
SG_LOG(SG_INPUT, SG_WARN, "Joystick " << i << " not found");
continue;
+ } else {
+#ifdef FG_PLIB_JOYSTICK_GETNAME
+ bool found_js = false;
+ const char * name = js->getName();
+ SG_LOG(SG_INPUT, SG_INFO, "Looking for bindings for joystick \""
+ << name << '"');
+ vector<SGPropertyNode_ptr> nodes = js_nodes->getChildren("js-named");
+ for (unsigned int i = 0; i < nodes.size(); i++) {
+ SGPropertyNode_ptr node = nodes[i];
+ vector<SGPropertyNode_ptr> name_nodes = node->getChildren("name");
+ for (unsigned int j = 0; j < name_nodes.size(); j++) {
+ const char * js_name = name_nodes[j]->getStringValue();
+ SG_LOG(SG_INPUT, SG_INFO, " Trying \"" << js_name << '"');
+ if (!strcmp(js_name, name)) {
+ SG_LOG(SG_INPUT, SG_INFO, " Found bindings");
+ js_node = node;
+ found_js = true;
+ break;
+ }
+ }
+ if (found_js)
+ break;
+ }
+#endif
}
#ifdef WIN32
JOYCAPS jsCaps ;
// Read the button bindings for this mode
m.modes[j].buttons = new button[MAX_MOUSE_BUTTONS];
- char buf[8];
+ char buf[32];
for (k = 0; k < MAX_MOUSE_BUTTONS; k++) {
sprintf(buf, "mouse button %d", k);
SG_LOG(SG_INPUT, SG_DEBUG, "Initializing mouse button " << k);
m.current_mode = mode;
if (mode >= 0 && mode < m.nModes) {
glutSetCursor(m.modes[mode].cursor);
+ m.x = fgGetInt("/sim/startup/xsize", 800) / 2;
+ m.y = fgGetInt("/sim/startup/ysize", 600) / 2;
+ glutWarpPointer(m.x, m.y);
} else {
SG_LOG(SG_INPUT, SG_DEBUG, "Mouse mode " << mode << " out of range");
glutSetCursor(GLUT_CURSOR_INHERIT);
int modifiers)
{
SG_LOG(SG_INPUT, SG_DEBUG, "Reading all bindings");
- vector<const SGPropertyNode *> bindings = node->getChildren("binding");
+ vector<SGPropertyNode_ptr> bindings = node->getChildren("binding");
for (unsigned int i = 0; i < bindings.size(); i++) {
SG_LOG(SG_INPUT, SG_DEBUG, "Reading binding "
<< bindings[i]->getStringValue("command"));
////////////////////////////////////////////////////////////////////////
FGInput::mouse::mouse ()
- : nModes(1),
- current_mode(0),
- x(-1),
+ : x(-1),
y(-1),
+ nModes(1),
+ current_mode(0),
modes(0)
{
}